-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
258 lines (205 loc) · 6.09 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
<!DOCTYPE html>
<html>
<head>
<title>Open Bangalore Maps</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./leaflet/leaflet.css" />
<link rel="stylesheet" href="./locate/L.Control.Locate.css" />
<!--[if lte IE 8]><link rel="stylesheet" href=./leaflet/leaflet.ie.css" /><![endif]-->
<style>
#map {
width: 99%;
height: 600px;
}
.info {
padding: 6px 8px;
font: 14px/16px Arial, Helvetica, sans-serif;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
width:250px;
}
.info h4 {
margin: 0 0 5px;
color: #777;
}
.legend {
text-align: left;
line-height: 18px;
color: #555;
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
}
</style>
<script src="terraformer.js" type="text/javascript"></script>
<script src="terraformer-geostore.js" type="text/javascript"></script>
<script src="terraformer-geostore-memory.js" type="text/javascript"></script>
<script src="terraformer-geostore-rtree.js" type="text/javascript"></script>
<script src="terraformer-arcgis-parser.js" type="text/javascript"></script>
<script type="text/javascript" src="wards.js"></script>
<script src="./leaflet/leaflet.js"></script>
<script src="./locate/L.Control.Locate.js"></script>
<link rel="stylesheet" href="./geocoder/Control.Geocoder.css" />
<script src="./geocoder/Control.Geocoder.js"></script>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
var map_title = "Where am I?";
var map_attribution = 'Data From © <a href="http://openbangalore.org/">OpenBangalore</a>'
var map = L.map('map').setView([ 12.976549,77.594397], 13);
var whereami = L.marker([ 12.976549,77.594397]).addTo(map);
var mapquestUrl = 'http://{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png',
subDomains = ['otile1','otile2','otile3','otile4'];
var mapquest = new L.TileLayer(mapquestUrl, {maxZoom: 18, subdomains: subDomains});
mapquest.addTo(map);
function callMyLocation(lat,lng) {
highlightGivenAPoint(lat,lng);
}
locate_using_gps= L.control.locate().addTo(map);
var geocoder = L.Control.geocoder({"collapsed":true,"position":"topleft"}).addTo(map);
geocoder.markGeocode = function(result) {
highlightGivenAPoint(result.center.lat,result.center.lng);
};
// control that shows state info on hover
var info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
info.update = function (props) {
this._div.innerHTML = '<h4>'+map_title+'</h4>' + (props ?
'<b>' + props.WARD_NAME + '('+props.WARD_NO+')</b>'+ ' '
: 'Click on the map or use GPS or Search to find your ward.');
};
info.addTo(map);
// get color depending on population density value
function getColor(d) {
return d > 1000 ? '#800026' :
d > 500 ? '#BD0026' :
d > 200 ? '#E31A1C' :
d > 100 ? '#FC4E2A' :
d > 50 ? '#FD8D3C' :
d > 20 ? '#FEB24C' :
d > 10 ? '#FED976' :
'#FFEDA0';
}
function style(feature) {
return {
weight: 1,
opacity: 0.7,
color: '#800026',
dashArray: '1',
fillOpacity: 0.1,
//fillColor: getColor(feature.properties.WARD_NO)
fillColor:'#FFEDA0'
};
}
function highlightFeature(e) {
if (e.target !== undefined ){
var layer = e.target;
}else{
var layer = e;
}
layer.setStyle({
weight: 1,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
var geojson;
function resetHighlight(e) {
//geojson.resetStyle(e.target);
geojson.eachLayer(function(l){geojson.resetStyle(l);});
info.update();
}
function zoomToFeature(e) {
if (e.target !== undefined ){
var layer = e.target;
}else{
var layer = e;
}
map.fitBounds(layer.getBounds());
resetHighlight(e);
highlightFeature(e);
}
function onEachFeature(feature, layer) {
layer.on({
//mouseover: highlightFeature,
//mouseout: resetHighlight,
click: zoomToFeature
});
}
geojson = L.geoJson(ward_b, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);
console.log(geojson);
map.attributionControl.addAttribution(map_attribution);
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
div.innerHTML = '<h1>Where am I ?</h1>';
return div;
};
legend.addTo(map);
// create a GeoStore
var WardsGeoStore = new Terraformer.GeoStore({
store: new Terraformer.GeoStore.Memory(),
index: new Terraformer.RTree()
});
// wait for the load event
// loop over counties
my_wards = ward_b["features"];
for (var i = my_wards.length - 1; i >= 0; i--) {
var w = my_wards[i];
//console.log(w);
// insert into the index
WardsGeoStore.add(w);
}
function findMe() {
// One-shot position request.
navigator.geolocation.getCurrentPosition(function (position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
// Query location
//coordinates: [ 77.542303, 12.953592 ]
//coordinates: [ lng, lat ]
});
}
function highlightGivenAPoint(lat,lng){
whereami.setLatLng([lat,lng]);
var point = new Terraformer.Primitive({"type": "Point",
coordinates: [ lng, lat ]
});
var def = WardsGeoStore.contains(point,function(err,results){
if (results.length) {
console.log(1);
all_wards = geojson.getLayers();
for(i=0; i <all_wards.length; i++ ){
if (all_wards[i].feature.id == results[0].id){
zoomToFeature(all_wards[i]);
break;
}
}
} else {
alert("nothing");
}
});
}
</script>
</body>
</html>