-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdev.js
145 lines (128 loc) · 3.9 KB
/
dev.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
import View from 'ol/View';
import Map from 'ol/Map';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import Feature from 'ol/Feature';
import LineString from 'ol/geom/LineString';
import Modify from 'ol/interaction/Modify';
import {
MaplibreLayer,
RealtimeLayer,
RoutingControl,
routingStyle,
} from './build/ol';
import 'ol/ol.css';
window.apiKey = '5cc87b12d7c5370001c1d65534da34dc9d4648aab190503c2e5ee81d';
const map = new Map({
target: 'map',
view: new View({
center: [950690.34, 6003962.67],
zoom: 15,
}),
});
const baseLayer = new MaplibreLayer({
apiKey: window.apiKey,
});
map.addLayer(baseLayer);
const realtimeLayer = new RealtimeLayer({
apiKey: window.apiKey,
});
map.addLayer(realtimeLayer);
const routingLayer = new VectorLayer({
source: new VectorSource(),
style: routingStyle,
});
// map.addLayer(routingLayer);
// const control = new RoutingControl({
// element: document.createElement('div'),
// apiKey: window.apiKey,
// routingLayer: routingLayer,
// });
// map.addControl(control);
const vectorLayer = new VectorLayer({
source: new VectorSource(),
});
vectorLayer.getSource().addFeature(
new Feature({
geometry: new LineString([
// [950476.4055933182, 6003322.253698345],
// [950389.0813034325, 6003656.659274571],
// [
[950478.7985399539, 6003320.7265438335],
[950483.7500754321, 6003337.644331005],
[950518.7823191849, 6003431.357665203],
[950420.9547506756, 6003448.256090432],
[950349.999707244, 6003582.770702608],
[950351.0015826611, 6003608.825650063],
[950361.1427882726, 6003611.801014977],
[950368.5900622065, 6003616.61749184],
[950379.0986221373, 6003626.80936295],
[950388.2936120768, 6003641.22594949],
[950393.3361623707, 6003652.514778154],
// ]
]),
}),
);
map.addLayer(vectorLayer);
const modify = new Modify({
source: vectorLayer.getSource(),
hitDetection: vectorLayer,
});
map.addInteraction(modify);
// control.addViaPoint([950476.4055933182, 6003322.253698345]);
// control.addViaPoint([950389.0813034325, 6003656.659274571]);
// control.addViaPoint('29563461696e881d');
// Add example button to toggle the RoutingControl.
// document.getElementById('control-button').addEventListener('click', (e) => {
// e.target.innerHTML = control.active
// ? 'Activate RoutingControl'
// : 'Deactivate RoutingControl';
// if (control.active) {
// control.active = false;
// } else {
// control.active = true;
// }
// });
// // Add example button to toggle the RoutingControl mot.
// document.getElementById('mot-button').addEventListener('click', (e) => {
// e.target.innerHTML =
// control.mot === 'bus' ? 'Switch to bus routing' : 'Switch to foot routing';
// control.mot = control.mot === 'bus' ? 'foot' : 'bus';
// });
// // Add example button to toggle the RoutingControl mot.
// document.getElementById('reset-button').addEventListener('click', () => {
// control.reset();
// });
map.on('pointermove', (e) => {
const feature = map.getFeaturesAtPixel(e.pixel)[0];
realtimeLayer.highlight(feature);
});
map.on('singleclick', (e) => {
const feature = map.getFeaturesAtPixel(e.pixel)[0];
realtimeLayer.select(feature);
console.log(feature);
});
let map2 = new Map({
pixelRatio: 3,
target: 'map2',
view: new View({
center: map.getView().getCenter(),
zoom: map.getView().getZoom(),
}),
});
document.getElementById('map2ToMap').onclick = () => {
const layers = [...map2.getLayers().getArray()];
map2.getLayers().clear();
map.setLayers(layers);
map.addEventListener('rendercomplete', (e) => {
console.log('map rendercomplete');
});
};
document.getElementById('mapToMap2').onclick = () => {
const layers = [...map.getLayers().getArray()];
map.getLayers().clear();
map2.setLayers(layers);
map2.addEventListener('rendercomplete', (e) => {
console.log('map2 rendercomplete');
});
};