Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
92 lines (83 loc) · 2.88 KB
/
Copy pathutils.js
File metadata and controls
92 lines (83 loc) · 2.88 KB
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
// Initialize map to these values: Kalvin ter, Budapest
var BP_LATITUDE = 47.4896944;
var BP_LONGITUDE = 19.0618194;
// get custom icon for places of interest based on their type
function getIcon(place) {
if (isInArray(place.types, 'restaurant')) {
return 'icons/restaurant.png';
} else if (isInArray(place.types, 'lodging')) {
return 'icons/lodging.png';
} else if (isInArray(place.types, 'bus_station')) {
return 'icons/bus.png';
}
}
function isInArray(array, element) {
return array.indexOf(element) >= 0;
}
function getBusStopDetailsInfo(locationDetails, busStopDetails) {
return getBasicLocationInfo(locationDetails) + "<br>closest bus station: "
+ "<a href='javascript:moveMapTo("
+ busStopDetails.geometry.location.d + ","
+ busStopDetails.geometry.location.e + ");'>" + busStopDetails.name
+ "</a>";
}
function getBasicLocationInfo(details) {
return "<b>" + details.name + "</b>" + "<br>" + details.formatted_address
+ getReviewText(details.reviews);
}
// return the first review if it is available
function getReviewText(reviews) {
if (reviews == undefined || reviews[0] == undefined) {
return "";
}
var invalidUrl = reviews[0].author_url == undefined;
return "<br>" + (invalidUrl ? "" : "<a href='" + reviews[0].author_url
+ "' target='_blank'>") + reviews[0].author_name
+ (invalidUrl ? "" : "</a>") + ": " + reviews[0].text;
}
// remove existing markers. called whenever we change visible map
function removeUnseenMarkers(markers, bounds) {
var markersToKeep = [];
for ( var i = 0; i < markers.length; ++i) {
if (bounds.contains(markers[i].getPosition())) {
markersToKeep.push(markers[i]);
} else {
markers[i].setMap(null);
}
}
return markersToKeep;
}
// find the closest location on a spherical surface from an array of points
// using the build-in google method, which uses the Haversine formula
function findClosestLocation(location, array) {
var closestDistance = Number.MAX_VALUE;
var closestId = -1;
for ( var i = 0; i < array.length; ++i) {
var distance = google.maps.geometry.spherical.computeDistanceBetween(
location.geometry.location, array[i].geometry.location);
if (distance < closestDistance) {
closestDistance = distance;
closestId = i;
}
}
return array[closestId];
}
// search radius is based on the visible map's width and height. we take the
// smaller and divide it by 2.
function getSearchRadius(bounds) {
var ne = bounds.getNorthEast();
var sw = bounds.getSouthWest();
var nw = new google.maps.LatLng(ne.lat(), sw.lng());
var width = google.maps.geometry.spherical.computeDistanceBetween(ne, nw);
var height = google.maps.geometry.spherical.computeDistanceBetween(sw, nw);
return Math.min(width, height) / 2;
}
// create a request object for a single type
function request(searchCenter, searchRadius, type) {
var request = {
location : searchCenter,
radius : searchRadius,
types : [ type ]
};
return request;
}