-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
456 lines (422 loc) · 11.4 KB
/
index.js
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
import 'ol/ol.css';
import Map from 'ol/Map';
import ImageLayer from 'ol/layer/Image';
import Static from 'ol/source/ImageStatic';
import Projection from 'ol/proj/Projection'
import Feature from 'ol/Feature';
import { LineString, Point, Polygon } from 'ol/geom';
import View from 'ol/View';
import {defaults as defaultControls, ScaleLine} from 'ol/control';
import TileLayer from 'ol/layer/Tile';
import { OSM, TileDebug } from 'ol/source';
import TileXYZ from 'ol/source/XYZ';
import { transform } from 'ol/proj.js';
import proj4 from 'proj4';
import {register} from 'ol/proj/proj4';
import sync from 'ol-hashed';
import GeoJSON from 'ol/format/GeoJSON';
import DragAndDrop from 'ol/interaction/DragAndDrop';
import Modify from 'ol/interaction/Modify';
import Draw from 'ol/interaction/Draw';
import Snap from 'ol/interaction/Snap';
import Event from 'ol/events/Event';
//import UndoRedo from './UndoRedo.js';
import { Vector as VectorLayer } from 'ol/layer';
import { TileJSON, Vector as VectorSource } from 'ol/source';
import { Circle, Text, Fill, Icon, Stroke, Style } from 'ol/style';
var Bdates = [
'22.05.2020',
'11.06.2020',
'12.06.2020',
];
var dates = [
'2019_03',
'2019_05',
'2020_03',
'2020_04',
'2020_05',
'2020_06',
'2020_09',
'2024_07',
];
var renderGridCheckbox = document.getElementById('render-grid');
var renderGridRotCheckbox = document.getElementById('render-grid-rot');
var renderDebugCheckbox = document.getElementById('render-debug');
var renderStudyAreasCheckbox = document.getElementById('render-study');
var editStudyAreasCheckbox = document.getElementById('edit-study');
//proj4.defs('EPSG:25832','+proj=utm +zone=32 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
proj4.defs('projLayer1','+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs');
register(proj4);
var scaleType = 'scalebar';
var scaleBarSteps = 4;
var scaleBarText = true;
var control;
const vSource = new VectorSource({
format: new GeoJSON(),
url: 'https://wasserbueffel.hlrs.de/studyareas.json'
});
//undoRedo = new UndoRedo(vSource);
var image = new Circle({
radius: 5,
fill: null,
stroke: new Stroke({color: 'red', width: 1})
});
var styles = {
'Point': new Style({
image: image
}),
'LineString': new Style({
stroke: new Stroke({
color: 'green',
width: 1
})
}),
'MultiLineString': new Style({
stroke: new Stroke({
color: 'green',
width: 1
})
}),
'MultiPoint': new Style({
image: image
}),
'MultiPolygon': new Style({
stroke: new Stroke({
color: 'yellow',
width: 1
}),
fill: new Fill({
color: 'rgba(255, 255, 0, 0.1)'
})
}),
'Polygon': new Style({
stroke: new Stroke({
color: 'blue',
lineDash: [4],
width: 3
}),
fill: new Fill({
color: 'rgba(0, 0, 255, 0.1)'
})
}),
'GeometryCollection': new Style({
stroke: new Stroke({
color: 'magenta',
width: 2
}),
fill: new Fill({
color: 'magenta'
}),
image: new Circle({
radius: 10,
fill: null,
stroke: new Stroke({
color: 'magenta'
})
})
}),
'Circle': new Style({
stroke: new Stroke({
color: 'red',
width: 2
}),
fill: new Fill({
color: 'rgba(255,0,0,0.2)'
})
})
};
var styleFunction = function(feature) {
var text = new Style({
text :new Text({
text: feature.getProperties().name,
font: '12px Calibri,sans-serif',
weight:'Bold',
fill: new Fill({ color: '#000' }),
stroke: new Stroke({
color: '#D3D3D3', width: 2
}),
offsetX: 0,
offsetY: 0,
rotation: 0
})
});
return [styles[feature.getGeometry().getType()],text];
};
const vLayer = new VectorLayer({
source: vSource,
style: styleFunction
/* style: new Style({
stroke: new Stroke({
width: 2,
color: 'white'
}),
fill: new Fill({
color: [255,255,255,0]
})
A})*/
});
function scaleControl() {
if (scaleType === 'scaleline') {
control = new ScaleLine({
units: "metric"
});
return control;
}
control = new ScaleLine({
units:"metric",
bar: true,
steps: scaleBarSteps,
text: scaleBarText,
minWidth: 140
});
return control;
}
var layers = [];
var flightLayers = [];
var Blayers = [];
var gridLines = [];
var gridRotLines = [];
var i, ii;
layers.push(
new TileLayer({
source: new OSM(),
visible: true,
})
)
layers.push(
new TileLayer({
source: new TileDebug(),
visible: false,
})
)
var origin = [9.285, 48.984];
var angle = 0.3;
var pos = transform(origin, 'EPSG:4326', 'EPSG:3857');
for (i = 0; i < (2000/15.6); i++) {
gridLines.push(
new Feature(
new LineString([pos, [pos[0]+800,pos[1]]])
)
);
pos[1] += 15.6;
}
var pos = transform(origin, 'EPSG:4326', 'EPSG:3857');
for (i = 0; i < (800/15.6); i++) {
gridLines.push(
new Feature(
new LineString([pos, [pos[0],pos[1]+2000]])
)
);
pos[0] += 15.6;
}
origin = [9.288, 48.983];
var pos = transform(origin, 'EPSG:4326', 'EPSG:3857');
var posRot = transform(origin, 'EPSG:4326', 'EPSG:3857');
for (i = 0; i < (2000/15.6); i++) {
var p1=[];
var p2=[];
p1[0] = ((pos[0] - posRot[0])*Math.cos(angle))-(pos[1] - posRot[1])*Math.sin(angle)+posRot[0];
p1[1] = ((pos[0] - posRot[0])*Math.sin(angle))+(pos[1] - posRot[1])*Math.cos(angle)+posRot[1];
p2[0] = ((pos[0]+800 - posRot[0])*Math.cos(angle))-(pos[1] - posRot[1])*Math.sin(angle)+posRot[0];
p2[1] = ((pos[0]+800 - posRot[0])*Math.sin(angle))+(pos[1] - posRot[1])*Math.cos(angle)+posRot[1];
gridRotLines.push(
new Feature(
new LineString([p1, p2])
)
);
pos[1] += 15.6;
}
pos = transform(origin, 'EPSG:4326', 'EPSG:3857');
for (i = 0; i < (800/15.6); i++) {
var p1=[];
var p2=[];
p1[0] = ((pos[0] - posRot[0])*Math.cos(angle))-(pos[1] - posRot[1])*Math.sin(angle)+posRot[0];
p1[1] = ((pos[0] - posRot[0])*Math.sin(angle))+(pos[1] - posRot[1])*Math.cos(angle)+posRot[1];
p2[0] = ((pos[0] - posRot[0])*Math.cos(angle))-(pos[1]+2000 - posRot[1])*Math.sin(angle)+posRot[0];
p2[1] = ((pos[0] - posRot[0])*Math.sin(angle))+(pos[1]+2000 - posRot[1])*Math.cos(angle)+posRot[1];
gridRotLines.push(
new Feature(
new LineString([p1, p2])
)
);
pos[0] += 15.6;
}
for (i = 0, ii = dates.length; i < ii; ++i) {
var fl= new TileLayer({
source: new TileXYZ({
url: 'https://wasserbueffel.hlrs.de/' + dates[i] + '/code/odm_orthophoto/odm_orthophoto/{z}/{x}/{-y}.png',
type: 'png',
//projection: 'projLayer1'
}),
visible: false,
preload: Infinity,
});
layers.push(fl);
flightLayers.push(fl);
}
pos = transform(origin, 'EPSG:4326', 'EPSG:3857');
pos[0] += -263;
pos[1] += -703;
var extent = [pos[0]+0, pos[1]+0, pos[0]+3000, pos[1]+3000];
//var extent = [0, 0, 512, 512];
var projection = new Projection({
code: 'static-image',
units: 'pixels',
extent: extent
});
for (i = 0, ii = Bdates.length; i < ii; ++i) {
Blayers.push(new ImageLayer({
source: new Static({
url: 'https://wasserbueffel.hlrs.de/fauna/WBAvifauna_'+Bdates[i]+'NoBG.svg',
projection: 'EPSG:3857',
imageExtent: extent
})
})
);
}
var gridLayer =
new VectorLayer({
visible: false,
source: new VectorSource({
projection: 'EPSG:3857',
features: gridLines
}),
style: new Style({
stroke: new Stroke({
width: 1,
color: [5, 5, 5, 1]
})
})
});
var gridRotLayer =
new VectorLayer({
visible: false,
source: new VectorSource({
projection: 'EPSG:3857',
features: gridRotLines
}),
style: new Style({
stroke: new Stroke({
width: 1,
color: [5, 5, 5, 1]
})
})
});
layers.push(gridLayer);
layers.push(gridRotLayer);
layers.push(vLayer);
for (i = 0, ii = Bdates.length; i < ii; ++i) {
layers.push(Blayers[i]);
Blayers[i].setVisible(false);
}
Blayers[0].setVisible(true);
var map = new Map({
controls: defaultControls().extend([
scaleControl()
]),
layers: layers,
target: 'map',
view: new View({
center: transform([9.288, 48.9905], 'EPSG:4326', 'EPSG:3857'),
zoom: 16,
maxZoom: 23
})
});
sync(map);
map.addInteraction(new DragAndDrop({
source: vSource,
formatConstructors: [GeoJSON]
}));
var modifyInteraction = new Modify({
source: vSource
});
var drawInteraction = new Draw({
type: 'Polygon',
source: vSource
});
var snapInteraction = new Snap({
source: vSource
});
/**
* * Handle checkbox change event.
* */
renderGridCheckbox.onchange = function () {
gridLayer.setVisible(renderGridCheckbox.checked);
};
renderGridRotCheckbox.onchange = function () {
gridRotLayer.setVisible(renderGridRotCheckbox.checked);
};
renderDebugCheckbox.onchange = function () {
layers[1].setVisible(renderDebugCheckbox.checked);
};
renderStudyAreasCheckbox.onchange = function () {
vLayer.setVisible(renderStudyAreasCheckbox.checked);
};
editStudyAreasCheckbox.onchange = function () {
if(editStudyAreasCheckbox.checked)
{
vLayer.setVisible(true);
renderStudyAreasCheckbox.checked=true;
map.addInteraction(modifyInteraction);
map.addInteraction(drawInteraction);
map.addInteraction(snapInteraction);
}
else{
map.removeInteraction(modifyInteraction);
map.removeInteraction(drawInteraction);
map.removeInteraction(snapInteraction);
}
};
document.addEventListener('keydown',function(evt) {
var handled = false;
switch (evt.keyCode) {
case 90: // z
if (evt.metaKey || evt.ctrlKey) {
drawInteraction.removeLastPoint();
handled = true;
}
break;
case 89: // y
if (evt.metaKey || evt.ctrlKey) {
//drawInteraction.redo();
handled = true;
}
break;
case 27: // esc
drawInteraction.abortDrawing();
handled = true;
break;
}
});
const clear = document.getElementById('clear');
clear.addEventListener('click', function() {
vSource.clear();
});
const format = new GeoJSON({featureProjection: 'EPSG:3857'});
const download = document.getElementById('download');
vSource.on('change', function() {
const features = vSource.getFeatures();
const json = format.writeFeatures(features);
download.href = 'data:text/json;charset=utf-8,' + json;
});
var select = document.getElementById('imageDate');
function onChange() {
var date = select.value;
console.log(date);
for (var i = 0, ii = dates.length ; i < ii; ++i) {
flightLayers[i].setVisible(dates[i] === date);
console.log(dates[i] === date);
console.log(dates[i]);
}
}
select.addEventListener('change', onChange);
onChange();
var birdSelect = document.getElementById('birdsDate');
function BonChange() {
var date = birdSelect.value;
for (var i = 0, ii = Blayers.length; i < ii; ++i) {
Blayers[i].setVisible(Bdates[i] === date);
}
}
birdSelect.addEventListener('change', BonChange);
BonChange();