-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal.js
More file actions
309 lines (262 loc) · 7.89 KB
/
local.js
File metadata and controls
309 lines (262 loc) · 7.89 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
var map;
var located = false;
function onLocationError(e) {
if(!located){
var map = L.map('map').setView([55.950, -3.203], 16);
located = true;
}
alert(e.message);
}
function resetMap(map){
document.getElementById('map').innerHTML = "";
if (typeof map === 'undefined')return;
try{
map.off();
map.remove();
map = undefined;
}catch(e){
console.log("Tried to remove a defined map, but failed: "+JSON.stringify(e));
}
}
// === Some cookie parameters ===
var cookiename = "mapinfo"; // name for this cookie
var expiredays = 7; // number of days before cookie expiry
function setCookie(){
if (typeof map === 'undefined')return;
var mapcenter = map.getCenter();
var cookietext = cookiename+"="+mapcenter.lat+"|"+mapcenter.lng+"|"+map.getZoom();
if (expiredays) {
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
cookietext += ";expires="+exdate.toGMTString();
}
// == write the cookie ==
document.cookie=cookietext;
}
function getParam(val) {
var paramData = location.hash.substr(1);
if(typeof paramData === 'undefined' || paramData === ''){
paramData = location.search.substr(1);
}
var params = paramData.split("&");
for(param of params){
var kv = param.split("=");
if(kv[0] === val) return kv[1];
}
}
function mapstartFromParams(){
var paramLat = getParam("lat");
if(typeof paramLat === 'undefined'){
return undefined;
}else{
// We're using the URL to override
paramLon = getParam("lon");
paramZoom = getParam("zoom");
return [paramLat,paramLon,paramZoom];
}
}
function mapstartFromCookie(){
if (document.cookie.length>0) {
cookieStart = document.cookie.indexOf(cookiename + "=");
if (cookieStart!=-1) {
cookieStart += cookiename.length+1;
cookieEnd=document.cookie.indexOf(";",cookieStart);
if (cookieEnd==-1) {
cookieEnd=document.cookie.length;
}
cookietext = document.cookie.substring(cookieStart,cookieEnd);
// == split the cookie text and create the variables ==
bits = cookietext.split("|");
lat = parseFloat(bits[0]);
lon = parseFloat(bits[1]);
zoom = parseInt(bits[2]);
return [lat, lon, zoom];
}
}
return null;
}
function initMaps(){
map = L.map('map');
var cookieStart = mapstartFromCookie();
var paramStart = mapstartFromParams();
try{
map.setView([paramStart[0], paramStart[1]], paramStart[2]);
console.log("Initialised map location from query parameters");
}catch(e){
console.log("Couldn't set map from params. Falling back to cookie");
try{
map.setView([cookieStart[0], cookieStart[1]], cookieStart[2]);
}catch(e){
console.log("Couldn't set map from cookie. Falling back to defaults");
map.setView([55.951,-3.200],15);
}
}
var osm = L.tileLayer('/osm/{z}/{x}/{y}.png', {
maxZoom: 17,
minZoom: 5,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ',
id: 'bear.mapnik'
});
var contours = L.tileLayer('/tiles/contours/{z}/{x}/{y}.png', {
maxZoom: 16,
minZoom: 8,
id: 'bear.contours',
opacity: 0.3
});
var osgb = L.tileLayer('/tiles/grid/{z}/{x}/{y}.png', {
maxZoom: 16,
minZoom: 12,
id: 'bear.osgb'
});
var dykes = L.tileLayer('/tiles/dykes/{z}/{x}/{y}.png', {
maxZoom: 16,
id: 'bear.dykes',
opacity: 0.5,
attribution: '| Geology layers: Based upon DiGMapGB-625, with the permission of the British Geological Survey'
});
var faults = L.tileLayer('/tiles/faults/{z}/{x}/{y}.png', {
maxZoom: 16,
id: 'bear.faults',
opacity: 0.5,
attribution: '| Geology layers: Based upon DiGMapGB-625, with the permission of the British Geological Survey'
});
var solid = L.tileLayer('/tiles/solid/{z}/{x}/{y}.png', {
maxZoom: 16,
id: 'bear.solid',
opacity: 1.0,
attribution: '| Geology layers: Based upon DiGMapGB-625, with the permission of the British Geological Survey'
});
var constituencies = L.tileLayer('/tiles/constituencies/{z}/{x}/{y}.png', {
maxZoom: 17,
id: 'bear.constituencies',
opacity: 1.0,
attribution: '| '
});
var ukconstituencies = L.tileLayer('/tiles/ukconstituencies/{z}/{x}/{y}.png', {
maxZoom: 17,
id: 'bear.ukconstituencies',
opacity: 1.0,
attribution: '| OS OpenData'
});
var councilwards = L.tileLayer('/tiles/council_wards/{z}/{x}/{y}.png', {
maxZoom: 17,
id: 'bear.councilwards',
opacity: 1.0,
attribution: '| OS OpenData'
});
var regions = L.tileLayer('/tiles/regions/{z}/{x}/{y}.png', {
maxZoom: 17,
id: 'bear.regions',
opacity: 1.0,
attribution: '| '
});
var newMarilynLayer = new L.MarkerClusterGroup({
iconCreateFunction: function(cluster) {
var n = '<b>' + cluster.getChildCount() + '</b>';
return new L.DivIcon({
html: n,
className: 'mycluster',
iconSize: L.point(40, 40)
});
}
});
for(i=0;i<marilynsArray.length;i++){
var m = L.marker([marilynsArray[i].lat, marilynsArray[i].lng]).bindPopup(marilynsArray[i].hill_name);
newMarilynLayer.addLayer(m);
}
L.control.search({
url: 'http://www.rasilon.net/find_postcode.php?q={s}',
textPlaceholder: 'Postcode...',
collapsed: false,
//markerIcon: new L.Icon({iconUrl:'data/custom-icon.png', iconSize: [20,20]}),
markerLocation: true
}).addTo(map);
osm.addTo(map);
//contours.addTo(map);
//osgb.addTo(map);
if(getParam("marilyns")){
newMarilynLayer.addTo(map);
}
if(getParam("solid")){
solid.addTo(map);
}
if(getParam("dykes")){
dykes.addTo(map);
}
if(getParam("faults")){
faults.addTo(map);
}
if(getParam("constituencies")){
constituencies.addTo(map);
}
if(getParam("ukconstituencies")){
ukconstituencies.addTo(map);
}
if(getParam("councilwards")){
councilwards.addTo(map);
}
var baseMaps = {
"Mapnik": osm
};
var overlayMaps = {
"Contours": contours,
"OS Grid": osgb,
"Solid": solid,
"Dykes": dykes,
"Faults": faults,
"Marilyn Markers": newMarilynLayer,
"Scottish Constituencies": constituencies,
"Scottish Regions": regions,
"UK Constituencies": ukconstituencies,
"UK Council Wards": councilwards
};
var layers = L.control.layers(baseMaps, overlayMaps);
layers.addTo(map);
map.addControl(new L.Control.Permalink({text: 'Permalink', layers: layers}));
var solidExplanationMarker = L.marker([0.0,0.0]).bindPopup("No popup content yet!");
map.on('click', function(e) {
if(map.hasLayer(solid)){
var popupData = "Not Implemented Yet.<br>At "+e.latlng.lng+" "+e.latlng.lat;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var r = JSON.parse(xmlhttp.responseText);
var groupName = decodeURI(r.lex_d);
var descr = decodeURI(r.rcs_d);
var minMY = decodeURI(r.min_my);
var maxMY = decodeURI(r.max_my);
var maxPeriod = decodeURI(r.max_period);
var minPeriod = decodeURI(r.min_period);
var popupData = "";
if(typeof groupName == "undefined" || groupName === ""){
popupData = "Unknown bedrock.";
}else{
popupData = "<table class=\"descrTable\">"+
"<tr><td>Name</td><td> "+groupName+"</td></tr>"+
"<tr><td>Description</td><td>"+descr+"</td></tr>"+
"<tr><td>Deposited between</td><td>"+
maxMY+
" million years ago ("+
maxPeriod+
"),<br>and<br>"+
minMY+
" million years ago ("+
minPeriod+
").</td></tr>\n</table>"
;
}
solidExplanationMarker
.setLatLng(e.latlng)
.addTo(map)
.setPopupContent(popupData)
.openPopup();
}
}
xmlhttp.open("GET", "http://www.rasilon.net/descr_for_location.cgi?lat="+e.latlng.lat+"&lng="+e.latlng.lng, true);
xmlhttp.send();
}else{
//alert("No solid");
}
});
}