-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample_map_with_markers.html
executable file
·71 lines (65 loc) · 2.36 KB
/
sample_map_with_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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>OpenStreetMap & OpenLayers - Marker Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/css/ol.css" type="text/css">
<script src="https://openlayers.org/en/v4.6.5/build/ol.js" type="text/javascript"></script>
<script>
var map;
var mapLat = -36.8513;
var mapLng = 174.7644;
var mapDefaultZoom = 11;
function initialize_map() {
map = new ol.Map({
target: "map",
layers: [
new ol.layer.Tile({
source: new ol.source.OSM({
url: "https://a.tile.openstreetmap.org/{z}/{x}/{y}.png"
})
})
],
view: new ol.View({
center: ol.proj.fromLonLat([mapLng, mapLat]),
zoom: mapDefaultZoom
})
});
}
function add_map_point(lat, lng) {
var vectorLayer = new ol.layer.Vector({
source:new ol.source.Vector({
features: [new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([parseFloat(lng), parseFloat(lat)], 'EPSG:4326', 'EPSG:3857')),
})]
}),
style: new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 0.5],
anchorXUnits: "fraction",
anchorYUnits: "fraction",
src: "https://upload.wikimedia.org/wikipedia/commons/e/ec/RedDot.svg"
})
})
});
map.addLayer(vectorLayer);
}
var req = new XMLHttpRequest();
req.open("GET", "https://raw.githubusercontent.com/PaulAtKeyboard/OpenCCTV/master/data-AT-CCTV.json", false);
req.send();
var data = JSON.parse(req.responseText);
console.log(data[0]);
function make_map() {
for (rows of data) {
add_map_point(rows["Lattitude"], rows["Longitude"]);
}
}
</script>
<style type="text/css"></style>
</head>
<body onload="initialize_map(); make_map();">
<div id="map" style="position: absolute; width: 75vw; height: 100vh; left: 0; top: 0"></div>
<div style="position: absolute; width: 25vw; height: 100vh; right: 0; top: 0; background-color: #222; color: #efefef; font-family: sans-serif; line-height: 10vh; text-align: center; font-size: 15pt;">Public Security Cameras around Auckland</div>
</body>
</html>