@@ -28,17 +28,15 @@ export var FeatureLayer = L.FeatureGroup.extend({
2828 ) ;
2929 L . setOptions ( this . options . renderer , { pane : this . _container } ) ;
3030 }
31-
3231 this . _layers = { } ;
3332 if ( this . options . query ) {
3433 this . _mapmlFeatures = mapml . features ? mapml . features : mapml ;
3534 this . isVisible = true ;
36- let native = this . _getNativeVariables ( mapml ) ;
35+ let native = M . getNativeVariables ( mapml ) ;
3736 this . options . nativeZoom = native . zoom ;
3837 this . options . nativeCS = native . cs ;
39- }
40- if ( mapml && ! this . options . query ) {
41- let native = this . _getNativeVariables ( mapml ) ;
38+ } else if ( mapml ) {
39+ let native = M . getNativeVariables ( mapml ) ;
4240 //needed to check if the feature is static or not, since this method is used by templated also
4341 if (
4442 ! mapml . querySelector ( 'map-extent' ) &&
@@ -48,11 +46,15 @@ export var FeatureLayer = L.FeatureGroup.extend({
4846 this . _features = { } ;
4947 this . _staticFeature = true ;
5048 this . isVisible = true ; //placeholder for when this actually gets updated in the future
51- this . zoomBounds = this . _getZoomBounds ( mapml , native . zoom ) ;
52- this . layerBounds = this . _getLayerBounds ( mapml ) ;
49+ this . zoomBounds = M . getZoomBounds ( mapml , native . zoom ) ;
50+ this . layerBounds = M . getLayerBounds ( mapml ) ;
5351 L . extend ( this . options , this . zoomBounds ) ;
5452 }
5553 this . addData ( mapml , native . cs , native . zoom ) ;
54+ } else if ( ! mapml ) {
55+ this . isVisible = true ;
56+ this . layerBounds = this . options . extent ;
57+ this . zoomBounds = this . options . zoomBounds ;
5658 }
5759 } ,
5860
@@ -131,54 +133,6 @@ export var FeatureLayer = L.FeatureGroup.extend({
131133 }
132134 } ,
133135
134- // _getNativeVariables: returns an object with the native zoom and CS,
135- // based on the map-metas that are available within
136- // the layer or the fallback default values.
137- // _getNativeVariables: mapml-||layer-||null||[map-feature,...] -> {zoom: _, val: _}
138- // mapml can be a mapml- element, layer- element, null, or an array of map-features
139- _getNativeVariables : function ( mapml ) {
140- let nativeZoom , nativeCS ;
141- // when mapml is an array of features provided by the query
142- if (
143- mapml . length &&
144- mapml [ 0 ] . parentElement . parentElement &&
145- mapml [ 0 ] . parentElement . parentElement . tagName === 'mapml-'
146- ) {
147- let mapmlEl = mapml [ 0 ] . parentElement . parentElement ;
148- nativeZoom =
149- ( mapmlEl . querySelector &&
150- mapmlEl . querySelector ( 'map-meta[name=zoom]' ) &&
151- + M . _metaContentToObject (
152- mapmlEl . querySelector ( 'map-meta[name=zoom]' ) . getAttribute ( 'content' )
153- ) . value ) ||
154- 0 ;
155- nativeCS =
156- ( mapmlEl . querySelector &&
157- mapmlEl . querySelector ( 'map-meta[name=cs]' ) &&
158- M . _metaContentToObject (
159- mapmlEl . querySelector ( 'map-meta[name=cs]' ) . getAttribute ( 'content' )
160- ) . content ) ||
161- 'GCRS' ;
162- } else {
163- // when mapml is null or a layer-/mapml- element
164- nativeZoom =
165- ( mapml . querySelector &&
166- mapml . querySelector ( 'map-meta[name=zoom]' ) &&
167- + M . _metaContentToObject (
168- mapml . querySelector ( 'map-meta[name=zoom]' ) . getAttribute ( 'content' )
169- ) . value ) ||
170- 0 ;
171- nativeCS =
172- ( mapml . querySelector &&
173- mapml . querySelector ( 'map-meta[name=cs]' ) &&
174- M . _metaContentToObject (
175- mapml . querySelector ( 'map-meta[name=cs]' ) . getAttribute ( 'content' )
176- ) . content ) ||
177- 'GCRS' ;
178- }
179- return { zoom : nativeZoom , cs : nativeCS } ;
180- } ,
181-
182136 _handleMoveEnd : function ( ) {
183137 let mapZoom = this . _map . getZoom ( ) ,
184138 withinZoom =
@@ -210,60 +164,6 @@ export var FeatureLayer = L.FeatureGroup.extend({
210164 this . _resetFeatures ( ) ;
211165 } ,
212166
213- //sets default if any are missing, better to only replace ones that are missing
214- _getLayerBounds : function ( container ) {
215- if ( ! container ) return null ;
216- let cs = FALLBACK_CS ,
217- projection =
218- ( container . querySelector ( 'map-meta[name=projection]' ) &&
219- M . _metaContentToObject (
220- container
221- . querySelector ( 'map-meta[name=projection]' )
222- . getAttribute ( 'content' )
223- ) . content . toUpperCase ( ) ) ||
224- FALLBACK_PROJECTION ;
225- try {
226- let meta =
227- container . querySelector ( 'map-meta[name=extent]' ) &&
228- M . _metaContentToObject (
229- container
230- . querySelector ( 'map-meta[name=extent]' )
231- . getAttribute ( 'content' )
232- ) ;
233-
234- let zoom = meta . zoom || 0 ;
235-
236- let metaKeys = Object . keys ( meta ) ;
237- for ( let i = 0 ; i < metaKeys . length ; i ++ ) {
238- if ( ! metaKeys [ i ] . includes ( 'zoom' ) ) {
239- cs = M . axisToCS ( metaKeys [ i ] . split ( '-' ) [ 2 ] ) ;
240- break ;
241- }
242- }
243- let axes = M . csToAxes ( cs ) ;
244- return M . boundsToPCRSBounds (
245- L . bounds (
246- L . point ( + meta [ `top-left-${ axes [ 0 ] } ` ] , + meta [ `top-left-${ axes [ 1 ] } ` ] ) ,
247- L . point (
248- + meta [ `bottom-right-${ axes [ 0 ] } ` ] ,
249- + meta [ `bottom-right-${ axes [ 1 ] } ` ]
250- )
251- ) ,
252- zoom ,
253- projection ,
254- cs
255- ) ;
256- } catch ( error ) {
257- //if error then by default set the layer to osm and bounds to the entire map view
258- return M . boundsToPCRSBounds (
259- M [ projection ] . options . crs . tilematrix . bounds ( 0 ) ,
260- 0 ,
261- projection ,
262- cs
263- ) ;
264- }
265- } ,
266-
267167 _resetFeatures : function ( ) {
268168 this . clearLayers ( ) ;
269169 // since features are removed and re-added by zoom level, need to clean the feature index before re-adding
@@ -300,45 +200,6 @@ export var FeatureLayer = L.FeatureGroup.extend({
300200 }
301201 } ,
302202
303- _getZoomBounds : function ( container , nativeZoom ) {
304- if ( ! container ) return null ;
305- let nMin = 100 ,
306- nMax = 0 ,
307- features = container . querySelectorAll ( 'map-feature' ) ,
308- meta ,
309- projection ;
310- for ( let i = 0 ; i < features . length ; i ++ ) {
311- let lZoom = + features [ i ] . getAttribute ( 'zoom' ) ;
312- if ( ! features [ i ] . getAttribute ( 'zoom' ) ) lZoom = nativeZoom ;
313- nMax = Math . max ( nMax , lZoom ) ;
314- nMin = Math . min ( nMin , lZoom ) ;
315- }
316- try {
317- projection = M . _metaContentToObject (
318- container
319- . querySelector ( 'map-meta[name=projection]' )
320- . getAttribute ( 'content' )
321- ) . content ;
322- meta = M . _metaContentToObject (
323- container . querySelector ( 'map-meta[name=zoom]' ) . getAttribute ( 'content' )
324- ) ;
325- } catch ( error ) {
326- return {
327- minZoom : 0 ,
328- maxZoom :
329- M [ projection || FALLBACK_PROJECTION ] . options . resolutions . length - 1 ,
330- minNativeZoom : nMin ,
331- maxNativeZoom : nMax
332- } ;
333- }
334- return {
335- minZoom : + meta . min ,
336- maxZoom : + meta . max ,
337- minNativeZoom : nMin ,
338- maxNativeZoom : nMax
339- } ;
340- } ,
341-
342203 addData : function ( mapml , nativeCS , nativeZoom ) {
343204 var features =
344205 mapml . nodeType === Node . DOCUMENT_NODE || mapml . nodeName === 'LAYER-'
0 commit comments