diff --git a/src/mapml/layers/FeatureLayer.js b/src/mapml/layers/FeatureLayer.js index 82f4e8add..dd2ccf2d5 100644 --- a/src/mapml/layers/FeatureLayer.js +++ b/src/mapml/layers/FeatureLayer.js @@ -13,6 +13,11 @@ export var FeatureLayer = L.FeatureGroup.extend({ 2. for static templated feature: null 3. for non-templated feature: layer- (with no src) or mapml file (with src) */ + // options.extent: when you use a FeatureLayer, you can either get it to calculate the + // .layerBounds dynamically (the default), based on adds/removes of features from the layer/ + // or you can construct it with a bounds (via options.extent), + // which will then remain static for the lifetime of the layer + L.setOptions(this, options); if (this.options.static) { this._container = L.DomUtil.create( @@ -53,7 +58,7 @@ export var FeatureLayer = L.FeatureGroup.extend({ this.addData(mapml, native.cs, native.zoom); } else if (!mapml) { this.isVisible = false; - this.layerBounds = null; + this.layerBounds = this.options.extent ? this.options.extent : null; this.zoomBounds = this.options.zoomBounds; } }, @@ -273,14 +278,16 @@ export var FeatureLayer = L.FeatureGroup.extend({ } let layer = this.geometryToLayer(mapml, options, nativeCS, +zoom, title); - let ext = mapml.extent, - xmin = ext.topLeft.pcrs.horizontal, - ymin = ext.bottomRight.pcrs.vertical, - xmax = ext.bottomRight.pcrs.horizontal, - ymax = ext.topLeft.pcrs.vertical, - bnd = L.bounds(L.point(xmin, ymin), L.point(xmax, ymax)); + if (!this.options.extent) { + let ext = mapml.extent, + xmin = ext.topLeft.pcrs.horizontal, + ymin = ext.bottomRight.pcrs.vertical, + xmax = ext.bottomRight.pcrs.horizontal, + ymax = ext.topLeft.pcrs.vertical, + bnd = L.bounds(L.point(xmin, ymin), L.point(xmax, ymax)); - this.layerBounds = this.layerBounds ? this.layerBounds.extend(bnd) : bnd; + this.layerBounds = this.layerBounds ? this.layerBounds.extend(bnd) : bnd; + } if (layer) { // if the layer is being used as a query handler output, it will have // a color option set. Otherwise, copy classes from the feature diff --git a/src/mapml/layers/MapMLLayer.js b/src/mapml/layers/MapMLLayer.js index 811b82cea..7d3668aa7 100644 --- a/src/mapml/layers/MapMLLayer.js +++ b/src/mapml/layers/MapMLLayer.js @@ -1515,6 +1515,9 @@ export var MapMLLayer = L.Layer.extend({ pane: layer._container, opacity: layer.options.opacity, projection: layer._properties.projection, + // by NOT passing options.extent, we are asking the FeatureLayer + // to dynamically update its .layerBounds property as features are + // added or removed from it native: native, zoomBounds: M.getZoomBounds(layer._content, native.zoom), // each owned child layer gets a reference to the root layer diff --git a/src/mapml/layers/TemplatedFeaturesLayer.js b/src/mapml/layers/TemplatedFeaturesLayer.js index 2f2e3c3c1..a2f4550cb 100644 --- a/src/mapml/layers/TemplatedFeaturesLayer.js +++ b/src/mapml/layers/TemplatedFeaturesLayer.js @@ -35,6 +35,8 @@ export var TemplatedFeaturesLayer = L.Layer.extend({ // pass the vector layer the container for the parent into which // it will append its own container for rendering into pane: container, + // the extent will be static, fixed, constant for the lifetime of the layer + extent: this.extentBounds, opacity: opacity, projection: map.options.projection, static: true,