Skip to content

Commit

Permalink
Add resetOverlayLayers event listener
Browse files Browse the repository at this point in the history
  • Loading branch information
stilist committed Nov 21, 2017
1 parent 67f524c commit 189b03b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
12 changes: 12 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.min.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/map.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
control,
icon,
Layer,
map,
MapOptions,
Marker,
Expand Down Expand Up @@ -55,8 +56,21 @@ function addMap(id: string = "map", options: MapOptions = {}) {
// This is necessary because `control.layers(...)` always creates a new layer
// control -- it's a better user experience to add *all* layers to a single
// control.
const addedOverlayLayers: Layer[] = [];
instance.on("addOverlayLayer", (event: ICustomLeafletEvent) => {
layers.addOverlay(event.overlayLayer, event.key);
addedOverlayLayers.push(event.overlayLayer);
});
// There doesn't seem to be a way to determine what layers have been added to
// the control.
instance.on("resetOverlayLayers", () => {
for (const layer of addedOverlayLayers) {
layers.removeLayer(layer);
instance.removeLayer(layer);

const index = addedOverlayLayers.indexOf(layer);
addedOverlayLayers.splice(index, 1);
}
});

return instance;
Expand Down

0 comments on commit 189b03b

Please sign in to comment.