forked from Turbo87/leaflet-sidebar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisting-markers.html
92 lines (73 loc) · 2.94 KB
/
listing-markers.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<head>
<title>leaflet-sidebar example</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<link rel="stylesheet" href="../src/L.Control.Sidebar.css" />
<!--[if lte IE 8]><link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.ie.css" /><![endif]-->
<style>
body {
padding: 30px;
font-family: sans-serif;
}
#map {
width: 100%;
height: 600px;
border-radius: 10px;
}
#sidebar {
padding: 24px;
font-family: monospace;
}
</style>
</head>
<body>
<div id="sidebar"></div>
<div id="map"></div>
<p>This is based on a <a href="https://www.mapbox.com/mapbox.js/example/v1.0.0/listing-markers/">mapbox.js example</a>, but implemented with the leaflet-sidebar plugin instead.</p>
<a href="https://github.com/Turbo87/leaflet-sidebar/"><img style="position: fixed; top: 0; right: 0; border: 0; z-index: 3000" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<script src="../src/L.Control.Sidebar.js"></script>
<script>
var map = L.map('map');
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © OpenStreetMap contributors'
}).addTo(map);
var sidebar = L.control.sidebar('sidebar', {
closeButton: false,
position: 'right'
});
map.addControl(sidebar);
setTimeout(function () {
sidebar.show();
}, 500);
var markers = [];
for (var x = -120; x < 120; x += 20) {
for (var y = -80; y < 80; y += 10) {
var marker = L.marker([x, y]).addTo(map);
marker.options.title = [x, y].join(',');
markers.push(marker);
}
}
map.on('move', function() {
// construct an empty list to fill with onscreen markers
var inBounds = [],
// get the map bounds - the top-left and bottom-right locations
bounds = map.getBounds();
// for each marker, consider whether it is currently visible by comparing
// with the current map bounds
for (var i = 0, len = markers.length; i < len; i++) {
var marker = markers[i];
if (bounds.contains(marker.getLatLng())) {
inBounds.push(marker.options.title);
}
}
// display a list of markers.
sidebar.setContent(inBounds.join('<br>\n'));
});
map.setView([37, -77], 5);
</script>
</body>
</html>