-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
80 lines (66 loc) · 1.99 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
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script>
$(function(){
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
var iosocket = io.connect('http://localhost:3000');
iosocket.on('connect', function () {
console.log('connected');
});
iosocket.on('message', function(msg) {
var strMessage = ab2str(msg);
console.log(strMessage);
parseCoordinates(strMessage);
});
function parseCoordinates(strMessage){
var json = JSON.parse('[' + strMessage + ']');
addMarker(json);
}
iosocket.on('disconnect', function() {
console.log('disconnected');
});
var map = L.map('map').setView([-35.5423308442, 176.574665847], 5);
var marker = L.marker([-35.5423308442, 176.574665847]).addTo(map);
var mapLayer = L.tileLayer('http://{s}.base.maps.api.here.com/maptile/2.1/maptile/newest/{scheme}/{z}/{x}/{y}/{size}/{format}?app_id={app_id}&app_code={app_code}', {
attribution: 'here',
subdomains: '1234',
type: 'maptile',
scheme: 'reduced.night',
app_id: 'XXXXX',
app_code: 'XXXXX',
mapID: 'newest',
maxZoom: 20,
format: 'png8',
size: '256'
}).addTo(map);
function addMarker(json){
var lon = json[0];
var lat = json[1];
var newLatLng = new L.LatLng(lon, lat);
marker.setLatLng(newLatLng);
}
});
</script>
<style>
html, body {
height: 100%;
width: 100%;
margin: 0;
}
#map {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="message">vdvd</div>
</body>
</html>