Skip to content

Commit 2ae8d1f

Browse files
committed
Revert "Rename / refactor _setLayerElExtent to _getExtent, create getter for"
This reverts commit f27ea67.
1 parent f27ea67 commit 2ae8d1f

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

src/layer.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ 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-
6359
constructor() {
6460
// Always call super first in constructor
6561
super();
@@ -441,6 +437,7 @@ export class MapLayer extends HTMLElement {
441437
}
442438
}
443439
zoomTo() {
440+
if (!this.extent) return;
444441
let map = this._layer._map,
445442
tL = this.extent.topLeft.pcrs,
446443
bR = this.extent.bottomRight.pcrs,

src/map-feature.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ 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();
158160
delete this._getFeatureExtent;
159161
}
160162
}
@@ -232,6 +234,9 @@ export class MapFeature extends HTMLElement {
232234
}
233235
}
234236

237+
if (Object.keys(mapmlvectors._layers).length === 1) {
238+
this._layer._setLayerElExtent();
239+
}
235240
this._setUpEvents();
236241
});
237242
}
@@ -256,6 +261,7 @@ export class MapFeature extends HTMLElement {
256261
mapmlvectors.layerBounds = M.getBounds(this._layer._content);
257262
// add feature layers to map
258263
// mapmlvectors._resetFeatures();
264+
this._layer._setLayerElExtent();
259265
// update map's zoom limit
260266
this._map._addZoomLimit(mapmlvectors);
261267
L.extend(mapmlvectors.options, mapmlvectors.zoomBounds);

src/mapml/layers/MapMLLayer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,13 @@ export var MapMLLayer = L.Layer.extend({
119119
extentEl: extentEl._DOMnode || extentEl
120120
}).addTo(this._map);
121121
extentEl.templatedLayer.setZIndex();
122+
this._setLayerElExtent();
122123
}
123124
} else {
124125
L.DomEvent.stopPropagation(e);
125126
extentEl.checked = false;
126127
if (this._layerEl.checked) this._map.removeLayer(extentEl.templatedLayer);
128+
this._setLayerElExtent();
127129
}
128130
},
129131
titleIsReadOnly() {
@@ -185,6 +187,7 @@ export var MapMLLayer = L.Layer.extend({
185187
this
186188
);
187189
}
190+
this._setLayerElExtent();
188191

189192
this.setZIndex(this.options.zIndex);
190193
this.getPane().appendChild(this._container);
@@ -258,7 +261,7 @@ export var MapMLLayer = L.Layer.extend({
258261
},
259262

260263
//sets the <layer-> elements .bounds property
261-
_getExtent: function () {
264+
_setLayerElExtent: function () {
262265
let bounds,
263266
zoomMax,
264267
zoomMin,
@@ -402,7 +405,8 @@ export var MapMLLayer = L.Layer.extend({
402405
}
403406
});
404407
if (bounds) {
405-
return Object.assign(
408+
//assigns the formatted extent object to .extent and spreads the zoom ranges to .extent also
409+
this._layerEl.extent = Object.assign(
406410
M._convertAndFormatPCRS(bounds, this._properties.crs),
407411
{ zoom: zoomBounds, projection: this._properties.projection }
408412
);

src/mapml/utils/Util.js

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

0 commit comments

Comments
 (0)