-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexample.customscale.html
49 lines (40 loc) · 1.45 KB
/
example.customscale.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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="leaflet/dist/leaflet.css" />
<!--[if lte IE 8]><link rel="stylesheet" href="leaflet/dist/leaflet.ie.css" /><![endif]-->
<script src="leaflet/build/deps.js"></script>
<script src="leaflet/debug/leaflet-include.js"></script>
<script src="leaflet.customscale/leaflet.customscale.js"></script>
</head>
<body>
<div id="map" style="width: 640px; height: 480px;"></div>
<script type="text/javascript">
var layerOsm = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
subdomains: ["a", "b", "c"],
maxZoom: 18
});
var map = new L.Map('map', {
fullscreenControl: true
}).addLayer(layerOsm).setView(new L.LatLng(40.524724, -3.816153), 6);
map.addControl(new L.Control.ScaleCustom({
metric: true,
imperial: true,
// Custom scale in nautical miles
custom: function(maxMeters, leafletDefaultRoundingFunction) {
var maxNauticalMiles = maxMeters / 1852,
nauticalMiles;
if(maxMeters >= 1852) {
nauticalMiles = leafletDefaultRoundingFunction(maxNauticalMiles);
} else {
nauticalMiles = maxNauticalMiles > 0.1 ? Math.round(maxNauticalMiles * 10) / 10 : Math.round(maxNauticalMiles * 100) / 100;
}
return {
caption: nauticalMiles + ' nm',
ratio: nauticalMiles / maxNauticalMiles
}
}
}));
</script>
</body>
</html>