-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkartta.html
More file actions
executable file
·141 lines (124 loc) · 4.21 KB
/
kartta.html
File metadata and controls
executable file
·141 lines (124 loc) · 4.21 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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Asdf</title>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script src="js/RouteBoxer.js" type="text/javascript"></script>
<script src="js/libs/jquery-1.8.0.js" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var boxpolys = null;
var markers = new Array();
var directions = null;
var routeBoxer = null;
var distance = null; // km
var infowindow = new google.maps.InfoWindow();
var marker, i;
function initialize() {
// Default the map view to the continental U.S.
var mapOptions = {
center: new google.maps.LatLng(60.170806,24.941919),
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 4
};
map = new google.maps.Map(document.getElementById("map"), mapOptions);
routeBoxer = new RouteBoxer();
directionService = new google.maps.DirectionsService();
directionsRenderer = new google.maps.DirectionsRenderer({ map: map });
}
function route() {
// Clear any previous route boxes from the map
clearBoxes();
clearMarkers();
distance = parseFloat(document.getElementById("distance").value);
var request = {
origin: document.getElementById("from").value,
destination: document.getElementById("to").value,
travelMode: google.maps.DirectionsTravelMode.DRIVING
}
// Make the directions request
directionService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsRenderer.setDirections(result);
// Box around the overview path of the first route
var path = result.routes[0].overview_path;
var boxes = routeBoxer.box(path, distance);
drawMarkers(boxes);
drawBoxes(boxes);
} else {
alert("Directions query failed: " + status);
}
});
}
function addLocation(location) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(location.lat, location.lon),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(location.title);
infowindow.open(map, marker);
}
})(marker, i));
markers.push(marker);
}
function drawMarkers(boxes) {
for (var i=0; i < boxes.length; i++) {
$.getJSON("/api/v1/pois.json?bbox="+boxes[i], function(json) {
if (json.length>0) {
for (i=0; i<json.length; i++) {
var location = json[i];
addLocation(location);
}
}
});
}
}
// Draw the array of boxes as polylines on the map
function drawBoxes(boxes) {
boxpolys = new Array(boxes.length);
for (var i = 0; i < boxes.length; i++) {
boxpolys[i] = new google.maps.Rectangle({
bounds: boxes[i],
fillOpacity: 0,
strokeOpacity: 1.0,
strokeColor: '#000000',
strokeWeight: 1,
map: map
});
}
}
// Clear boxes currently on the map
function clearBoxes() {
if (boxpolys != null) {
for (var i = 0; i < boxpolys.length; i++) {
boxpolys[i].setMap(null);
}
}
boxpolys = null;
}
// Clear markers currently on the map
function clearMarkers() {
for (var i = 0; i < markers.length; i++ ) {
markers[i].setMap(null);
}
markers = new Array();
}
</script>
<style>
#map {
border: 1px solid black;
}
</style>
</head>
<body onload="initialize();">
<div id="map" style="width: 800px; height: 600px;"></div>
Box within at least <input type="text" id="distance" value="20" size="2">km
of the route from <input type="text" id="from" value="Helsinki"/>
to <input type="text" id="to" value="Oulu"/>
<input type="submit" onclick="route()"/>
</body>
</html>