Skip to content

Commit 6790317

Browse files
committed
Update how map-feature / mapmlvectors calculates FeatureLayer.layerBounds
Update FeatureLayer to dynamically update .layerBounds if initialized without a options.extent bounds Apply temporary patch to get multipleExtents.test.js working in debug mode Change FeatureLayer, no longer extend / shrink layerBounds as features are added. Pass layerBounds to M.featureLayer initialize via option during initialization; use M.getBounds(mapml) to derive bounds from map-meta in the MapMLLayer._content (in the case of MapMLLayer._mapmlvectors), pass the derived bounds (from TemplatedFeaturesLayer.extentBounds and TemplatedTileLayer.extentBounds) when creating a FeatureLayer in those contexts. (templated layers' extentBounds property is derived from their child map-input axis min/max values, with the M._extractInputBounds utility).
1 parent b40a3a0 commit 6790317

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

src/mapml/layers/FeatureLayer.js

Lines changed: 9 additions & 2 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(
@@ -47,13 +52,15 @@ export var FeatureLayer = L.FeatureGroup.extend({
4752
this._staticFeature = true;
4853
this.isVisible = true; //placeholder for when this actually gets updated in the future
4954
this.zoomBounds = M.getZoomBounds(mapml, native.zoom);
50-
this.layerBounds = M.getLayerBounds(mapml);
55+
this.layerBounds = M.getBounds(mapml);
5156
L.extend(this.options, this.zoomBounds);
5257
}
5358
this.addData(mapml, native.cs, native.zoom);
5459
} else if (!mapml) {
5560
this.isVisible = false;
56-
this.layerBounds = this.options.extent;
61+
this.layerBounds = this.options.layerBounds
62+
? this.options.layerBounds
63+
: null;
5764
this.zoomBounds = this.options.zoomBounds;
5865
}
5966
},

src/mapml/layers/MapMLLayer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,10 @@ export var MapMLLayer = L.Layer.extend({
15151515
pane: layer._container,
15161516
opacity: layer.options.opacity,
15171517
projection: layer._properties.projection,
1518-
extent: M.getBounds(layer._content),
1518+
layerBounds: M.getBounds(layer._content),
1519+
// by NOT passing options.extent, we are asking the FeatureLayer
1520+
// to dynamically update its .layerBounds property as features are
1521+
// added or removed from it
15191522
native: native,
15201523
zoomBounds: M.getZoomBounds(layer._content, native.zoom),
15211524
// 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 bounds will be static, fixed, constant for the lifetime of the layer
39+
layerBounds: this.extentBounds,
3840
opacity: opacity,
3941
projection: map.options.projection,
4042
static: true,

src/mapml/layers/TemplatedTileLayer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export var TemplatedTileLayer = L.TileLayer.extend({
166166
let tileFeatures = M.featureLayer(null, {
167167
projection: this._map.options.projection,
168168
static: false,
169+
layerBounds: this.extentBounds,
169170
interactive: false
170171
});
171172

0 commit comments

Comments
 (0)