Skip to content

Commit

Permalink
Adding an example of toggling hex layer on/off and moved the fix around
Browse files Browse the repository at this point in the history
  • Loading branch information
reblace committed Feb 18, 2022
1 parent ac45dac commit ce07d21
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
14 changes: 12 additions & 2 deletions examples/hexbins/advanced.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

<h2>Leaflet d3 Hexbin Example</h2>
<p>Demonstrates advanced functionality</p>
<button onclick="toggleLayer()">Toggle Hexbins Layer</button>

<!-- The map element -->
<div id="map" style="width: 600px; height: 400px; border: 1px solid #ccc"></div>
Expand Down Expand Up @@ -66,8 +67,6 @@ <h2>Leaflet d3 Hexbin Example</h2>
]
}));

hexLayer.addTo(map);

// Set up events
hexLayer.dispatch()
.on('mouseover', function(d, i) {
Expand Down Expand Up @@ -95,6 +94,17 @@ <h2>Leaflet d3 Hexbin Example</h2>
hexLayer.data(data);
}

var layerVisible = false;
function toggleLayer() {
if (layerVisible) {
map.removeLayer(hexLayer);
}
else {
map.addLayer(hexLayer);
}
layerVisible = !layerVisible;
}

generateData();

</script>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"artifactName": "leaflet-d3",
"moduleName": "leafletD3",
"description": "Custom d3 layers for leaflet",
"version": "4.4.0",
"author": "Asymmetrik, Ltd.",
"copyright": "Copyright (c) 2007-2019 Asymmetrik Ltd, a Maryland Corporation",
"version": "4.4.1",
"author": "Asymmetrik, Ltd. a BlueHalo Company",
"copyright": "Copyright (c) 2007-2022 Asymmetrik Ltd, a BlueHalo Company",
"license": "MIT",
"scripts": {
"build": "npm run bundle",
Expand Down
9 changes: 1 addition & 8 deletions src/js/hexbin/HexbinLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ L.HexbinLayer = L.SVG.extend({

this._map = null;

d3.select(this._container).remove();

// Explicitly will leave the data array alone in case the layer will be shown again
//this._data = [];

},

/**
Expand All @@ -148,9 +143,7 @@ L.HexbinLayer = L.SVG.extend({
* @private
*/
_destroyContainer: function() {

// Don't do anything

d3.select(this._container).remove();
},

/**
Expand Down

0 comments on commit ce07d21

Please sign in to comment.