Skip to content

Commit

Permalink
WIP on map-link:
Browse files Browse the repository at this point in the history
- fix bug in first added or removed map-feature
  • Loading branch information
prushfor authored and prushfor committed Feb 18, 2024
1 parent dd0cbe8 commit 7cb1984
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/mapml/layers/FeatureLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,13 @@ export var FeatureLayer = L.FeatureGroup.extend({
// static FeatureLayer (e.g. MapMLLayer._mapmlvectors) NEVER has a
// .layerBounds property, so if there is this.options.layerBounds, don't
// go copying it to this.layerBounds. Same for zoomBounds.
// bug alert: it's necessary to create a new bounds object to initialize
// this.layerBounds, to avoid changing the layerBounds of the first geometry
// added to this layer
if (!this.options.layerBounds) {
this.layerBounds = this.layerBounds
? this.layerBounds.extend(layerToAdd.layerBounds)
: layerToAdd.layerBounds;
: L.bounds(layerToAdd.layerBounds.min, layerToAdd.layerBounds.max);

if (this.zoomBounds) {
if (layerToAdd.zoomBounds.minZoom < this.zoomBounds.minZoom)
Expand Down Expand Up @@ -178,12 +181,15 @@ export var FeatureLayer = L.FeatureGroup.extend({
let layerIds = Object.keys(this._layers);
// re-calculate the layerBounds and zoomBounds for the whole layer when
// a feature is permanently removed from the overall layer
// bug alert: it's necessary to create a new bounds object to initialize
// this.layerBounds, to avoid changing the layerBounds of the first geometry
// added to this layer
for (let id of layerIds) {
let layer = this._layers[id];
if (layerBounds) {
layerBounds.extend(layer.layerBounds);
} else {
layerBounds = layer.layerBounds;
layerBounds = L.bounds(layer.layerBounds.min, layer.layerBounds.max);
}
if (zoomBounds) {
if (layer.zoomBounds.minZoom < zoomBounds.minZoom)
Expand Down

0 comments on commit 7cb1984

Please sign in to comment.