-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
181 lines (165 loc) · 6.31 KB
/
index.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="http://openlayers.org/en/v3.19.1/css/ol.css" type="text/css">
<link rel="stylesheet" href="css/ol3-layerswitcher.css" type="text/css">
<link rel="stylesheet" href="css/main.css" type="text/css">
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://openlayers.org/en/v3.19.1/build/ol.js" type="text/javascript"></script>
<script src="js/ol3-layerswitcher.js" type="text/javascript"></script>
<script src="styles.js" type="text/javascript"></script>
<title>SHA2017 Map</title>
<style>
html {
height: 100%;
}
body{
border: 0px;
margin: 0px;
padding: 0px;
}
#map, body {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="map" class="map">
<div id="popup" class="ol-popup">
<a href="#" id="popup-closer" class="ol-popup-closer"></a>
<div id="popup-content">asdfasdfasdfasdf</div>
</div>
</div>
<script type="text/javascript">
function isMobile() {
try{ document.createEvent("TouchEvent"); return true; }
catch(e){ return false; }
}
var map, base_layers, overlay_layers;
$(function() {
$.getJSON('config.json', createMap);
});
var wikiUrl = "https://orga.sha2017.org/";
var wikiDataUrl = "wikidata.php?handle=";
// Direct access to the wiki is possible if the wiki allows Cross-Origin Requests.
//var wikiDataUrl = wikiUrl + "api.php?action=askargs&printouts=Summary&format=json&conditions=Handle::0x";
function createMap(config) {
base_layers = new ol.layer.Group({
title: 'Base Layers',
layers: [
new ol.layer.Tile({ title: "OSM", type: 'base', source: new ol.source.OSM() }),
new ol.layer.Tile({ title: "Blank", type: 'base'})
]
});
overlay_layers = new ol.layer.Group({
title: 'Overlays', layers: []
});
map = new ol.Map({
layers: [base_layers,
overlay_layers],
target: 'map',
controls: ol.control.defaults({
attributionOptions: ({
collapsible: false
})
}),
view: new ol.View({
center: (new ol.geom.Point([5.52579, 52.28488])).transform('EPSG:4326', 'EPSG:3857').getCoordinates(),
zoom: 17,
minZoom: config.zoom_range[0],
maxZoom: config.zoom_range[1]
})
});
var layerSwitcher = new ol.control.LayerSwitcher();
map.addControl(layerSwitcher);
$.getJSON('vector_layers.json', addVectorLayers);
config.layers.forEach(function(layerName) {
var layer = new ol.layer.Tile({
title: layerName,
source: new ol.source.XYZ({
url: 'tiles/' + layerName + '/{z}/{x}/{y}.png'
}),
minZoom: config.zoom_range[0],
maxZoom: config.zoom_range[1]
});
overlay_layers.getLayers().push(layer);
});
}
function addVectorLayers(layer_data) {
$.each(layer_data, function(index, layer) {
var vectorSource = new ol.source.Vector({
url: 'vector/' + layer.source,
format: new ol.format.GeoJSON()
});
var vectorLayer = new ol.layer.Vector({
title: layer.name + " (vector)",
source: vectorSource,
// style: styleFunction,
updateWhileAnimating: !isMobile(),
updateWhileInteracting: !isMobile()
});
overlay_layers.getLayers().push(vectorLayer);
});
addPopupActions(map);
}
function addPopupActions(map) {
var container = document.getElementById('popup');
var content = document.getElementById('popup-content');
var closer = document.getElementById('popup-closer');
var overlay = new ol.Overlay(/** @type {olx.OverlayOptions} */ ({
element: container,
autoPan: true,
autoPanAnimation: {
duration: 250
}
}));
map.addOverlay(overlay);
closer.onclick = function() {
overlay.setPosition(undefined);
closer.blur();
return false;
};
// Highlight element on hover:
var hoverAction = new ol.interaction.Select({condition: ol.events.condition.pointerMove});
map.addInteraction(hoverAction);
// Display popup on click
var clickAction = new ol.interaction.Select();
map.addInteraction(clickAction);
clickAction.on('select', function(e) {
if (e.selected.length > 0){
var coordinate = e.mapBrowserEvent.coordinate;
props = e.selected[0].getProperties();
var html = 'Layer: ' + props['layer'] + "<br>Handle: 0x" + props['entityhandle'] + "<br>";
$.ajax(wikiDataUrl + props['entityhandle'], {
dataType: "json",
success: function(data) {
if(Object.keys(data.query.results).length == 0) {
html += "<p>This object is not yet defined in the wiki. If there is an page on the <a href='" + wikiUrl + "' target='_new'>wiki</a> representing this object, add the following snippet to that page:</p>";
html += "<pre>{{MapObject\n|Name = OBJECT NAME\n|Handle = 0x" + props['entityhandle'] + "\n|Summary = SUMMARY OF THIS OBJECT THAT IS SHOWN HERE.\n}}</pre>";
} else {
html = "";
$.each(data.query.results, function(index, item) {
if('printouts' in item) {
html += "<a href='" + item.fullurl + "' target='_new'>" + item.fulltext + "</a><br>";
html += item.printouts.Summary[0].fulltext + "<br>";
}
});
}
content.innerHTML = html;
overlay.setPosition(coordinate);
},
error: function() {
content.innerHTML = html + "<p>Wiki-data is currently unavailable</p>";
overlay.setPosition(coordinate);
}
});
}
clickAction.getFeatures().clear()
});
}
</script>
</body>
</html>