-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
156 lines (130 loc) · 4.93 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
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Follow the Hootsuite Bus!</title>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css">
<link rel="stylesheet" href="styles.css">
<!-- Load the library references for ArcGIS API for JavaScript -->
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3compact"></script>
<script type="text/javascript" src="https://api.geoloqi.com/js/geoloqi.min.js"></script>
<script>
dojo.require("esri.map");
dojo.require("esri.dijit.Popup");
var geoloqiToken = "58rMWnW"; // Hootsuite
var map;
var graphic;
function init() {
var options = {
basemap: "gray",
center: [-97.7441, 30.2724], // Austin, TX
zoom: 16,
infoWindow: new esri.dijit.Popup(null, dojo.create("div")) // Define a popup
};
// Create map
map = new esri.Map("mapDiv", options);
autoResize(map);
// Init the Geoloqi library with no authentication
geoloqi.init({});
geoloqi.auth = {access_token: "x"};
map.on('load', function(){
require(["dojo/request"], function(request){
request("/route.json").then(
function(text){
var data = JSON.parse(text);
var line = new esri.geometry.Polyline(data);
var symbol = new esri.symbol.SimpleLineSymbol('solid', new dojo.Color([20, 70, 122, 0.75]), 5);
var graphic = new esri.Graphic(line, symbol);
map.graphics.add(graphic);
},
function(error){
console.log("An error occurred: " + error);
}
);
});
// Get the last location from the Geoloqi API
geoloqi.get('share/last?geoloqi_token='+geoloqiToken, function(result, error) {
var symbol = new esri.symbol.PictureMarkerSymbol({
angle: 0,
xoffset: -16,
yoffset: 23,
type: "esriPMS",
url: "images/hootsuite-owl.png",
contentType: "image/png",
width: 62,
height: 54
})
var pt = pointFromGeoloqiResult(result);
var attributes = {
lat: rounded6(pt.y),
lng: rounded6(pt.x),
time: timeFormatted(result.date_ts)
};
infoTemplate = new esri.InfoTemplate("Current Location","Time: ${time}<br/>Latitude: ${lat}<br/>Longitude: ${lng}<br/><span class='popupZoom' onclick='zoomToPlace(" + pt.x + "," + pt.y + ",15)';>Zoom To</span>");
graphic = new esri.Graphic(pt, symbol, attributes, infoTemplate);
// Add the pin to the map
map.graphics.add(graphic);
// If the location of the tracker is outside the visible window, pan the map
recenterMapOnPoint(pt);
// Set a timeout to start polling location
setTimeout(updateCurrentLocation, 5000);
});
});
}
function updateCurrentLocation() {
geoloqi.get('share/last?geoloqi_token='+geoloqiToken, function(result, error) {
var pt = pointFromGeoloqiResult(result);
graphic.setGeometry(pt);
graphic.setAttributes({
lat: rounded6(pt.y),
lng: rounded6(pt.x),
time: timeFormatted(result.date_ts)
});
recenterMapOnPoint(pt);
setTimeout(updateCurrentLocation, 5000);
});
}
function recenterMapOnPoint(pt) {
if(!map.extent.contains(pt)) {
map.setExtent(map.extent.centerAt(esri.geometry.geographicToWebMercator(pt)));
}
}
// Rounds to 6 decimal places
function rounded6(num) {
return Math.round(num*1000000) / 1000000;
}
function timeFormatted(unixtimestamp) {
var date = new Date(unixtimestamp * 1000);
return date.getHours() + ":" + date.getMinutes();
}
// Return a new esri.geometry.Point given a location from Geoloqi
function pointFromGeoloqiResult(result) {
return new esri.geometry.Point([
result.location.position.longitude,
result.location.position.latitude],
new esri.SpatialReference({ wkid: 4326 })
);
}
function autoResize(map) {
dojo.connect(map, 'onLoad', function (map) {
dojo.connect(window, 'resize', map, map.resize);
});
dojo.connect(map, 'onResize', function(extent, width, height) {
map.__resizeCenter = map.extent.getCenter();
setTimeout(function() {
map.centerAt(map.__resizeCenter);
}, 200);
});
}
dojo.addOnLoad(init);
</script>
</head>
<body>
<div class="panel">
<div class="titlearea"><span id="titleMessage" class="title-message">Follow the Hootsuite Bus!</span></div>
</div>
<div id="mapDiv"></div>
</body>
</html>