-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
175 lines (149 loc) · 6.05 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
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="application-name" content="OpenLayers Demo">
<link rel="shortcut icon" sizes="196x196" href="icon.png">
<title>OpenLayers Demo</title>
<script src="http://people.rit.edu/yxs9493/api/jquery-1.11.0.min.js"></script>
<script src="http://www.ist.rit.edu/~jxs/classes/2014_Spring/Mobile/OpenLayers-2.13.1/OpenLayers.js" type="text/javascript"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type="text/javascript">
var openStreet = new Object();
openStreet.map = null;
function init() {
openStreet.map = new OpenLayers.Map( "basicMap" );
var mapnik = new OpenLayers.Layer.OSM();
var fromProjection = new OpenLayers.Projection( "EPSG:4326" ); // Transform from WGS 1984
var toProjection = new OpenLayers.Projection( "EPSG:900913" ); // to Spherical Mercator Projection
var position = new OpenLayers.LonLat( -77.68,43.08 ).transform( fromProjection, toProjection );
/* var position = new OpenLayers.LonLat( 13.41,52.52 ).transform( fromProjection, toProjection ); */
var zoom = 13; //g
openStreet.map.addLayer( mapnik );
openStreet.map.setCenter( position, zoom );
}
</script>
</head>
<body onload="init();">
<header>
<input type="button" value="Food" onclick="loadXML('food.json')" />
<input type="button" value="Gym" onclick="loadXML('gym.json')" />
<input type="button" value="Bank" onclick="loadXML('bank.json')" />
<input type="button" value="Gas Station" onclick="loadXML('gas_station.json')" />
<input type="button" value="Car rental" onclick="loadXML('car_rental.json')" />
<input type="button" value="Reset" onclick="clearMap()" />
<img id="toggle" src="leftarrow.png" width="35" height="50">
</header>
<div id="basicMap"></div>
<script type="text/javascript">
var useAddr = null;
//https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=43.083203,-77.675612&radius=500&types=gas&sensor=false&key=AIzaSyB552XRGHKDUT8xlocrn1nVJzS5u3WVqGY
//create marker icon
var size = new OpenLayers.Size(21,25);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png', size, offset);
/** track which user is using and display it.
*/
$(document).ready(function(){
$('#toggle').on('click',function(){
var panel = $(this).parent();
panel.animate({
left: parseInt(panel.css('left')) == -panel.outerWidth() ? 0 : -panel.outerWidth()
});
});
$('input[type=button]').click(function(){
//$(this).addClass('active');
});
//loadXML('food.xml');
});
function loadXML(filename)
{
//clearMap();
var xmlHTTP = new XMLHttpRequest();
try
{
xmlHTTP.open("GET", filename, false);
xmlHTTP.send(null);
}
catch (e) {
window.alert("Unable to load the requested file.");
return;
}
var response=xmlHTTP.responseText;
//console.log(response);
var obj = JSON.parse(response);
if(obj){
zero = obj.status;
obj = obj.results;
if( obj && zero.toUpperCase()!="ZERO_RESULTS" ){
processPoints(obj);
}
}else{
alert('can\'t process an empty JSON');
}
}
function processPoints(obj){
//layer for the markers
//var markerLayer = new OpenLayers.Layer.Markers("Markers");
markerLayer = new OpenLayers.Layer.Vector("Overlay");
var fromProjection = new OpenLayers.Projection( "EPSG:4326" ); // Transform from WGS 1984
var toProjection = new OpenLayers.Projection( "EPSG:900913" ); // to Spherical Mercator Projection
for(var i=0;i<obj.length;i++){
//console.log(obj[i]);
//var lonlat = new OpenLayers.LonLat(obj[i].geometry.location.lng, obj[i].geometry.location.lat).transform(fromProjection, toProjection);
var lonlat = new OpenLayers.Geometry.Point(obj[i].geometry.location.lng, obj[i].geometry.location.lat).transform(fromProjection, toProjection);
//markerLayer.addMarker(new OpenLayers.Marker(lonlat, icon));
var feature = new OpenLayers.Feature.Vector(lonlat,{description:obj[i].name} ,
{externalGraphic: 'marker.png', graphicHeight: 25, graphicWidth: 21, graphicXOffset:-12, graphicYOffset:-25 });
markerLayer.addFeatures(feature);
}
//console.log(markerLayer);
openStreet.map.addLayer(markerLayer);
}
function showSidebar(){
}
function hideSidebar(){
}
function showMarker(){
var fromProjection = new OpenLayers.Projection( "EPSG:4326" ); // Transform from WGS 1984
var toProjection = new OpenLayers.Projection( "EPSG:900913" ); // to Spherical Mercator Projection
markerLayer = new OpenLayers.Layer.Markers("Markers");
var myLong = -77.68;
var myLat = 43.08;
var lonlat = new OpenLayers.LonLat(myLong, myLat).transform(fromProjection, toProjection);
markerLayer.addMarker(new OpenLayers.Marker(lonlat, icon));
openStreet.map.addLayer(markerLayer);
}
function clearMap(){
//openStreet.map.markerLayer.clearMarkers();
//var arr = openStreet.map.markerLayer.markers;
//for(var i=0; i < arr.length; i++){
//arr[i].destroy();
//}
//openStreet.map.markerLayer.clearMarkers();
/*
var thisArr = openStreet.map.layers;
for(var i=0;i<thisArr.length;i++){
console.log(thisArr[i]);
features = [];
features.length = 0;
thisArr[i].removeAllFeatures();
if(thisArr.features){
alert('blah2');
thisArr[i].destoryFeatures();
}
}
*/
if(markerLayer !== undefined){
markerLayer.features = [];
markerLayer.features.length = 0;
markerLayer.removeAllFeatures();
}
}
</script>
<link rel="stylesheet" type="text/css" href="style.css">
</body>
</html>