-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
83 lines (76 loc) · 2.46 KB
/
index.js
File metadata and controls
83 lines (76 loc) · 2.46 KB
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
var GreatCircle = require('great-circle')
var LATLNG = require('./latlng')
var map = L.map('map')
var nav = L.multiPolyline
if(location.hash) {
[lat, long, zoom] = location.hash.substring(1).split(',')
// console.log([lat, long, zoom])
var ll = LATLNG.parse(lat+', '+long)
map.setView(ll, (+zoom)||13);
}
else
map.setView([-41.25, 173.25], 13);
//var map = L.map('map').setView([51.505, -0.09], 13);
// L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
// L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
// L.tileLayer('https://tiles.wetmaps.co.nz/file/wetmaps-tiles/sync/tiles/{z}/{x}/{y}.png', {
L.tileLayer('http://localhost:8080/https/tiles.wetmaps.co.nz/file/wetmaps-tiles/sync/tiles/{z}/{x}/{y}.png', {
// L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
var mouse
function append (type, latlng, string) {
var log = document.querySelector('#log')
log.value += '\n' + [type, LATLNG.stringify(latlng), string].join('; ') + '\n'
}
map.on('click', function (ev) {
console.log('click', ev)
append('nav', ev.latlng, new Date())
pl.addLatLng(ev.latlng)
var X = new L.icon({
iconUrl: 'images/x.svg',
iconSize: [10, 10],
iconAnchor: [5, 5]
})
var marker = new L.Marker(ev.latlng, {
draggable: true,
icon: X
});
marker.bindPopup(''+new Date()).openPopup();
marker.addTo(map)
})
map.on('mousemove', function (ev) {
mouse = ev
document.querySelector('#location').textContent = LATLNG.stringify(ev.latlng)
})
map.on('move', function (e) {
var center = map.getCenter()
console.log('MOVE', center, LATLNG.stringify(center), LATLNG.parse(LATLNG.stringify(center))
)
window.location.hash = '#' + LATLNG.stringify(center) + ','+map.getZoom()
})
MAP=map
var log = document.querySelector('#log').value
log = log.split('\n').map(e => e.trim()).filter(Boolean).map(line => {
var [type, ll, message] = line.split(';')
return {type, latlng: LATLNG.parse(ll), message}
})
var navs = []
log.forEach(v => {
if('nav' === v.type)
navs.push(v.latlng)
})
console.log('navs', navs, log)
var pl = L.polyline(navs, {color:'red'});
PL = pl
function length (line) {
var sum = 0
for(var i = 1; i < line.length; i++) {
var a = line[i-1], b = line[i]
sum += GreatCircle.distance(a.lat, a.lng, b.lat, b.lng, 'NM')
}
return sum
}
pl.addTo(map)
console.log("LENGTH", length(navs))