Skip to content

Commit

Permalink
Fixed bug causing adding and removing overlays to break due to confus…
Browse files Browse the repository at this point in the history
…ed references
  • Loading branch information
DavidSouthgate committed Oct 2, 2020
1 parent abdce1c commit 879c4a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 36 deletions.
21 changes: 8 additions & 13 deletions src/map.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
L.MultiMap.Map = L.Class.extend({
id: null,
tileLayerIds: [],
zoomOffset: 0,
vanillaOptions: {},
_overlayMaps: {},
_vanillaMap: null,
_vanillaTileLayers: null,
_vanillaLayersControl: null,

initialize: function(id = null, options = {}) {
this.id = id;
this.tileLayerIds = options.tileLayerIds ? options.tileLayerIds : this.tileLayerIds;
this.zoomOffset = options.zoomOffset ? options.zoomOffset : this.zoomOffset;
this.vanillaOptions = options.vanillaOptions ? options.vanillaOptions : this.vanillaOptions;
this.id = id ? id : null;
this.tileLayerIds = options.tileLayerIds ? options.tileLayerIds : [];
this.zoomOffset = options.zoomOffset ? options.zoomOffset : 0;
this.vanillaOptions = options.vanillaOptions ? options.vanillaOptions : {};
this._overlayMaps = {};
this._vanillaMap = null;
this._vanillaTileLayers = null;
this._vanillaLayersControl = null;
}
});

Expand Down
23 changes: 7 additions & 16 deletions src/multi-map.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import cloneLayer from "@davidsouthgate/leaflet-clonelayer";

L.MultiMap = L.Class.extend({
id: null,
tileLayers: [],
maps: [],
center: [0, 0],
zoom: 0,
_currentMapId: null,
_currentMapIndex: null,

initialize: function(id = null, options = {}) {
this.id = id;
this.tileLayers = options.tileLayers ? options.tileLayers : this.tileLayers;
this.maps = options.maps ? options.maps : this.maps;
this.center = options.center ? options.center : this.center;
this.zoom = options.zoom ? options.zoom : this.zoom;
this.tileLayers = options.tileLayers ? options.tileLayers : [];
this.maps = options.maps ? options.maps : [];
this.center = options.center;
this.zoom = options.zoom ? options.zoom : 0;
this._currentMapId = null;
this._currentMapIndex = null;

// TODO. Needed?
this._onBaseLayerChange = this._onBaseLayerChange.bind(this);
Expand Down Expand Up @@ -90,9 +84,6 @@ L.MultiMap = L.Class.extend({
}
}

console.log("===");
console.log(activeLayers);

return {
...map.vanillaOptions,
zoom: this.zoom - map.zoomOffset,
Expand Down Expand Up @@ -144,7 +135,7 @@ L.MultiMap = L.Class.extend({

_onOverlayAdd: function (event) {
for(const map of this.maps) {
const layer = map._overlayMaps[event.name];
let layer = map._overlayMaps[event.name];
map.vanillaMap.addLayer(layer);
}
},
Expand Down
10 changes: 3 additions & 7 deletions src/tile-layer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
L.MultiMap.TileLayer = L.Class.extend({
id: null,
title: null,
vanillaTileLayer: null,

initialize: function(id = null, options = {}) {
this.id = id ? id : this.id;
this.title = options.title ? options.title : this.title;
this.vanillaTileLayer = options.vanillaTileLayer ? options.vanillaTileLayer : this.vanillaTileLayer;
this.id = id ? id : null;
this.title = options.title ? options.title : null;
this.vanillaTileLayer = options.vanillaTileLayer ? options.vanillaTileLayer : null;
}
});

Expand Down

0 comments on commit 879c4a0

Please sign in to comment.