forked from FreifunkFranken/VPNkeyXchange
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.html
61 lines (58 loc) · 1.63 KB
/
map.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
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.2.0/css/ol.css" type="text/css">
<style>
.map {
height: 1000px;
width: 100%;
}
</style>
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.2.0/build/ol.js"></script>
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<title>KeyExchangeV2 Hoods</title>
</head>
<body>
<h2>KeyExchangeV2 Hoods</h2>
<div id="map" class="map"></div>
<script type="text/javascript">
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([10.5, 49.75]),
zoom: 9
})
});
$.getJSON('hoods.php', function(data) {
$.each(data, function(idx, obj) {
if(!('polygons' in obj)) {
return true; // continue
}
var hoodid = obj.id;
// At the moment, we add one layer PER POLYGON, not per hood. This should be improved at some point
$.each(obj.polygons, function(polyid, polygon) {
var polyCoords = [];
$.each(polygon, function(vertid, vertex) {
polyCoords.push(ol.proj.transform([vertex.lon, vertex.lat], 'EPSG:4326', 'EPSG:3857'));
});
polyCoords.push(polyCoords[0]); // Add first point as last point (= close polygon)
var feature = new ol.Feature({
geometry: new ol.geom.Polygon([polyCoords])
})
var layer = new ol.layer.Vector({
source: new ol.source.Vector({
features: [feature]
})
});
map.addLayer(layer);
});
});
});
</script>
</body>
</html>