-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathgoogle-draw-line.html
113 lines (86 loc) · 2.49 KB
/
google-draw-line.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
<!DOCTYPE html>
<html>
<head>
<title>Leaflet</title>
<script type="text/javascript" src="../eon-map.js"></script>
<style type="text/css">
body {
padding: 0px;
margin: 0px;
}
</style>
</head>
<body>
<div style="width: 100%; height:500px" id="map"></div>
<div id='map'></div>
<script>
function getNonZeroRandomNumber(){
var random = Math.floor(Math.random()*199) - 99;
if(random==0) return getNonZeroRandomNumber();
return random;
}
</script>
<script>
var pubnub = new PubNub({
publishKey: 'demo',
subscribeKey: 'demo'
});
var channel = 'pubnub-mapbox' + getNonZeroRandomNumber();
var pointA = false;
var pointB = false;
var map = eon.map({
pubnub: pubnub,
id: 'map',
channels: [channel],
connect: connect,
options: {
center: new L.LatLng(37.370375, -97.75613851),
zoom: 5
},
provider: 'google',
googleKey: 'AIzaSyBYcy2l0Yf4lDADZ_U0zi6dy0M6pFZyPQA',
googleMutant: {
type: 'roadmap',
styles: [
{elementType: 'labels', stylers: [{visibility: 'off'}]},
{featureType: 'water', stylers: [{color: '#000000'}]}
]
},
message: function(message, timetoken, channel) {
console.log(message, timetoken, channel);
var currentPoint = new L.LatLng(message[0].latlng[0], message[0].latlng[1]);
if(pointA && pointB) {
var pointList = [pointA, pointB];
console.log(pointA)
var firstpolyline = new L.Polyline(pointList, {
color: 'red',
weight: 3,
opacity: 0.5,
smoothFactor: 1
});
console.log(map)
firstpolyline.addTo(map);
}
pointB = pointA;
pointA = currentPoint;
}
});
function connect() {
var point = {
latlng: [37.370375, -97.756138]
};
setInterval(function(){
var new_point = JSON.parse(JSON.stringify(point));
new_point.latlng = [
new_point.latlng[0] + (getNonZeroRandomNumber() * 0.05),
new_point.latlng[1] + (getNonZeroRandomNumber() * 0.1)
];
pubnub.publish({
channel: channel,
message: [new_point]
});
}, 1000);
};
</script>
</body>
</html>