-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
63 lines (63 loc) · 1.74 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
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.2.1/css/ol.css" type="text/css">
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.2.1/build/ol.js"></script>
<style>
html, body {
height: 100%;
}
#map {
width: 100%;
height: 75%;
}
#log {
width: 100%;
height: 25%;
}
</style>
</head>
<body>
<div id="map" class="map"></div>
<textarea id="log">v1.1</textarea>
<script type="module">
String.prototype.rightPad = function(padString, length) {
var str = this;
while (str.length < length)
str = str + padString;
return str;
}
String.prototype.leftPad = function(padString, length) {
var str = this;
while (str.length < length)
str = padString + str;
return str;
}
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2
}),
moveTolerance: 4
});
var log = document.getElementById('log');
['click', 'dblclick', 'movestart', 'moveend', 'pointerdrag', 'pointermove', 'singleclick'].forEach((eventType) => {
map.on(eventType, (event) => {
if (event.pixel) {
log.value = eventType.rightPad(' ', 15) + '(' + event.pixel[0].toString().leftPad(' ', 6) + ', ' + event.pixel[1].toString().leftPad(' ', 6) + ')' + '\n' + log.value;
}
else {
log.value = eventType.rightPad(' ', 15) + '\n' + log.value;
}
});
});
</script>
</body>
</html>