mirror of
https://github.com/Leaflet/Leaflet.markercluster.git
synced 2025-07-28 04:21:51 +00:00
Tidy up examples. Add a -everything example which shows boundarys on mouse over and zooms on click.
This commit is contained in:
@ -32,23 +32,14 @@
|
||||
var map = new L.Map('map', {center: latlng, zoom: 15, layers: [cloudmade]});
|
||||
|
||||
var markers = new L.MarkerClusterGroup();
|
||||
var markersList = [];
|
||||
|
||||
function populate() {
|
||||
for (var i = 0; i < 100; i++) {
|
||||
var m = new L.Marker(getRandomLatLng(map));
|
||||
markersList.push(m);
|
||||
markers.addLayer(m);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function populateRandomVector() {
|
||||
for (var i = 0, latlngs = [], len = 20; i < len; i++) {
|
||||
latlngs.push(getRandomLatLng(map));
|
||||
}
|
||||
var path = new L.Polyline(latlngs);
|
||||
map.addLayer(path);
|
||||
}
|
||||
function getRandomLatLng(map) {
|
||||
var bounds = map.getBounds(),
|
||||
southWest = bounds.getSouthWest(),
|
||||
@ -61,37 +52,41 @@
|
||||
southWest.lng + lngSpan * Math.random());
|
||||
}
|
||||
|
||||
markers.on('click', function (a) {
|
||||
|
||||
|
||||
var polygon;
|
||||
var polygonCluster;
|
||||
markers.on('mouseover', function (a) {
|
||||
if (a.layer instanceof L.MarkerCluster) {
|
||||
console.log('cluster ' + a.layer.getAllChildMarkers().length);
|
||||
//a.layer.zoomToBounds();
|
||||
|
||||
var path = new L.Polygon(a.layer.getConvexHull());
|
||||
map.addLayer(path);
|
||||
if (polygon) {
|
||||
map.removeLayer(polygon);
|
||||
}
|
||||
polygon = new L.Polygon(a.layer.getConvexHull());
|
||||
map.addLayer(polygon);
|
||||
} else {
|
||||
console.log('marker ' + a.layer);
|
||||
}
|
||||
});
|
||||
|
||||
populate();
|
||||
//populateRandomVector();
|
||||
map.addLayer(markers);
|
||||
markers.on('mouseout', function (a) {
|
||||
if (a.layer instanceof L.MarkerCluster && polygon) {
|
||||
map.removeLayer(polygon);
|
||||
polygon = null;
|
||||
}
|
||||
});
|
||||
|
||||
L.DomUtil.get('populate').onclick = function () {
|
||||
var bounds = map.getBounds(),
|
||||
southWest = bounds.getSouthWest(),
|
||||
northEast = bounds.getNorthEast(),
|
||||
lngSpan = northEast.lng - southWest.lng,
|
||||
latSpan = northEast.lat - southWest.lat;
|
||||
var m = new L.Marker(new L.LatLng(
|
||||
southWest.lat + latSpan * 0.5,
|
||||
southWest.lng + lngSpan * 0.5));
|
||||
markersList.push(m);
|
||||
markers.addLayer(m);
|
||||
};
|
||||
L.DomUtil.get('remove').onclick = function () {
|
||||
markers.removeLayer(markersList.pop());
|
||||
};
|
||||
map.on('zoomend', function () {
|
||||
if (polygon) {
|
||||
map.removeLayer(polygon);
|
||||
polygon = null;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
populate();
|
||||
map.addLayer(markers);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
92
example/marker-clustering-everything.html
Normal file
92
example/marker-clustering-everything.html
Normal file
@ -0,0 +1,92 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Leaflet debug page</title>
|
||||
|
||||
<link rel="stylesheet" href="../lib/leaflet-dist/leaflet.css" />
|
||||
<!--[if lte IE 8]><link rel="stylesheet" href="../lib/leaflet-dist/leaflet.ie.css" /><![endif]-->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="screen.css" />
|
||||
<script src="../lib/leaflet-dist/leaflet-src.js"></script>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../src/MarkerCluster.css" />
|
||||
<link rel="stylesheet" href="../src/MarkerCluster.Default.css" />
|
||||
<script src="../src/MarkerClusterGroup.js"></script>
|
||||
<script src="../src/MarkerCluster.js"></script>
|
||||
<script src="../src/MarkerCluster.QuickHull.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="map"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
|
||||
cloudmadeAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade',
|
||||
cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution}),
|
||||
latlng = new L.LatLng(50.5, 30.51);
|
||||
|
||||
var map = new L.Map('map', {center: latlng, zoom: 15, layers: [cloudmade]});
|
||||
|
||||
var markers = new L.MarkerClusterGroup();
|
||||
var markersList = [];
|
||||
|
||||
function populate() {
|
||||
for (var i = 0; i < 100; i++) {
|
||||
var m = new L.Marker(getRandomLatLng(map));
|
||||
markersList.push(m);
|
||||
markers.addLayer(m);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function getRandomLatLng(map) {
|
||||
var bounds = map.getBounds(),
|
||||
southWest = bounds.getSouthWest(),
|
||||
northEast = bounds.getNorthEast(),
|
||||
lngSpan = northEast.lng - southWest.lng,
|
||||
latSpan = northEast.lat - southWest.lat;
|
||||
|
||||
return new L.LatLng(
|
||||
southWest.lat + latSpan * Math.random(),
|
||||
southWest.lng + lngSpan * Math.random());
|
||||
}
|
||||
|
||||
//Zoom on cluster click
|
||||
markers.on('click', function (a) {
|
||||
if (a.layer instanceof L.MarkerCluster) {
|
||||
a.layer.zoomToBounds();
|
||||
}
|
||||
});
|
||||
|
||||
//Show convex hull (boundary) polygon on mouse over
|
||||
var polygon;
|
||||
var polygonCluster;
|
||||
markers.on('mouseover', function (a) {
|
||||
if (a.layer instanceof L.MarkerCluster) {
|
||||
if (polygon) {
|
||||
map.removeLayer(polygon);
|
||||
}
|
||||
polygon = new L.Polygon(a.layer.getConvexHull());
|
||||
map.addLayer(polygon);
|
||||
}
|
||||
});
|
||||
markers.on('mouseout', function (a) {
|
||||
if (a.layer instanceof L.MarkerCluster && polygon) {
|
||||
map.removeLayer(polygon);
|
||||
polygon = null;
|
||||
}
|
||||
});
|
||||
map.on('zoomend', function () {
|
||||
if (polygon) {
|
||||
map.removeLayer(polygon);
|
||||
polygon = null;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
populate();
|
||||
map.addLayer(markers);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user