-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
188 lines (163 loc) · 7.41 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
182
183
184
185
186
187
188
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>National Library of Scotland: Maps API</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/4.6.5/ol.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/openlayers/4.6.5/ol.css" type="text/css">
<script type="text/javascript" src="//nls.tileserver.com/api-cluster.js"></script>
<script type="text/javascript">
var map;
function permalink() {
var url = document.location.toString();
if (url.indexOf('?') != -1) { url = url.substring(0,url.indexOf('?'))};
var center = ol.proj.toLonLat(map.getView().getCenter());
document.location.href= url + "?lat=" + center[1] +"&lng="+ center[0] + "&zoom="+map.getView().getZoom();
}
function getURLParam( name ) {
var regex = new RegExp( "[\\?&]"+name+"=([^&#]*)" );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
var param_q = getURLParam("q");
var param_lat = getURLParam("lat");
var param_lng = getURLParam("lng");
var param_zoom = getURLParam("zoom");
var map;
function initialize() {
var map_zoom = 5;
var map_center = ol.proj.fromLonLat([-2.834473,54.699234]);
var gbbounds = ol.extent.applyTransform(
[-9.272461,49.795450,2.746582,60.898388],
ol.proj.getTransform('EPSG:4326', 'EPSG:3857')
);
var isAsync = false;
if (param_lat && param_lng) {
map_center = ol.proj.fromLonLat([parseFloat(param_lng), parseFloat(param_lat)]);
} else if (param_q == 'auto') {
isAsync = true;
var doGeoIp = function() {
function reqListener() {
var response = JSON.parse(this.responseText);
if (response.longitude && response.latitude) {
center = ol.proj.fromLonLat([response.longitude, response.latitude]);
if (ol.extent.containsCoordinate(gbbounds, center)) {
map_center = center;
map_zoom = 13;
initialize_map(map_zoom, map_center);
} else {
initialize_map(map_zoom, map_center);
}
} else {
initialize_map(map_zoom, map_center);
}
}
var oReq = new XMLHttpRequest();
oReq.addEventListener('load', reqListener);
oReq.open('GET', 'https://freegeoip.klokantech.com/json/');
oReq.send();
}
// W3C Geolocation provided by modern browsers
if (typeof(navigator.geolocation) != 'undefined') {
navigator.geolocation.getCurrentPosition(function(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var center = ol.proj.fromLonLat([lng, lat]);
if (ol.extent.containsCoordinate(gbbounds, center)) {
map_center = center;
map_zoom = 13;
initialize_map(map_zoom, map_center);
} else {
initialize_map(map_zoom, map_center);
}
}, function(err) {
doGeoIp();
});
} else {
doGeoIp();
};
} else if (param_q) {
isAsync = true;
var url = 'https://geocoder.tilehosting.com/gb/q/' + param_q + '.js?key=6mugkTijDnj5zw1Kh7Q5';
function reqListener() {
var response = JSON.parse(this.responseText);
if (response.results && response.results.length) {
var first = response.results[0];
if (param_zoom) map_zoom = parseInt(param_zoom);
map_center = ol.proj.fromLonLat([first.lon, first.lat]);
initialize_map( map_zoom, map_center, ol.extent.applyTransform(
first.boundingbox,
ol.proj.getTransform('EPSG:4326', 'EPSG:3857')
));
} else {
if (param_zoom) map_zoom = parseInt(param_zoom);
initialize_map(map_zoom, map_center);
}
}
var oReq = new XMLHttpRequest();
oReq.addEventListener('load', reqListener);
oReq.open('GET', url);
oReq.send();
}
if (param_zoom) map_zoom = parseInt(param_zoom);
// Initialize map only if we are not searching via GeoCoder
if (!isAsync) {
initialize_map(map_zoom, map_center);
}
// Disable right click context menu
document.getElementById('nlslogo')['oncontextmenu'] = function() { return false; };
document.getElementById('klokantechlogo')['oncontextmenu'] = function() { return false; };
// Disable selection
function disableSelection(target){
if (typeof target['onselectstart']!="undefined") //IE
target['onselectstart']=function(){return false}
else if (typeof target['style']['MozUserSelect']!="undefined") //Firefox
target['style']['MozUserSelect']="none"
else //All other route (ie: Opera)
target['onmousedown']=function(){return false}
target['style']['cursor'] = "default"
}
disableSelection(document.getElementById('nlslogo'));
disableSelection(document.getElementById('klokantechlogo'));
disableSelection(document.getElementById('nlsmaptext'));
}
function initialize_map(map_zoom, map_center, map_viewport) {
if (map_viewport) map_zoom = 13; // zoom in by default for initialization of Geocoder results
map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.XYZ({
minZoom: 1,
maxZoom: 14,
tileUrlFunction: function(tilecoord, pixelRatio, projection) {
return NLSTileUrlOS(tilecoord[1], - tilecoord[2] - 1, tilecoord[0]);
}
})
})
],
target: 'map_canvas',
controls: ol.control.defaults({attribution: false}),
view: new ol.View({
center: map_center,
zoom: map_zoom,
minResolution: 40075016.68557849 / 256 / Math.pow(2, 15)
})
});
if (map_viewport) {
map.getView().fit(map_viewport);
map.getView().setResolution(map.getView().constrainResolution(map.getView().getResolution()));
}
document.getElementById('loading').style.display = 'none';
}
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%;background:#cedfe4;"></div>
<a href="http://www.nls.uk/" target="_blank" id="nlslogo" style="-webkit-user-select:none; display:block;position:absolute;bottom:2px;left:2px;z-index:1000;"><img src="nls70-nq8.png" width="70" height="41" border="0" alt="National Library of Scotland" /></a>
<a href="http://www.klokantech.com/" target="_blank" id="klokantechlogo" style="-webkit-user-select: none; display:block;position:absolute;bottom:18px;right:2px;z-index:1000;background:rgba(255, 255, 255, 0.6); padding: 2px"><img src="klokantech70-nq8.png" width="70" height="11" border="0" alt="KlokanTech.com" /></a>
<div id="nlsmaptext" style=" -webkit-user-select: none; position: absolute; bottom: 0px; right:0px; color:black;font-family: Arial, sans-serif; font-size:11px; white-space: nowrap; text-align: right; padding:2px;">Historical maps from 1919-47 <a href="http://geo.nls.uk/maps/api/" target="_blank">NLS Maps API</a></div>
<div id="loading" style="position:absolute;top:50%;left:50%;width:200px;text-align:center;margin-left:-100px;">Loading...</div>
</body>
</html>