-
Notifications
You must be signed in to change notification settings - Fork 65
/
index.html
215 lines (192 loc) · 5.78 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
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
<html>
<head>
<title>OpenLayers Editor</title>
<link rel="stylesheet" type="text/css" href="style/ole.css" />
<link rel="stylesheet" type="text/css" href="style/style.css" />
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/ol.css"
/>
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/maplibre-gl.css"
/>
<meta charset="utf-8" />
</head>
<body>
<script src="https://unpkg.com/[email protected]/dist/ol.js"></script>
<script src="https://unpkg.com/[email protected]/dist/maplibre-gl.js"></script>
<script src="https://unpkg.com/[email protected]/dist/jsts.min.js"></script>
<script src="index.js"></script>
<div id="app">
<div id="header">
<nav>
<div id="brand">OpenLayers Editor</div>
<div id="links">
<a href="#" class="active">Demo</a>
<a href="api.html">API</a>
<a
target="_blank"
href="https://github.com/geops/openlayers-editor"
>
Code
</a>
</div>
</nav>
</div>
<div id="map"></div>
<div id="promo">
<a href="https://geops.com/en/career" target="_blank">
<div id="promo-text">Join the team!</div>
</a>
</div>
<div id="copyright">
<a href="https://www.sbb.ch/" target="_blank">© SBB/CFF/FFS</a>|
<a href="https://www.geops.ch/" target="_blank">© geOps Tiles</a>|
<a href="https://www.openstreetmap.org/about/" target="_blank">
© OpenStreetMap Contributors
</a>
|
<a href="https://www.openmaptiles.org/" target="_blank">
© OpenMapTiles
</a>
|
<a
href="https://geops.com/en/imprint"
target="_blank"
rel="noopener noreferrer"
>
Imprint
</a>
|
<a
href="https://geops.com/en/privacy"
target="_blank"
rel="noopener noreferrer"
>
Privacy
</a>
|
<a
href="https://geops.com/en"
target="_blank"
rel="noopener noreferrer"
>
About geOps
</a>
</div>
</div>
<script type="text/javascript">
var editLayer = new ol.layer.Vector({
source: new ol.source.Vector({
wrapX: false,
}),
});
// Code taken from https://openlayers.org/en/latest/examples/mapbox-layer.html
var mbMap = new maplibregl.Map({
container: 'map',
center: ol.proj.toLonLat([873708.375917, 6105425.847789]),
attributionControl: false,
interactive: false,
});
// Get the public api key
fetch('https://backend.developer.geops.io/publickey')
.then((response) => response.json())
.then(function (data = {}) {
mbMap.setStyle(
'https://maps.geops.io/styles/travic_v2/style.json?key=' + data.key,
);
});
// Code taken from https://openlayers.org/en/latest/examples/mapbox-layer.html
var mbLayer = new ol.layer.Layer({
render: function (frameState) {
if (!mbMap) {
return null;
}
var canvas = mbMap.getCanvas();
var viewState = frameState.viewState;
var visible = mbLayer.getVisible();
canvas.style.position = 'absolute';
canvas.style.display = visible ? 'block' : 'none';
var opacity = mbLayer.getOpacity();
canvas.style.opacity = opacity;
// adjust view parameters in mapbox
var rotation = viewState.rotation;
mbMap.jumpTo({
center: ol.proj.toLonLat(viewState.center),
zoom: viewState.zoom - 1,
bearing: (-rotation * 180) / Math.PI,
animate: false,
});
if (!(
canvas.width === Math.floor(frameState.size[0] * frameState.pixelRatio) &&
canvas.height === Math.floor(frameState.size[1] * frameState.pixelRatio)
)) {
mbMap.resize();
}
mbMap.redraw();
return mbMap.getCanvas();
},
});
var map = new ol.Map({
layers: [mbLayer, editLayer],
target: 'map',
view: new ol.View({
center: [873708.375917, 6105425.847789],
zoom: 15,
}),
keyboardEventTarget: document,
});
var editor = new ole.Editor(map);
var cad = new ole.control.CAD({
source: editLayer.getSource(),
});
var draw = new ole.control.Draw({
source: editLayer.getSource(),
});
var drawLine = new ole.control.Draw({
type: 'LineString',
source: editLayer.getSource(),
});
var rotate = new ole.control.Rotate({
source: editLayer.getSource(),
});
var drawPoly = new ole.control.Draw({
type: 'Polygon',
source: editLayer.getSource(),
});
var modify = new ole.control.Modify({
source: editLayer.getSource(),
});
var buffer = new ole.control.Buffer({
source: editLayer.getSource(),
});
var union = new ole.control.Union({
source: editLayer.getSource(),
});
var intersection = new ole.control.Intersection({
source: editLayer.getSource(),
});
var difference = new ole.control.Difference({
source: editLayer.getSource(),
});
editor.addControls([
cad,
draw,
drawLine,
drawPoly,
modify,
rotate,
buffer,
union,
intersection,
difference,
]);
var ls = new ole.service.LocalStorage();
editor.addService(ls);
// For tests purpose
window.editor = editor;
window.editLayer = editLayer;
</script>
</body>
</html>