Skip to content

Commit 633c4ae

Browse files
committed
Update FeatureLayer to dynamically update .layerBounds if initialized
without a options.extent bounds
1 parent 57d3ecf commit 633c4ae

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/mapml/layers/FeatureLayer.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export var FeatureLayer = L.FeatureGroup.extend({
1313
2. for static templated feature: null
1414
3. for non-templated feature: layer- (with no src) or mapml file (with src)
1515
*/
16+
// options.extent: when you use a FeatureLayer, you can either get it to calculate the
17+
// .layerBounds dynamically (the default), based on adds/removes of features from the layer/
18+
// or you can construct it with a bounds (via options.extent),
19+
// which will then remain static for the lifetime of the layer
20+
1621
L.setOptions(this, options);
1722
if (this.options.static) {
1823
this._container = L.DomUtil.create(
@@ -53,7 +58,7 @@ export var FeatureLayer = L.FeatureGroup.extend({
5358
this.addData(mapml, native.cs, native.zoom);
5459
} else if (!mapml) {
5560
this.isVisible = false;
56-
this.layerBounds = null;
61+
this.layerBounds = this.options.extent ? this.options.extent : null;
5762
this.zoomBounds = this.options.zoomBounds;
5863
}
5964
},
@@ -273,14 +278,16 @@ export var FeatureLayer = L.FeatureGroup.extend({
273278
}
274279

275280
let layer = this.geometryToLayer(mapml, options, nativeCS, +zoom, title);
276-
let ext = mapml.extent,
277-
xmin = ext.topLeft.pcrs.horizontal,
278-
ymin = ext.bottomRight.pcrs.vertical,
279-
xmax = ext.bottomRight.pcrs.horizontal,
280-
ymax = ext.topLeft.pcrs.vertical,
281-
bnd = L.bounds(L.point(xmin, ymin), L.point(xmax, ymax));
281+
if (!this.options.extent) {
282+
let ext = mapml.extent,
283+
xmin = ext.topLeft.pcrs.horizontal,
284+
ymin = ext.bottomRight.pcrs.vertical,
285+
xmax = ext.bottomRight.pcrs.horizontal,
286+
ymax = ext.topLeft.pcrs.vertical,
287+
bnd = L.bounds(L.point(xmin, ymin), L.point(xmax, ymax));
282288

283-
this.layerBounds = this.layerBounds ? this.layerBounds.extend(bnd) : bnd;
289+
this.layerBounds = this.layerBounds ? this.layerBounds.extend(bnd) : bnd;
290+
}
284291
if (layer) {
285292
// if the layer is being used as a query handler output, it will have
286293
// a color option set. Otherwise, copy classes from the feature

src/mapml/layers/MapMLLayer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,9 @@ export var MapMLLayer = L.Layer.extend({
15151515
pane: layer._container,
15161516
opacity: layer.options.opacity,
15171517
projection: layer._properties.projection,
1518+
// by NOT passing options.extent, we are asking the FeatureLayer
1519+
// to dynamically update its .layerBounds property as features are
1520+
// added or removed from it
15181521
native: native,
15191522
zoomBounds: M.getZoomBounds(layer._content, native.zoom),
15201523
// each owned child layer gets a reference to the root layer

src/mapml/layers/TemplatedFeaturesLayer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export var TemplatedFeaturesLayer = L.Layer.extend({
3535
// pass the vector layer the container for the parent into which
3636
// it will append its own container for rendering into
3737
pane: container,
38+
// the extent will be static, fixed, constant for the lifetime of the layer
39+
extent: this.extentBounds,
3840
opacity: opacity,
3941
projection: map.options.projection,
4042
static: true,

0 commit comments

Comments
 (0)