-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
468 lines (404 loc) · 15.6 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
<!DOCTYPE html>
<html>
<head>
<title>POI Locator Demo</title>
<meta charset="utf-8" />
<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=no" />
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<style>
body {
padding: 0;
margin: 0;
}
html,
body,
#map {
height: 100%;
}
.info {
padding: 6px 8px;
font: 14px/16px Arial, Helvetica, sans-serif;
background: white;
background: rgba(255, 255, 255, 0.8);
}
</style>
</head>
<body>
<div id="map"></div>
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="./lib/leaflet-pip.min.js"></script>
<script src="./lib/lunr.min.js"></script>
<script src="./lib/NonTiledLayer.js"></script>
<script src="./lib/NonTiledLayer.WMS.js"></script>
<script src="./lib/helper.js"></script>
<script type="text/javascript">
// set up the map
var attribution = '<a href="http://www.ptvgroup.com">PTV</a>, TOMTOM';
var xMapWmsUrl = '/XServerProxy/WMS/WMS';
// create a map in the "map" div, set the view to a given place and zoom
var map = new L.Map('map');
// insert xMap back- and forground layers with sandbox-style
getXMapBaseLayers(xMapWmsUrl, "sandbox", token, attribution).addTo(map);
var token = null; // not using a token, no direct xServer access
// add scale control
L.control.scale().addTo(map);
var searchLocation;
var isoFeature;
var highlightedPois = [];
var isBusy = false;
var marker;
var horizon = 600;
var searchMethod = 0;
var index;
// add the application data
$.get('./MapData.ashx', function (data) {
poiData = data;
// initialize layer
var layer = L.geoJson(poiData, {
pointToLayer: style
}).addTo(map);
// create full text index
index = lunr(function () {
this.field('description', {
boost: 10
}),
this.ref('id');
});
for (var i = 0; i < poiData.features.length; i++) {
index.add({
id: i,
description: poiData.features[i].properties.description
});
}
// fit bounds
map.fitBounds(layer.getBounds(), { maxZoom: 14 });
});
// url we're sending the request to
var isoUrl = '/XServerProxy/xroute/rs/XRoute/calculateIsochrones';
var findAddressUrl = '/XServerProxy/xlocate/rs/XLocate/findAddressByText';
var searchForReachableObjectsUrl = '/XServerProxy/xroute/rs/XRoute/calculateReachableObjects';
map.on('click', onMapClick);
// add input control
var info = L.control();
info.onAdd = function (map) {
var container = L.DomUtil.create('div', 'info leaflet-bar');
var clickcmd = "if(!isBusy)findByAddress(document.getElementById('f1').value);";
var fuzzySearchCmd = "if(!isBusy)findFuzzy(document.getElementById('f2').value);";
var html =
'<div>Click on map or find near address</div>' +
'<div>' +
'<input type="text" id="f1" value="Hamburg, Rathausmarkt">' +
'<input type="button" value="Find" onClick="' + clickcmd + '">' +
'</div><br>' +
'<div>Search method</div>' +
'<div>' +
'<input type="radio" name="searchmethod" checked="true" onclick="setSearchMethod(0);">airline' +
'<input type="radio" name="searchmethod" onclick="setSearchMethod(1);">route' +
'<input type="radio" name="searchmethod" onclick="setSearchMethod(2);">isochrone' +
'</div><br>' +
'<div>Horizon</div>' +
'<div>' +
'<input type="radio" name="horizon" checked="true" onclick="setHorizon(600);">10 min' +
'<input type="radio" name="horizon" onclick="setHorizon(1200);">20 min' +
'<input type="radio" name="horizon" onclick="setHorizon(1800);">30 min' +
'</div><br>' +
'<div>Or find stores by name</div>' +
'<div>' +
'<input type="text" id="f2" value="Metro">' +
'<input type="button" value="Find" onClick="' + fuzzySearchCmd + '">' +
'</div>';
container.innerHTML = html;
fixClickPropagationSoItWorksForIE11(container);
return container;
};
info.addTo(map);
function setBusy(busy) {
isBusy = busy;
}
function findNearestObjects() {
if (!searchLocation)
return;
cleanupMarkers();
var c = 'marker-red';
marker = L.marker(searchLocation, {
zIndexOffset: 1000,
icon: new L.Icon.Default({
iconUrl: "icons/" + c + ".png",
iconRetinaUrl: "icons/" + c + "-2x.png"
})
}).addTo(map);
marker.bindPopup(latFormatter(searchLocation.lat) + ", " + lngFormatter(searchLocation.lng));
if (searchMethod == 0)
findByAirline(searchLocation, horizon);
else if (searchMethod == 1)
findByReachableObjects(searchLocation, horizon);
else
findByIso(searchLocation, horizon);
}
function setSearchMethod(method) {
searchMethod = method;
findNearestObjects();
}
function setHorizon(hor) {
horizon = hor;
findNearestObjects();
}
function onMapClick(e) {
if (isBusy)
return;
searchLocation = e.latlng;
findNearestObjects();
}
function findFuzzy(name) {
cleanupMarkers();
var res = index.search(name);
for (var i = 0; i < res.length; i++) {
highlightPoi(poiData.features[res[i].ref], 'marker-green');
}
setBounds(highlightedPois);
}
function findByAddress(adr) {
var request = {
"address": adr,
"country": "D",
"options": [],
"sorting": [],
"additionalFields": [],
"callerContext": {
"properties": [{
"key": "CoordFormat",
"value": "OG_GEODECIMAL"
}, {
"key": "Profile",
"value": "default"
}]
}
};
setBusy(true);
runRequest(
findAddressUrl,
request,
token,
function (response) {
var firstResult = response.resultList[0].coordinates.point;
searchLocation = new L.LatLng(firstResult.y, firstResult.x);
findNearestObjects();
},
function (xhr) {
alert(xhr);
setBusy(false);
});
}
function findByIso(latlng, hor) {
setBusy(true);
var request = {
"sink": {
"coords": [{
"point": {
"x": latlng.lng,
"y": latlng.lat
}
}],
"linkType": "NEXT_SEGMENT"
},
"options": [],
"isoOptions": {
"isoDetail": "POLYS_ONLY",
"polygonCalculationMode": "NODE_BASED",
"expansionDesc": {
"expansionType": "EXP_TIME",
"horizons": [
hor
]
}
},
"callerContext": {
"properties": [{
"key": "CoordFormat",
"value": "OG_GEODECIMAL"
}, {
"key": "ResponseGeometry",
"value": "WKT"
}, {
"key": "Profile",
"value": "pedestrian"
}]
}
};
runRequest(
isoUrl,
request,
token,
function (response) {
var x = isoToPoly(response.isochrones[0].polys.wkt);
var feature = {
"type": "Feature",
"properties": {
"style": {
weight: 4,
color: "#222",
opacity: 1,
fillColor: "#fff",
fillOpacity: 0.5
}
}
};
feature.geometry = {
type: 'Polygon',
coordinates: x
};
isoFeature = L.geoJson([feature], {
style: function (feature) {
return feature.properties && feature.properties.style;
}
});
isoFeature.on('click', onMapClick);
isoFeature.addTo(map);
for (var i = 0; i < poiData.features.length; i++) {
if (leafletPip.pointInLayer(poiData.features[i].geometry.coordinates, isoFeature).length > 0) {
highlightPoi(poiData.features[i], 'marker-green', null, true);
}
}
map.fitBounds(isoFeature.getBounds(), { maxZoom: 15 });
setBusy(false);
},
function (xhr) {
setBusy(false);
});
}
function filterByAirline(latlng, hor) {
var result = new Array();
var range = hor /*=s*/ * 6 /* km/h */ / 3.6 /*=m/s */;
for (var i = 0; i < poiData.features.length; i++) {
var poiLocation = poiData.features[i].geometry.coordinates;
var p = L.latLng(poiLocation[1], poiLocation[0]);
var distance = latlng.distanceTo(p);
if (distance < range) {
result.push({ distance: distance, data: poiData.features[i] });
}
}
return result;
}
function findByAirline(latlng, hor) {
var found = filterByAirline(latlng, hor);
for (var i = 0; i < found.length; i++) {
highlightPoi(found[i].data, 'marker-green', Math.round(found[i].distance) + "m", true);
}
setBounds(highlightedPois, latlng);
}
function findByReachableObjects(latlng, hor) {
var candidates = filterByAirline(latlng, hor);
var locations = new Array();
for (var i = 0; i < candidates.length; i++) {
var location = candidates[i].data.geometry.coordinates;
locations.push({
"coords": [{
"point": {
"x": location[0],
"y": location[1]
}
}],
"linkType": "NEXT_SEGMENT"
});
}
setBusy(true);
var request = {
"sink": {
"coords": [{
"point": {
"x": latlng.lng,
"y": latlng.lat
}
}],
"linkType": "NEXT_SEGMENT"
},
"binaryPathDesc": null,
"locations": locations,
"options": [],
"expansionDesc": {
"expansionType": "EXP_TIME",
"horizons": [
hor
]
},
"callerContext": {
"properties": [{
"key": "CoordFormat",
"value": "OG_GEODECIMAL"
}, {
"key": "ResponseGeometry",
"value": "WKT"
}, {
"key": "Profile",
"value": "pedestrian"
}]
}
};
runRequest(
searchForReachableObjectsUrl,
request,
token,
function (response) {
setBusy(false);
for (var i = 0; i < response.reachInfo.length; i++) {
if (response.reachInfo[i].reachable) {
highlightPoi(candidates[i].data, 'marker-green', response.reachInfo[i].routeInfo.distance + "m", true);
}
}
setBounds(highlightedPois, latlng);
},
function (xhr) {
setBusy(false);
});
}
function setBounds(features, center) {
var arr = [];
for (var i = 0; i < features.length; i++) {
arr.push(features[i]._latlng);
}
if (center)
arr.push(center);
var bounds = new L.LatLngBounds(arr);
map.fitBounds(bounds, { maxZoom: 15 });
}
function cleanupMarkers() {
for (var i = 0; i < highlightedPois.length; i++) {
map.removeLayer(highlightedPois[i]);
}
highlightedPois = [];
if (isoFeature)
map.removeLayer(isoFeature);
if (marker)
map.removeLayer(marker);
}
function highlightPoi(feature, c, additionalInfo, drawSpiderLine) {
var latlon = [feature.geometry.coordinates[1], feature.geometry.coordinates[0]];
var popUp = feature.properties.description;
if (additionalInfo)
popUp = popUp + "<br>" + additionalInfo;
var highlightedPoi = L.marker(latlon, {
zIndexOffset: 1000,
icon: new L.Icon.Default({
iconUrl: "icons/" + c + ".png",
iconRetinaUrl: "icons/" + c + "-2x.png"
})
}).addTo(map);
highlightedPoi.bindPopup(popUp);
if (drawSpiderLine) {
var spidlerLineline = L.polyline([searchLocation, latlon], { color: 'red' }).addTo(map)
highlightedPois.push(spidlerLineline);
spidlerLineline.bindPopup(popUp);
}
highlightedPois.push(highlightedPoi);
}
function style(feature, latlng) {
var style =
L.circleMarker([feature.geometry.coordinates[1], feature.geometry.coordinates[0]], {});
style.bindPopup(feature.properties.description);
return style;
}
</script>
</body>
</html>