Leaflet/debug/tests/detached-dom-memory-leak.html
Thach Hoang 0d1eae32be Fix debug examples after rollup (#5417)
Fix #5373.

- Remove references to removed file "../../build/deps.js"
- Update leaflet-include.js to point to "../dist/leaflet-src.js"
- Update watch to use the same destination file as rollup (dist/leaflet-src.js)
- Define getRandomLatLng where used
2017-03-28 08:40:48 +02:00

56 lines
1.4 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Leaflet debug page</title>
<link rel="stylesheet" href="../../dist/leaflet.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../css/screen.css" />
<script src="../leaflet-include.js"></script>
<script>
var map,
mapDiv,
osm = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png');
var recreateMap = function(){
// destroy previous map and div
if(map) map.remove(); // This will destroy all DOM childs from layers and controls
if(mapDiv) mapDiv.parentNode.removeChild(mapDiv); // This will destroy the map div
// create new map div
var randomDivId = 'mapId' + new Date().getTime();
mapDiv = document.createElement('div');
mapDiv.id = randomDivId;
mapDiv.style.height = '200px';
mapDiv.style.width = '200px';
document.getElementsByTagName('body')[0].appendChild(mapDiv);
// attach map to div
map = L.map(randomDivId).setView([51.505, -0.09], 13);
map.addLayer(osm);
};
var interval = null;
function start(){
interval = window.setInterval(recreateMap, 200);
}
function stop() {
window.clearInterval(interval);
}
</script>
</head>
<body>
This page will destroy and recreate a map div lots of times. Developer tools shall not display a memory leak.
<div>
<button onclick='recreateMap();'>Once</button>
<button onclick='start();'>Start</button>
<button onclick='stop();'>Stop</button>
</div>
</body>
</html>