Skip to content

Commit f27ea67

Browse files
prushforprushfor
authored andcommitted
Rename / refactor _setLayerElExtent to _getExtent, create getter for
layer-.extent that invokes synchronously.
1 parent 2a077dd commit f27ea67

File tree

4 files changed

+9
-18
lines changed

4 files changed

+9
-18
lines changed

src/layer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ export class MapLayer extends HTMLElement {
5656
this.setAttribute('opacity', val);
5757
}
5858

59+
get extent() {
60+
if (this._layer) return this._layer._getExtent();
61+
}
62+
5963
constructor() {
6064
// Always call super first in constructor
6165
super();
@@ -437,7 +441,6 @@ export class MapLayer extends HTMLElement {
437441
}
438442
}
439443
zoomTo() {
440-
if (!this.extent) return;
441444
let map = this._layer._map,
442445
tL = this.extent.topLeft.pcrs,
443446
bR = this.extent.bottomRight.pcrs,

src/map-feature.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ 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();
160158
delete this._getFeatureExtent;
161159
}
162160
}
@@ -234,9 +232,6 @@ export class MapFeature extends HTMLElement {
234232
}
235233
}
236234

237-
if (Object.keys(mapmlvectors._layers).length === 1) {
238-
this._layer._setLayerElExtent();
239-
}
240235
this._setUpEvents();
241236
});
242237
}
@@ -261,7 +256,6 @@ export class MapFeature extends HTMLElement {
261256
mapmlvectors.layerBounds = M.getBounds(this._layer._content);
262257
// add feature layers to map
263258
// mapmlvectors._resetFeatures();
264-
this._layer._setLayerElExtent();
265259
// update map's zoom limit
266260
this._map._addZoomLimit(mapmlvectors);
267261
L.extend(mapmlvectors.options, mapmlvectors.zoomBounds);

src/mapml/layers/MapMLLayer.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,11 @@ export var MapMLLayer = L.Layer.extend({
119119
extentEl: extentEl._DOMnode || extentEl
120120
}).addTo(this._map);
121121
extentEl.templatedLayer.setZIndex();
122-
this._setLayerElExtent();
123122
}
124123
} else {
125124
L.DomEvent.stopPropagation(e);
126125
extentEl.checked = false;
127126
if (this._layerEl.checked) this._map.removeLayer(extentEl.templatedLayer);
128-
this._setLayerElExtent();
129127
}
130128
},
131129
titleIsReadOnly() {
@@ -187,7 +185,6 @@ export var MapMLLayer = L.Layer.extend({
187185
this
188186
);
189187
}
190-
this._setLayerElExtent();
191188

192189
this.setZIndex(this.options.zIndex);
193190
this.getPane().appendChild(this._container);
@@ -261,7 +258,7 @@ export var MapMLLayer = L.Layer.extend({
261258
},
262259

263260
//sets the <layer-> elements .bounds property
264-
_setLayerElExtent: function () {
261+
_getExtent: function () {
265262
let bounds,
266263
zoomMax,
267264
zoomMin,
@@ -405,8 +402,7 @@ export var MapMLLayer = L.Layer.extend({
405402
}
406403
});
407404
if (bounds) {
408-
//assigns the formatted extent object to .extent and spreads the zoom ranges to .extent also
409-
this._layerEl.extent = Object.assign(
405+
return Object.assign(
410406
M._convertAndFormatPCRS(bounds, this._properties.crs),
411407
{ zoom: zoomBounds, projection: this._properties.projection }
412408
);

src/mapml/utils/Util.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,9 @@ export var Util = {
533533
layer.parentElement.querySelectorAll('layer-').length === 1
534534
)
535535
layer.parentElement.projection = layer._layer.getProjection();
536-
if (layer.extent) {
537-
if (zoomTo)
538-
layer.parentElement.zoomTo(+zoomTo.lat, +zoomTo.lng, +zoomTo.z);
539-
else layer.zoomTo();
540-
}
536+
if (zoomTo)
537+
layer.parentElement.zoomTo(+zoomTo.lat, +zoomTo.lng, +zoomTo.z);
538+
else layer.zoomTo();
541539
if (opacity) layer.opacity = opacity;
542540
map.getContainer().focus();
543541
});

0 commit comments

Comments
 (0)