-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest5.html
52 lines (42 loc) · 1.64 KB
/
test5.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
<html>
<head>
<title>Boundary explorer</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<div id="map" style="height:100%; width:100%"></div>
<script>
var tiles = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="https://carto.com/attributions">CARTO</a>'
});
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
var areacode = getQueryVariable("code");
var url = "http://statistics.data.gov.uk/boundaries/" + areacode + ".json";
function onEachFeature(feature, layer) {
var popupContent = feature.properties.LAD15NM + "<br />" + feature.properties.LAD15CD;
layer.bindPopup(popupContent);
}
// load GeoJSON from an external file
var boundary = $.getJSON(url, function(data){
//add GeoJSON layer to the map once the file is loaded
var boundary = L.geoJson(data, {onEachFeature: onEachFeature});
var map = L.map('map').fitBounds(boundary.getBounds());
tiles.addTo(map);
// boundary.bindPopup(feature.properties.LAD15NM);
boundary.addTo(map);
boundary.openPopup();
});
</script>
</body>
</html>