-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
280 lines (228 loc) · 7.23 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>ArcGIS test</title>
<link rel="stylesheet" href="//js.arcgis.com/3.14/esri/css/esri.css">
<link rel="stylesheet" href="//js.arcgis.com/3.14/dijit/themes/claro/claro.css">
<script src="//js.arcgis.com/3.14/"></script>
<style>
html, body, #mapDiv {
padding: 0;
margin: 0;
height: 100%;
}
#BasemapToggle {
position: absolute;
top: 20px;
right: 5px;
z-index: 50;
}
#search {
display: block;
position: absolute;
z-index: 2;
top: 20px;
max-width:100px;
}
#LocateButton {
position: absolute;
top: 101px;
right: 4px;
z-index: 50;
}
#gpsStatus{
position:absolute;
z-index:51;
}
</style>
</head>
<body class="claro">
<div id="gpsStatus"><span id="gpsStatusTime"></span><span id="gpsStatusText"></span></div>
<div id="mapDiv">
<div id="search"></div>
<div id="LocateButton"></div>
<div id="BasemapToggle"></div>
</div>
<script>
console.log([dojo.version.major, dojo.version.minor, dojo.version.patch].join("."));
var globalMap;
require([
"esri/map",
"esri/dijit/BasemapToggle",
"esri/dijit/LocateButton",
"esri/dijit/Search",
"dojo/parser",
"dojo/on",
"esri/geometry/Point",
"esri/graphic",
"esri/Color",
"dojo/window",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/CartographicLineSymbol",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dojo/domReady!"
],
function(Map,
BasemapToggle,
LocateButton,
Search,
parser,
on,
Point,
Graphic,
Color,
win,
SimpleLineSymbol,
SimpleMarkerSymbol,
CartographicLineSymbol
) {
//SYMBOLFIX is a value in degrees for fixing the arrow symbol's orientation, atm it points 45 degs to the right
const SYMBOLFIX = -45;
var lastCompassValue = 0;
var graphic;
var gpsStatusIntervalHandle = undefined;
//compass functionality
//if apple, use webkitcompass, else, use event.alpha
window.addEventListener("deviceorientation", setCompassValue,false);
function setCompassValue(evt) {
var compassHeading = evt.compassHeading || evt.webkitCompassHeading || -1;
//not changed enough, more than 5 degs that is
if(compassHeading !== -1){
//setInterval(function(){alert(compassHeading + "--"+window.orientation);},1000);
if(compassHeading - lastCompassValue < 5 && compassHeading - lastCompassValue > -5)
return;
}
else{
if(evt.alpha - lastCompassValue < 5 && evt.alpha - lastCompassValue > -5)
return;
}
if(compassHeading !== -1)
lastCompassValue = compassHeading;
//fix for angle in evt.alpha being the wrong way
else
lastCompassValue = -evt.alpha;
if(graphic){
graphic.symbol.setAngle(parseInt(lastCompassValue)+SYMBOLFIX);
//graphic.symbol.setAngle(90+SYMBOLFIX);
graphic.draw();
}
}
//handle device's orientation change
var supportsOrientationChange = "onorientationchange" in window,
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
window.addEventListener(orientationEvent, function () {
if (globalMap) {
globalMap.reposition();
globalMap.resize();
}
}, false);
//parse the element-type stylings
parser.parse();
//the map itself
globalMap = new Map("mapDiv", {
center: [24.850015, 60.239143],
zoom: 16,
basemap: "gray",
slider:false
});
//pass the map to handler
on(globalMap, "load", mapLoadHandler);
//choose between map styles (eg. hi-fi vs. lo-fi)
var toggle = new BasemapToggle({
map: globalMap,
basemap: "topo",
basemaps: {
"topo":{
"title":"hi-fi",
"thumbnailUrl":"http://js.arcgis.com/3.11/esri/dijit/images/basemaps/topo.jpg"},
"gray":{
"title":"lo-fi",
"thumbnailUrl":"http://js.arcgis.com/3.11/esri/dijit/images/basemaps/gray.jpg"}
}
}, "BasemapToggle");
toggle.startup();
//add a searchfield for geocoding
var searchField = new Search({
map: globalMap,
enableInfoWindow:false,
enableButtonMode:true,
}, "search");
searchField.startup();
//
var geoLocate = new LocateButton(
{
map: globalMap,
highlightLocation:false,
}, "LocateButton"
);
geoLocate.startup();
//add an arrow which should point to the same direction as user
function addGraphic(pt) {
var symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_PATH, 30, new SimpleLineSymbol(), new Color([10, 10, 10, 0.9]));
//with this arrow symbol, SYMBOLFIX is -45
symbol.setPath("M15.834,29.084 15.834,16.166 2.917,16.166 29.083,2.917z");
//console.log(symbol)
graphic = new Graphic(pt, symbol);
globalMap.graphics.add(graphic);
//initial arrow symbol angle placement
graphic.symbol.angle = lastCompassValue+SYMBOLFIX;
}
//show the graphic or move it
function showLocation(location) {
pt = esri.geometry.geographicToWebMercator(new Point(location.coords.longitude, location.coords.latitude));
if (!graphic) {
addGraphic(pt);
} else {
//move the graphic if it already exists
graphic.setGeometry(pt);
}
//update status time
document.getElementById("gpsStatusTime").innerHTML = 0;
document.getElementById("gpsStatusText").innerHTML = " s since last update from GPS";
if(!gpsStatusIntervalHandle){
gpsStatusIntervalHandle = setInterval(
function(){
document.getElementById("gpsStatusTime").innerHTML = parseInt(document.getElementById("gpsStatusTime").innerHTML)+1;
},1000
);
}
globalMap.centerAt(pt);
}
// The HTML5 geolocation API is used to get the user's current position.
function mapLoadHandler() {
on(window, 'resize', globalMap, globalMap.resize);
// check if geolocation is supported
if (navigator.geolocation) {
// retrieve update about the current geographic location of the device
watchId = navigator.geolocation.watchPosition(showLocation, locationError,{enableHighAccuracy:true,maximumAge:3000});
} else {
alert("Browser doesn't support Geolocation. Visit http://caniuse.com to discover browser support for the Geolocation API.");
}
}
//error handling func, pretty much useless now
function locationError(error) {
//UPDATE! not stopping
if (navigator.geolocation) {
// navigator.geolocation.clearWatch(watchId);
}
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;
}
}
});
</script>
</body>