Last active
December 14, 2015 16:29
-
-
Save leplatrem/5115239 to your computer and use it in GitHub Desktop.
Leaflet.LayerIndex example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
L.Map.include(L.LayerIndexMixin); | |
var map = L.map('map'); | |
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png').addTo(map); | |
map.fitWorld(); | |
map.addControl(new L.Control.Information()); | |
for (var i=0; i<5000; i++) { | |
var lat = Math.random() * 170 - 85 | |
, lng = Math.random() * 350 - 175; | |
var layer = L.circleMarker(L.latLng([lat, lng])).setRadius(1).addTo(map); | |
map.indexLayer(layer); | |
} | |
map.fire('moveend'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<link rel="stylesheet" href="http://leafletjs.com/dist/leaflet.css" /> | |
<!--[if lte IE 8]><link rel="stylesheet" href="http://leafletjs.com/dist/leaflet.ie.css" /><![endif]--> | |
<script>L_PREFER_CANVAS = true;</script> | |
</head> | |
<body> | |
<div id="map" style="height:300px"/> | |
<script src="http://leafletjs.com/dist/leaflet.js"></script> | |
<script src="https://raw.github.com/imbcmdth/RTree/master/src/rtree.js"></script> | |
<script src="https://raw.github.com/makinacorpus/Leaflet.LayerIndex/master/leaflet.layerindex.js"></script> | |
<script src="infocontrol.js"></script> | |
<script src="demo.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
L.Control.Information = L.Control.extend({ | |
options: { | |
position: 'bottomright', | |
}, | |
onAdd: function (map) { | |
this._container = L.DomUtil.create('div', 'leaflet-control-attribution'); | |
L.DomEvent.disableClickPropagation(this._container); | |
map.on('moveend', function (e) { | |
if (map._loaded) { | |
var shown = map.search(map.getBounds()); | |
console.log(map.getBounds().toBBoxString()); | |
this._container.innerHTML = shown.length + ' objects shown.'; | |
} | |
}, this); | |
return this._container; | |
}, | |
onRemove: function (map) { | |
map.off('moveend'); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment