forked from arnolds/pineapple
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap.html
271 lines (222 loc) · 6.48 KB
/
map.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>DhammaCharts.org</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ol.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/ol.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300&display=swap" rel="stylesheet">
<style>
@font-face {
font-family: 'Poppins';
font-style: normal;
font-weight: 600;
src: local('Poppins SemiBold'), local('Poppins-SemiBold'), url(/assets/fonts/pxiByp8kv8JHgFVrLEj6Z11lFd2JQEl8qw.woff2) format('woff2');
unicode-range: U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200C-200D, U+20A8, U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB;
}
html,
body,
.map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.map {
width: 100%;
height: 100vh;
}
.ol-rotate {
top: 95px !important;
left: .5em !important;
right: auto;
}
.cross {
top: 0.5em;
right: 0.5em;
}
.help {
top: 65px;
left: .5em;
}
.modal {
display: none;
/* Hidden by default */
position: fixed;
/* Stay in place */
z-index: 1;
/* Sit on top */
padding-top: 100px;
/* Location of the box */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
background-color: rgb(0, 0, 0);
/* Fallback color */
background-color: rgba(0, 0, 0, 0.4);
/* Black w/ opacity */
font-family: Poppins;
}
/* Modal Content */
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
/* The Close Button */
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<div id="map" class="map"></div>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p> cmd/ctrl + drag = rotate (click on arrow to reset direction) </p>
<p> maj + drag = mini window zoom </p>
<p> wheel mouse = zoom </p>
</div>
</div>
<!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/elm-pep.js"></script>
<script>
const ImageLayer = ol.layer.Image;
const Map = ol.Map;
const Overlay = ol.Overlay;
const Projection = ol.proj.Projection;
const Static = ol.source.ImageStatic;
const View = ol.View;
const { getCenter } = ol.extent;
const { platformModifierKeyOnly } = ol.events.condition;
const { Stroke, Fill, Style, Circle } = ol.style;
const { DragRotate } = ol.interaction;
const { defaults } = ol.interaction.defaults;
const { Control } = ol.control;
const { defaultControls } = ol.control.defaults;
const Rotate = ol.control.Rotate;
const Zoom = ol.control.Zoom;
// url behaviour
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const mapUrl = urlParams.get('map-url')
const pageUrl = urlParams.get('page-url')
const zoomMax = urlParams.get('zoom-max')
const zoomMin = urlParams.get('zoom-min')
// cross button
const button = document.createElement('button');
button.innerHTML = '×';
const handle = function (e) {
// history.back();
window.open(pageUrl,"_self");
};
button.addEventListener('click', handle, false);
const element = document.createElement('div');
element.className = 'cross ol-unselectable ol-control';
element.appendChild(button);
const OneControl = new ol.control.Control({
element: element
});
// help button
const buttonHelp = document.createElement('button');
buttonHelp.innerHTML = '?';
const handleHelp = function (e) {
modal.style.display = "block"; // do anything ?
};
buttonHelp.addEventListener('click', handleHelp, false);
const elementHelp = document.createElement('div');
elementHelp.className = 'help ol-unselectable ol-control';
elementHelp.appendChild(buttonHelp);
const OneControlHelp = new ol.control.Control({
element: elementHelp
});
// map
const img = document.createElement('img');
img.onload = function () {
console.log("image loaded", img.width, img.height)
const extent = [0, 0, img.width, img.height];
const projection = new Projection({
code: 'xkcd-image',
units: 'pixels',
extent: extent,
});
const map = new Map({
layers: [
new ImageLayer({
source: new Static({
attributions: '',
url: img.src,
projection: projection,
imageExtent: extent,
}),
}),
],
target: 'map',
view: new View({
projection: projection,
center: getCenter(extent),
zoom: zoomMin ? zoomMin : 1.5,
maxZoom: zoomMax ? zoomMax : undefined,
}),
// use ctrl/cmd + drag for rotation //
interactions: defaults({ altShiftDragRotate: false }).extend([new DragRotate({ condition: platformModifierKeyOnly })]),
});
// buttons
map.addControl(OneControl);
map.addControl(OneControlHelp);
// cursor
map.getViewport().style.cursor = "-webkit-grab";
map.on('pointerdrag', function (evt) {
map.getViewport().style.cursor = "-webkit-grabbing";
});
map.on('pointerup', function (evt) {
map.getViewport().style.cursor = "-webkit-grab";
});
// Get the modal
const modal = document.getElementById("myModal");
// Get the button that opens the modal
const btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
const span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
document.getElementsByClassName("help")[0].onclick = function () {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function () {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
}
img.src = mapUrl;
</script>
</body>
</html>