-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
69 lines (44 loc) · 1.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html>
<head>
<title>Async Example</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="Leaflet/dist/leaflet.css" />
<!--[if lte IE 8]><link rel="stylesheet" href="Leaflet/dist/leaflet.ie.css" /><![endif]-->
</head>
<body>
<div id="map" style="width: 600px; height: 400px"></div>
<script src="Leaflet/dist/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
var map = new L.Map('map');
var markersLayer = new L.LayerGroup();
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});
map.setView(new L.LatLng(40.81259, -96.70189), 13).addLayer(cloudmade);
$(function() {
loadMarkers();
map.on('drag', function(e) {
markersLayer.clearLayers();
});
map.on('dragend', function(e) {
loadMarkers();
});
});
function loadMarkers() {
markersLayer.clearLayers();
var bounds = map.getBounds();
bounds = bounds._northEast.lat + ',' + bounds._northEast.lng + ',' + bounds._southWest.lat + ',' + bounds._southWest.lng;
$.get("ajax.php?bounds=" + bounds, { some_var: "" }, function(data){
$(data).each(function() {
var marker = new L.Marker(new L.LatLng(this.lat, this.lng));
markersLayer.addLayer(marker);
map.addLayer(markersLayer);
});
}, 'json');
}
</script>
</body>
</html>