@@ -25,7 +25,7 @@ import type {
2525 TerrainSpecification ,
2626 ProjectionSpecification
2727} from '../types/style-spec' ;
28- import type { MapInstance } from '../types/lib' ;
28+ import type { MapInstance , MapOptions } from '../types/lib' ;
2929import type { CameraUpdateTransformFunction , MapEventType } from 'maplibre-gl' ;
3030import type {
3131 MapCallbacks ,
@@ -35,8 +35,24 @@ import type {
3535 MapMouseEvent
3636} from '../types/events' ;
3737
38+ const cameraConstraintNames = [ 'minZoom' , 'maxZoom' , 'minPitch' , 'maxPitch' ] as const ;
39+
40+ type ReactiveMapOptions = Pick <
41+ MapOptions ,
42+ ( typeof cameraConstraintNames ) [ number ] | 'maxBounds' | 'renderWorldCopies'
43+ > ;
44+
45+ function removeNullishCameraConstraints ( options : ReactiveMapOptions ) : void {
46+ for ( const propName of cameraConstraintNames ) {
47+ if ( options [ propName ] === null || options [ propName ] === undefined ) {
48+ delete options [ propName ] ;
49+ }
50+ }
51+ }
52+
3853export type MaplibreProps = Partial < ViewState > &
39- MapCallbacks & {
54+ MapCallbacks &
55+ ReactiveMapOptions & {
4056 /** Camera options used when constructing the Map instance */
4157 initialViewState ?: Partial < ViewState > & {
4258 /** The initial bounds of the map. If bounds is specified, it overrides longitude, latitude and zoom options. */
@@ -83,40 +99,11 @@ export type MaplibreProps = Partial<ViewState> &
8399 interactiveLayerIds ?: string [ ] ;
84100 /** CSS cursor */
85101 cursor ?: string ;
86-
87- /** Minimum zoom available to the map.
88- * @default 0
89- */
90- minZoom ?: number ;
91- /** Maximum zoom available to the map.
92- * @default 22
93- */
94- maxZoom ?: number ;
95- /** Minimum pitch available to the map.
96- * @default 0
97- */
98- minPitch ?: number ;
99- /** Maximum pitch available to the map.
100- * @default 85
101- */
102- maxPitch ?: number ;
103- /** Bounds of the map.
104- * @default [-180, -85.051129, 180, 85.051129]
105- */
106- maxBounds ?: [ number , number , number , number ] ;
107- /** Whether to render copies of the world or not.
108- * @default true
109- */
110- renderWorldCopies ?: boolean ;
111102 } ;
112103
113104const DEFAULT_STYLE = { version : 8 , sources : { } , layers : [ ] } as StyleSpecification ;
114105
115106const DEFAULT_SETTINGS = {
116- minZoom : 0 ,
117- maxZoom : 22 ,
118- minPitch : 0 ,
119- maxPitch : 85 ,
120107 maxBounds : [ - 180 , - 85.051129 , 180 , 85.051129 ] ,
121108 projection : 'mercator' ,
122109 renderWorldCopies : true
@@ -302,6 +289,7 @@ export default class Maplibre {
302289 container,
303290 style : normalizeStyle ( mapStyle )
304291 } ;
292+ removeNullishCameraConstraints ( mapOptions ) ;
305293
306294 const viewState = mapOptions . initialViewState || mapOptions . viewState || mapOptions ;
307295 Object . assign ( mapOptions , {
@@ -457,23 +445,23 @@ export default class Maplibre {
457445 const didUpdateZoom = updateZoomConstraint (
458446 this . _map ,
459447 {
460- min : nextProps . minZoom ?? DEFAULT_SETTINGS . minZoom ,
461- max : nextProps . maxZoom ?? DEFAULT_SETTINGS . maxZoom
448+ min : nextProps . minZoom ,
449+ max : nextProps . maxZoom
462450 } ,
463451 {
464- min : currProps . minZoom ?? DEFAULT_SETTINGS . minZoom ,
465- max : currProps . maxZoom ?? DEFAULT_SETTINGS . maxZoom
452+ min : currProps . minZoom ,
453+ max : currProps . maxZoom
466454 }
467455 ) ;
468456 const didUpdatePitch = updatePitchConstraint (
469457 this . _map ,
470458 {
471- min : nextProps . minPitch ?? DEFAULT_SETTINGS . minPitch ,
472- max : nextProps . maxPitch ?? DEFAULT_SETTINGS . maxPitch
459+ min : nextProps . minPitch ,
460+ max : nextProps . maxPitch
473461 } ,
474462 {
475- min : currProps . minPitch ?? DEFAULT_SETTINGS . minPitch ,
476- max : currProps . maxPitch ?? DEFAULT_SETTINGS . maxPitch
463+ min : currProps . minPitch ,
464+ max : currProps . maxPitch
477465 }
478466 ) ;
479467
0 commit comments