@@ -70,25 +70,25 @@ export class MapFeature extends HTMLElement {
7070 attributeChangedCallback ( name , oldValue , newValue ) {
7171 switch ( name ) {
7272 case 'zoom' : {
73- this . whenReady ( ) . then ( ( ) => {
74- if ( oldValue !== newValue ) {
75- let layer = this . _layer ,
76- layerEl = layer . _layerEl ,
77- mapmlvectors = layer . _mapmlvectors ;
78- // if the vector layer only has static features, should update zoom bounds when zoom attribute is changed
79- if ( mapmlvectors ?. _staticFeature ) {
80- this . _removeInFeatureList ( oldValue ) ;
81- let native = this . _getNativeZoomAndCS ( layer . _content ) ;
82- mapmlvectors . zoomBounds = M . getZoomBounds (
83- layer . _content ,
84- native . zoom
85- ) ;
73+ if ( oldValue !== newValue && this . _layer ) {
74+ let layer = this . _layer ,
75+ zoom = newValue ,
76+ mapmlvectors = layer . _mapmlvectors ;
77+ // if the vector layer only has static features, should update zoom bounds when zoom attribute is changed
78+ if ( mapmlvectors . _staticFeature ) {
79+ this . _removeInFeatureList ( oldValue ) ;
80+ if ( zoom in mapmlvectors . _features ) {
81+ mapmlvectors . _features [ zoom ] . push ( this . _featureGroup ) ;
82+ } else {
83+ mapmlvectors . _features [ zoom ] = [ this . _featureGroup ] ;
8684 }
87- //this._removeFeature();
88- //this._updateFeature();
89- this . _reRender ( ) ;
85+ let native = this . _getNativeZoomAndCS ( layer . _content ) ;
86+ mapmlvectors . zoomBounds = M . getZoomBounds (
87+ layer . _content ,
88+ native . zoom
89+ ) ;
9090 }
91- } ) ;
91+ }
9292 break ;
9393 }
9494 }
@@ -123,8 +123,7 @@ export class MapFeature extends HTMLElement {
123123 return ;
124124 }
125125 // re-render feature if there is any observed change
126- this . _removeFeature ( ) ;
127- this . _updateFeature ( ) ;
126+ this . _reRender ( ) ;
128127 }
129128 } ) ;
130129 this . _observer . observe ( this , {
@@ -147,6 +146,7 @@ export class MapFeature extends HTMLElement {
147146 if ( this . _groupEl . isConnected ) {
148147 let native = this . _getNativeZoomAndCS ( this . _layer . _content ) ;
149148 let placeholder = document . createElement ( 'span' ) ;
149+ let mapmlvectors = this . _layer . _mapmlvectors ;
150150 this . _groupEl . insertAdjacentElement ( 'beforebegin' , placeholder ) ;
151151
152152 this . _featureGroup . _map . removeLayer ( this . _featureGroup ) ;
@@ -155,6 +155,9 @@ export class MapFeature extends HTMLElement {
155155 . addData ( this , native . cs , native . zoom )
156156 . addTo ( this . _map ) ;
157157 placeholder . replaceWith ( this . _featureGroup . options . group ) ;
158+ // TODO: getBounds() should dynamically update the layerBounds
159+ this . _layer . _setLayerElExtent ( ) ;
160+ delete this . _getFeatureExtent ;
158161 }
159162 }
160163
@@ -199,32 +202,43 @@ export class MapFeature extends HTMLElement {
199202 ? this . parentNode
200203 : this . parentNode . host ;
201204
202- // arrow function is not hoisted, define before use
203- let _attachedToMap = ( e ) => {
204- this . _parentEl . whenReady ( ) . then ( ( ) => {
205- let parentLayer =
206- this . _parentEl . nodeName . toUpperCase ( ) === 'LAYER-'
207- ? this . _parentEl
208- : this . _parentEl . parentElement || this . _parentEl . parentNode . host ;
209- this . _layer = parentLayer . _layer ;
210- this . _map = this . _layer . _map ;
211- // "synchronize" the event handlers between map-feature and <g>
212- if ( ! this . querySelector ( 'map-geometry' ) ) return ;
213- if ( ! this . _parentEl . _layer . _mapmlvectors ) {
214- // if vector layer has not yet created (i.e. the layer- is not yet rendered on the map / layer is empty)
215- this . _layer . once ( 'add' , this . _setUpEvents , this ) ;
216- return ;
217- } else if ( ! this . _featureGroup ) {
218- // if the map-feature el or its subtree is updated
219- // this._featureGroup has been free in this._removeFeature()
220- this . _updateFeature ( ) ;
221- } else {
222- this . _setUpEvents ( ) ;
205+ this . _parentEl . whenReady ( ) . then ( ( ) => {
206+ let parentLayer =
207+ this . _parentEl . nodeName . toUpperCase ( ) === 'LAYER-'
208+ ? this . _parentEl
209+ : this . _parentEl . parentElement || this . _parentEl . parentNode . host ;
210+ this . _layer = parentLayer . _layer ;
211+ this . _map = this . _layer . _map ;
212+ let mapmlvectors = this . _layer . _mapmlvectors ;
213+ // "synchronize" the event handlers between map-feature and <g>
214+ if ( ! this . querySelector ( 'map-geometry' ) ) return ;
215+ if ( ! this . _extentEl ) {
216+ let native = this . _getNativeZoomAndCS ( this . _layer . _content ) ;
217+ this . _featureGroup = mapmlvectors . addData ( this , native . cs , native . zoom ) ;
218+ if ( parentLayer . checked ) {
219+ this . _featureGroup . addTo ( this . _map ) ;
223220 }
224- } ) ;
225- } ;
221+ mapmlvectors . _layers [ this . _featureGroup . _leaflet_id ] =
222+ this . _featureGroup ;
223+ if ( mapmlvectors . _staticFeature && ! this . _extentEl ) {
224+ // update zoom bounds of vector layer
225+ mapmlvectors . zoomBounds = M . getZoomBounds (
226+ this . _layer . _content ,
227+ this . _getNativeZoomAndCS ( this . _layer . _content ) . zoom
228+ ) ;
229+ // todo: dynamically update layer bounds of vector layer
230+ mapmlvectors . layerBounds = M . getBounds ( this . _layer . _content ) ;
231+ // update map's zoom limit
232+ this . _map . _addZoomLimit ( mapmlvectors ) ;
233+ L . extend ( mapmlvectors . options , mapmlvectors . zoomBounds ) ;
234+ }
235+ }
226236
227- _attachedToMap ( ) ;
237+ if ( Object . keys ( mapmlvectors . _layers ) . length === 1 ) {
238+ this . _layer . _setLayerElExtent ( ) ;
239+ }
240+ this . _setUpEvents ( ) ;
241+ } ) ;
228242 }
229243
230244 _updateFeature ( ) {
@@ -246,7 +260,7 @@ export class MapFeature extends HTMLElement {
246260 // update layer bounds of vector layer
247261 mapmlvectors . layerBounds = M . getBounds ( this . _layer . _content ) ;
248262 // add feature layers to map
249- mapmlvectors . _resetFeatures ( ) ;
263+ // mapmlvectors._resetFeatures();
250264 this . _layer . _setLayerElExtent ( ) ;
251265 // update map's zoom limit
252266 this . _map . _addZoomLimit ( mapmlvectors ) ;
0 commit comments