forked from Esri/jquery-mobile-map-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_twopage.html
203 lines (170 loc) · 6.55 KB
/
index_twopage.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
<!DOCTYPE html>
<html>
<head>
<!--
Sample application to demonstrate using the jQueryHelper library.
-->
<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>Two Page jQuery Mobile Map</title>
<link rel="stylesheet" type="text/css" href="css/themes/black-theme.min.css"/>
<link rel="stylesheet" type="text/css" href="css/themes/jquery.mobile.icons.min.css"/>
<link rel="stylesheet" href="http://js.arcgis.com/3.13/esri/css/esri.css">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css" />
<style type="text/css">
html,body, div[data-role ="page"] {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
overflow: hidden !important;
}
.ui-header{
margin: 0px !important;
padding: 0px !important;
float: left;
}
.ui-content{
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
}
.settings{
margin-left: auto;
margin-right: auto;
text-align:center;
width: 100%;
}
#mapDiv {
position: absolute;
background-color: #EEEEDD;
height: 100%;
width: 100%;
padding: 0px;
z-index: 0;
left: 0px;
}
</style>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js"></script>
</head>
<body>
<div data-role="page" id="home">
<div data-theme="b" data-role="header" data-position="fixed">
<h3>HTML5 Geolocation</h3>
<a href="#settings" data-role="button" data-transition="slide"
data-icon="gear" class="ui-btn-right" data-iconpos="notext">Settings</a>
</div>
<div data-role="content">
<div id="mapDiv"></div>
</div>
<script type="text/javascript">
$( '#home' ).on( 'pageinit',function(event){
jqueryInit();
});
</script>
</div>
<div data-role="page" id="settings">
<div data-role="header" data-theme="b" data-position="fixed">
<h1>Settings</h1>
<a href="#home" data-role="button" data-rel="back"
data-icon="home" class="ui-btn-icon-left" data-iconpos="notext"></a>
</div>
<div data-role="content">
<div class="settings" style="margin-top: 15px;">
<div>Geolocation:</div>
<select name="slider" id="slider-geo-on-off" data-role="slider" data-theme="b">
<option value="off">Off</option>
<option value="on" selected>On</option>
</select>
</div>
</div>
</div>
<script src="src/jQueryHelper.js"></script>
<script src="http://js.arcgis.com/3.13/"></script>
<script>
var map, geolocation = null;
function jqueryInit(){
require(["esri/map","esri/symbols/PictureMarkerSymbol","dojo/domReady!"],
function(Map,PictureMarkerSymbol) {
var helper = null;
var geoEnabled = true;
map = new Map("mapDiv", {
basemap: "streets",
center: [-98.5,39.8], // long, lat
zoom: 4
});
////////////////////
//Listeners
////////////////////
//Listen for map load event
map.on("load",init);
function init(){
//Some browsers don't show full height after onLoad
map.reposition();
map.resize();
try{
helper = new jQueryHelper(map);
}
catch(err) {
console.log("Unable to initialize jQueryHelper: " + err.message);
}
startGeolocation();
}
// Listen for map loaded event from jqueryHelper.
$(document).on("helper-map-loaded",function(evt){
console.log("helper-map-loaded event fired. " + evt.message)
map = helper.map;
if(geoEnabled == true) {
startGeolocation();
}
})
//Listen for Geolocation on/off button events
$("#slider-geo-on-off").change(function(event){
event.stopPropagation();
var test = $(this);
var value = test[0].selectedIndex == 1 ? true:false;
geoEnabled = value;
if(geoEnabled == false){
navigator.geolocation.clearWatch(geolocation);
geolocation = null;
console.log("Geolocation off");
}
})
////////////////////
//End of Listeners
////////////////////
// Create the marker symbol
var markerSymbol = new PictureMarkerSymbol({
"angle":0,
"xoffset":0,
"yoffset":0,
"type":"esriPMS",
"url":"images/green-pin.png",
"width":35,
"height":35
})
function startGeolocation(){
geolocation = navigator.geolocation.getCurrentPosition(locationSuccess,locationError,{setHighAccuracy:true});
}
// Handle location success
function locationSuccess(position){
if(position.coords.latitude != null || position.coords.longitude != null){
var wgsPt = new esri.geometry.Point(position.coords.longitude,position.coords.latitude);
map.graphics.add(new esri.Graphic(wgsPt, markerSymbol));
map.centerAndZoom(wgsPt, 9);
//Set jQueryHelper properties
helper.setCenterPt(position.coords.latitude,position.coords.longitude,4326);
helper.setZoom(9);
}
}
function locationError(err){
console.log("LocationError: " + err.message);
}
}
);
}
</script>
</body>
</html>