This repository has been archived by the owner on May 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapScript.js
155 lines (141 loc) · 4.78 KB
/
mapScript.js
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
//Load maps
gothere.load("maps");
//Global Variables
var map;
var geocoder;
var directions;
var amenities;
//When first form is submitted
function submitBtn(){
if($("#fromForm").val() === "" || $("#toForm").val() === ""){
event.preventDefault();
alert("Field is empty");
return false();
}else{
//Set Data to Session Storage
var fromForm = $('#fromForm').val();
sessionStorage.setItem('from', fromForm);
var toForm = $('#toForm').val();
sessionStorage.setItem('to', toForm);
}
}
//When second form is submitted
function submittedBtn(){
if($("#modeForm").val() === ""){
event.preventDefault();
alert("Field is empty");
return false();
}else{
//Set Data to Session Storage
var modeForm = $("#modeForm").val();
sessionStorage.setItem('modeR', modeForm);
}
}
//When document is ready
$(document).ready(function(){
//Retrieve data from Session Storage
$('#fromMap').val(sessionStorage.getItem('from'));
$('#toMap').val(sessionStorage.getItem('to'));
$('#modeMap').val(sessionStorage.getItem('modeR'));
console.log(sessionStorage.getItem('from'));
console.log(sessionStorage.getItem('to'));
console.log(sessionStorage.getItem('modeR'));
})
// Initialize Map Function
function initializeMap() {
if (GBrowserIsCompatible()) {
// Create map
map = new GMap2(document.getElementById("map"));
// Center of the map.
map.setCenter(new GLatLng(1.362083, 103.819836), 11);
// Add zoom controls on the top left of the map
map.addControl(new GSmallMapControl());
// Add a scale bar at the bottom left of the map
map.addControl(new GScaleControl());
directions = new GDirections(map, document.getElementById("panel"));
// directions.load("from: Changi Airport to: Orchard Road");
amenities = new GAmenities(map, document.getElementById("panel"));
//amenities
geocoder = new GClientGeocoder();
}
}
// Get Amenities Results
function getAmenities(query, category) {
map.closeInfoWindow();
amenities.clear();
map.clearOverlays();
var categoryToRequest;
switch(category) {
case "supermarkets":
categoryToRequest = GAmenities.AMENITY_SUPERMARKET;
break;
case "clinics":
categoryToRequest = GAmenities.AMENITY_CLINIC;
break;
case "postoffices":
categoryToRequest = GAmenities.AMENITY_POST_OFFICE;
break;
case "schools":
categoryToRequest = GAmenities.AMENITY_SCHOOL;
break;
case "atms":
categoryToRequest = GAmenities.AMENITY_ATM;
break;
case "banks":
categoryToRequest = GAmenities.AMENITY_BANK;
break;
case "petrolkiosks":
categoryToRequest = GAmenities.AMENITY_PETROL_KIOSK;
break;
case "busstops":
categoryToRequest = GAmenities.AMENITY_BUS_STOP;
break;
case "railstations":
default:
categoryToRequest = GAmenities.AMENITY_RAIL_STATION;
break;
}
amenities.clearCategories();
amenities.addCategory(categoryToRequest, GAmenities.LARGE_RESULTSET);
geocoder.getLatLng(query, function(latlng) {
if (latlng) {
amenities.load(latlng);
map.addOverlay(new GMarker(latlng));
}
});
//If input is empty, return alert
if($("#selectionA").val() === ""){
alert("Field is empty");
return false();
}
}
//Get Directions Results
function getDirections(from, to, mode) {
var travelMode;
switch(mode) {
case "pt":
travelMode = G_TRAVEL_MODE_TRANSIT;
break;
case "pt_b":
travelMode = G_TRAVEL_MODE_BUS;
break;
case "pt_t":
travelMode = G_TRAVEL_MODE_TRAIN;
break;
case "t":
travelMode = G_TRAVEL_MODE_TAXI;
break;
case "d":
default:
travelMode = G_TRAVEL_MODE_DRIVING;
break;
}
directions.load("from: " + from + " to: " + to, {travelMode: travelMode});
//If input is empty, return alert
if($("#modeMap").val() === "" || $("#modeMap").val() === null){
alert("Field is empty");
return false();
}
}
//Initialize Map
gothere.setOnLoadCallback(initializeMap);