-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvector_overlay_areas.js
More file actions
260 lines (204 loc) · 6.62 KB
/
Copy pathvector_overlay_areas.js
File metadata and controls
260 lines (204 loc) · 6.62 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
// necessary for use of Bing layers - generate your own at: https://msdn.microsoft.com/en-us/library/ff428642.aspx
var BingapiKey = "AgS4SIQqnI-GRV-wKAQLwnRJVcCXvDKiOzf9I1QpUQfFcnuV82wf1Aw6uw5GJPRz";
// a generic attribution variable for NLS historic map tilesets
var NLS_attribution = new ol.Attribution({html: 'Historic Map Layer courtesy of the <a href="http://maps.nls.uk/">National Library of Scotland</a>'});
// the Web Tile Map Service layers from NLS - view full list at: http://maps.nls.uk/geo/explore/scripts/explore.js
var edin1804 = new ol.layer.Tile({
title: "Ainslie, 1804",
visible: false,
source: new ol.source.XYZ({
attributions: [NLS_attribution],
url: "http://geo.nls.uk/urbhist/74400072/{z}/{x}/{-y}.png",
minZoom: 8,
maxZoom: 18
})
});
var edin1817 = new ol.layer.Tile({
title: "Kirkwood, 1817",
visible: false,
source: new ol.source.XYZ({
attributions: [NLS_attribution],
url: "http://geo.nls.uk/urbhist/74400073-4/{z}/{x}/{-y}.png",
minZoom: 8,
maxZoom: 18
})
});
var edin1890s = new ol.layer.Tile({
title: "Ordnance Survey, 1890s",
visible: false,
source: new ol.source.XYZ({
attributions: [NLS_attribution],
url: "http://geo.nls.uk/maps/towns/edinburgh1893/{z}/{x}/{-y}.png",
minZoom: 8,
maxZoom: 20
})
});
var OS1920s = new ol.layer.Tile({
title: 'Ordnance Survey 1920s',
visible: false,
source: new ol.source.XYZ({
attributions: [NLS_attribution],
url: 'http://geo.nls.uk/maps/api/nls/{z}/{x}/{y}.jpg',
maxZoom: 15
})
});
// OpenStreetMap
var osm = new ol.layer.Tile({
title: 'OpenStreetMap',
visible: false,
source: new ol.source.OSM({
attributions: [new ol.Attribution({html:'© <a href="http://www.openstreetmap.org/">OpenStreetMap</a> contributors'})],
url: 'http://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'
})
});
// Bing layers
var BingSatellite = new ol.layer.Tile({
title: 'Bing Satellite',
visible: false,
source: new ol.source.BingMaps({
key: BingapiKey,
imagerySet: 'Aerial'
})
});
var BingRoad = new ol.layer.Tile({
title: 'Bing Road',
visible: false,
source: new ol.source.BingMaps({
key: BingapiKey,
imagerySet: 'Road'
})
});
var BingAerialWithLabels = new ol.layer.Tile({
title: 'Bing Hybrid',
visible: false,
source: new ol.source.BingMaps({
key: BingapiKey,
imagerySet: 'AerialWithLabels'
})
});
// an array of the base layers listed above
var baseLayers = [edin1804, edin1817, edin1890s, OS1920s, BingRoad, BingSatellite, osm ];
// makes the Edinburgh 1817 layer visible
edin1817.setVisible(true);
// sets up the base layers as a set of radio buttons
var baselayerSelect = document.getElementById('baselayerSelect');
for (var x = 0; x < baseLayers.length; x++) {
var checked = (baseLayers[x].getVisible()) ? "checked" : "";
baselayerSelect.innerHTML += '<p><input type="radio" name="base" id="baseRadio'+ baseLayers[x].get('title') +
'" value="' + x + '" onClick="switchbaseLayer(this.value)" ' + checked + '><span>' + baseLayers[x].get('title') + '</span></p>';
}
// the style for the 1804 landownership vector overlay
var style = new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 0, 0, 0.1)'
}),
stroke: new ol.style.Stroke({
color: '#c41959',
width: 1
}),
text: new ol.style.Text({
font: '16px helvetica,sans-serif',
fill: new ol.style.Fill({
color: '#000'
}),
stroke: new ol.style.Stroke({
color: '#000099',
width: 1
})
})
});
var styles = [style];
// the layer definition for the 1804 landownership vector overlay
var vector_ownership_1804 = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'http://geo.nls.uk/maps/dev/digitalideas/ainslie_1804.js',
format: new ol.format.GeoJSON()
}),
style: function(feature, resolution) {
style.getText().setText(resolution < 1 ? feature.get('PROPERTY') : '');
return styles;
}
});
// the main ol map class
var map = new ol.Map({
target: 'map',
renderer: 'canvas',
controls: ol.control.defaults().extend([ new ol.control.ScaleLine({ units:'metric' }) ]),
layers: [edin1817, vector_ownership_1804],
logo: false,
view: new ol.View({
center: ol.proj.transform([-3.188, 55.961], 'EPSG:4326', 'EPSG:3857'),
zoom: 13
})
});
// the featureOverlay for the selected vector features
var highlightStyleCache = {};
var featureOverlay = new ol.FeatureOverlay({
map: map,
style: function(feature, resolution) {
var text = resolution < 10 ? feature.get('PROPERTY') : '';
if (!highlightStyleCache[text]) {
highlightStyleCache[text] = [new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#000099',
width: 3
}),
fill: new ol.style.Fill({
color: 'rgba(255,0,0,0.1)'
}),
text: new ol.style.Text({
font: '16px helvetica,sans-serif',
text: text,
fill: new ol.style.Fill({
color: '#000099'
}),
stroke: new ol.style.Stroke({
color: '#000099',
width: 0.1
})
})
})];
}
return highlightStyleCache[text];
}
});
var highlight;
var displayFeatureInfo = function(pixel) {
var feature = map.forEachFeatureAtPixel(pixel, function(feature, layer) {
return feature;
});
var info = document.getElementById('info');
if (feature) {
info.innerHTML = feature.get('PROPERTY');
} else {
info.innerHTML = ' ';
}
if (feature !== highlight) {
if (highlight) {
featureOverlay.removeFeature(highlight);
}
if (feature) {
featureOverlay.addFeature(feature);
}
highlight = feature;
}
};
map.on('pointermove', function(evt) {
if (evt.dragging) {
return;
}
var pixel = map.getEventPixel(evt.originalEvent);
displayFeatureInfo(pixel);
});
// var scaleline = new ol.control.ScaleLine();
// map.addControl(scaleline);
var zoomslider = new ol.control.ZoomSlider();
map.addControl(zoomslider);
// function to change the baseLayer
function switchbaseLayer(index) {
map.getLayers().getArray()[0].setVisible(false);
map.getLayers().removeAt(0);
map.getLayers().insertAt(0,baseLayers[index]);
baselayerSelected = baseLayers[index];
baselayerSelected.setVisible(true);
}