Y-SLD/assets/plugins/leaflet/markercluster/example/old-bugs/removelayer-after-remove-fr...

70 lines
2.2 KiB
HTML
Raw Normal View History

2024-03-01 11:23:55 +00:00
<!DOCTYPE html>
<html>
<head>
<title>Leaflet debug page</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet-src.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../screen.css" />
<link rel="stylesheet" href="../../dist/MarkerCluster.css" />
<link rel="stylesheet" href="../../dist/MarkerCluster.Default.css" />
<script src="../../src/DistanceGrid.js"></script>
<script src="../../src/MarkerCluster.js"></script>
<script src="../../src/MarkerClusterGroup.js"></script>
<script src="../../src/MarkerCluster.QuickHull.js"></script>
<script src="../../src/MarkerCluster.Spiderfier.js"></script>
</head>
<body>
<div id="map"></div>
<a href="#" onclick="swapLayers()">1 - Swap layers</a><br>
<a href="#" onclick="removeMarker()">2 - Remove all markers</a><br>
<a href="#" onclick="swapLayers()">3 - Swap layers again =&gt; Marker is still there<a/></br>
<span>Bug <a href="https://github.com/danzel/Leaflet.markercluster/issues/160">#160</a>. Click 1,2,3. There should be nothing on the map.</span><br/>
<script type="text/javascript">
var map = new L.Map('map');
var tiles = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
});
map.addLayer(tiles);
var objectBounds = [[44.98131207805678, 6.0726203025917], [44.981459751363204, 6.073026722623153]];
map.fitBounds(new L.LatLngBounds(objectBounds));
var markers1 = new L.MarkerClusterGroup();
var markers2 = new L.MarkerClusterGroup();
map.addLayer(markers1);
var aMarker = new L.Marker(new L.LatLng(44.9813, 6.072620));
var anotherMarker = new L.Marker(new L.LatLng(44.9814, 6.072621));
markers1.addLayer(aMarker);
markers2.addLayer(anotherMarker);
swapLayers = function(){
if (map.hasLayer(markers1)){
map.removeLayer(markers1);
map.addLayer(markers2);
}else{
map.removeLayer(markers2);
map.addLayer(markers1);
}
};
removeMarker = function(){
markers1.removeLayer(aMarker);
markers2.removeLayer(anotherMarker);
};
</script>
</body>
</html>