forked from NoashX/NoashX.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compactTracks.html
191 lines (164 loc) · 6.03 KB
/
compactTracks.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Sets whether a web application runs in full-screen mode. -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<!-- Sets the style of the status bar for a web application. -->
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<title>Geolocate</title>
<link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.11/esri/css/esri.css">
<style type="text/css">
html, body {
height: 100%;
margin: 0px;
padding: 0px;
width: 100%;
}
#map {
height: 100%;
width: 100%;
}
</style>
<script src="//js.arcgis.com/3.11compact/"></script>
<script>
dojo.require("esri.map");
dojo.require("esri.layers.FeatureLayer");
var map, featureLayer;
function init() {
//onorientationchange doesn't always fire in a timely manner in Android so check for both orientationchange and resize
var supportsOrientationChange = "onorientationchange" in window, orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
window.addEventListener(orientationEvent, function() {
orientationChanged();
}, false);
map = new esri.Map("map", {
basemap: "streets",
zoom: 18
});
dojo.connect(map, "onLoad", initFunc);
}
function initFunc(map) {
//create a layer definition for the gps points
var layerDefinition = {
"geometryType" : "esriGeometryPoint",
"timeInfo" : {
"startTimeField" : "DATETIME",
"endTimeField" : null,
"timeExtent" : [1277412330365],
"timeInterval" : 1,
"timeIntervalUnits" : "esriTimeUnitsMinutes"
},
"fields" : [
{
"name" : "OBJECTID",
"type" : "esriFieldTypeOID",
"alias" : "OBJECTID"
},
{
"name" : "DATETIME",
"type" : "esriFieldTypeDate",
"alias" : "DATETIME"
},
{
"name" : "Path_1",
"type" : "esriFieldTypeString",
"alias" : "DATETIME"
}
]
};
var featureCollection = {
layerDefinition : layerDefinition,
featureSet : null
};
// feature layer
featureLayer = new esri.layers.FeatureLayer(featureCollection,{trackIdField: "Path_1"});
//setup a temporal renderer
var sms = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([255, 0, 0])).setSize(8);
var observationRenderer = new esri.renderer.SimpleRenderer(sms);
var latestObservationRenderer = new esri.renderer.SimpleRenderer(new esri.symbol.SimpleMarkerSymbol());
var infos = [{
minAge : 0,
maxAge : 1,
color : new dojo.Color([255, 0, 0])
}, {
minAge : 1,
maxAge : 5,
color : new dojo.Color([255, 153, 0])
}, {
minAge : 5,
maxAge : 10,
color : new dojo.Color([255, 204, 0])
}, {
minAge : 10,
maxAge : Infinity,
color : new dojo.Color([0, 0, 0, 0])
}];
var ager = new esri.renderer.TimeClassBreaksAger(infos, esri.renderer.TimeClassBreaksAger.UNIT_MINUTES);
var sls = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 3);
var trackRenderer = new esri.renderer.SimpleRenderer(sls);
var renderer = new esri.renderer.TemporalRenderer(observationRenderer, latestObservationRenderer, trackRenderer, ager);
featureLayer.setRenderer(renderer);
map.addLayer(featureLayer);
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(zoomToLocation, locationError);
navigator.geolocation.watchPosition(showLocation, locationError);
}
}
function locationError(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
alert("Location not provided");
break;
case error.POSITION_UNAVAILABLE:
alert("Current location not available");
break;
case error.TIMEOUT:
alert("Timeout");
break;
default:
alert("unknown error");
break;
}
}
function zoomToLocation(location) {
var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(location.coords.longitude, location.coords.latitude));
map.centerAndZoom(pt, 16);
}
function showLocation(location) {
if(location.coords.accuracy <= 500) {
var now = new Date();
var attributes = {};
attributes.DATETIME = now.getTime();
attributes.Path_1 = makeid();
var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(location.coords.longitude, location.coords.latitude));
var graphic = new esri.Graphic(new esri.geometry.Point(pt, map.spatialReference), null, attributes);
featureLayer.applyEdits([graphic], null, null, function(adds) {
map.setTimeExtent(new esri.TimeExtent(null, new Date()));
map.centerAt(graphic.geometry);
});
} else {
console.log("Point not added due to low accuracy: " + location.coords.accuracy);
}
}
function makeid()
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
function orientationChanged() {
if(map) {
map.reposition();
map.resize();
}
}
dojo.ready(init);
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>