-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
299 lines (246 loc) · 8.88 KB
/
main.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
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
let map;
let locations;
let user_pos;
let user_postcode;
let user_circle;
let accuracy_radius;
let info_card_context = new Hammer(document.getElementById("info-card"));
$("#map").on("click", slideUpBothCards)
$("#direction-btn").on("click", (e)=> {
let toilet = locations.filter(toilet => toilet.ToiletID == tid)[0]
window.location = `https://www.google.com/maps/dir/?api=1&origin=${user_pos.toUrlValue()}&destination=${toilet.Latitude},${toilet.Longitude}&travelmode=walking`
})
$("#save-btn").on("click", (e) => {
$("#save-btn").text("Saved")
})
$(".star-rating").on("click", (e) => {
let comment = $("#toilet-review").val();
$(".reviews").append('<div class="col-8"><p class="review-item">' + comment + '</p></div>');
$("#toilet-review").val("");
});
info_card_context.get('swipe').set({ direction: Hammer.DIRECTION_VERTICAL });
info_card_context.on('swipe', function(ev) {
tid = $("#info-card").data("tid")
if (ev.direction == Hammer.DIRECTION_UP) {
slideUpFullCard(tid)
} else if (ev.direction == Hammer.DIRECTION_DOWN) {
if ($("#info-page").hasClass("full")) {
slideDownFullCard(tid)
} else{
slideDownHalfCard(tid)
}
}
});
function slideUpBothCards() {
$("#info-card").removeClass("full")
$("#info-page").removeClass("full")
}
function slideUpFullCard(tid) {
$("#info-page").addClass("full")
}
function slideDownFullCard(tid) {
$("#info-page").removeClass("full")
}
function slideDownHalfCard(tid){
$("#info-card").removeClass("full")
}
function slideUpInfo(tid) {
$("#info-card").data("tid", tid);
let toilet = locations.filter(toilet => toilet.ToiletID == tid)[0]
$("#info-card").removeClass("full")
$(".icons").html("<h5>Features and Facilities</h5>");
console.log(toilet);
setTimeout(() => {
$(".rating").text(`4.5 ★`);
$(".address").text(toilet.Name);
if (toilet.OpeningHoursSchedule != "") {
$("#opening-hours").text(toilet.OpeningHoursSchedule);
} else if (toilet.OpeningHoursNote != "") {
$("#opening-hours").text(toilet.OpeningHoursNote);
} else {
$("#opening-hours").text("Open");
}
showFeatures(toilet);
$(".reviews").html('<div class="col-8"><p class="review-item">Wow I love this toilet!</p></div><div class="col-4"><p class="rating-small"><b>4.5 <span class="fa fa-star checked fa-small"></span></div>');
$("#info-card").addClass("full")
}, 300);
// $ ★
}
function showFeatures(toilet) {
if (toilet.Female == "True") {
$(".icons").append('<i class="feature-icon fas fa-female fa-2x"></i>');
}
if (toilet.Male == "True") {
$(".icons").append('<i class="feature-icon fas fa-male fa-2x"></i>');
}
if (toilet.AccessibleFemale == "True" && toilet.AccessibleMale == "True") {
$(".icons").append('<i class="feature-icon fas fa-wheelchair fa-2x"></i>');
}
if (toilet.Showers == "True") {
$(".icons").append('<i class="feature-icon fas fa-shower fa-2x"></i>');
}
if (toilet.BabyChange == "True") {
$(".icons").append('<i class="feature-icon fas fa-child fa-2x"></i>');
}
if (toilet.PaymentRequired == "False") {
$(".icons").append('<i class="material-icons md-36">money_off</i>');
}
if (toilet.Parking == "True") {
$(".icons").append('<i class="feature-icon fas fa-parking fa-2x"></i>');
}
if (toilet.DrinkingWater == "True") {
$(".icons").append('<i class="feature-icon fas fa-tint fa-2x"></i>');
}
if (toilet.SharpsDisposal == "True") {
$(".icons").append('<i class="feature-icon fas fa-syringe fa-2x"></i>');
}
}
function mark_closest_toilets_no_cookie(data) {
locations = data.result.records
let bounds = new google.maps.LatLngBounds();
for (let loc of locations) {
let pos = new google.maps.LatLng(loc.Latitude, loc.Longitude)
let pin = new google.maps.Marker(
{
position: pos,
map: map,
toilet_id: loc.ToiletID
}
)
google.maps.event.addListener(pin, "click", () => {
slideUpInfo(pin.toilet_id)
})
bounds.extend(pos)
}
map.fitBounds(bounds);
}
function mark_closest_toilets(data) {
locations = data.result.records
let bounds = new google.maps.LatLngBounds();
for (let loc of locations) {
let pos = new google.maps.LatLng(loc.Latitude, loc.Longitude)
let pin = new google.maps.Marker(
{
position: pos,
map: map,
toilet_id: loc.ToiletID
}
)
google.maps.event.addListener(pin, "click", () => {
slideUpInfo(pin.toilet_id)
})
bounds.extend(pos)
}
map.fitBounds(bounds);
}
function getCookie(name) {
var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
return v ? v[2] : null;
}
function get_closest_toilets() {
// GEOCACHING METHOD
filters = decodeURIComponent(getCookie("real_filters"))
console.log()
if (filters != "null") {
toiletFilters = JSON.parse(filters)
$.getJSON({
url: 'https://data.gov.au/api/3/action/datastore_search?callback=?',
data: {
resource_id: '54566d76-a809-4959-8622-61dc30b3114d', // the resource id
limit: 10,
//filters: '{"Unisex":"True", "Town":"Sydney","PaymentRequired":"False"}' // query for 'jones'
filters:JSON.stringify(toiletFilters)
//filters.push({key:"Unisex", value:"True"});
},
dataType: 'jsonp',
success: mark_closest_toilets,
cache: true,
// processData: false
});
} else {
$.getJSON({
url: 'https://data.gov.au/api/3/action/datastore_search?callback=?',
data: {
resource_id: '54566d76-a809-4959-8622-61dc30b3114d', // the resource id
limit: 10,
filters: `{"Male": "True", "Postcode": "${user_postcode}"}`, // query for 'jones'
offset: 0
},
dataType: 'jsonp',
success: mark_closest_toilets,
cache: true,
});
}
}
function mark_user_position() {
let user_dot = {
url: "img/dot.png",
size: new google.maps.Size(32, 32),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(15, 15)
}
new google.maps.Marker(
{
position: user_pos,
map: map,
icon: user_dot
}
)
user_circle = new google.maps.Circle({
strokeColor: "#1569C7",
fillColor: "#5FCDE4",
strokeOpacity: 0.9,
fillOpacity: 0.4,
strokeWeight: 2,
map: map,
center: user_pos,
radius: accuracy_radius
})
map.setCenter(user_pos)
get_closest_toilets()
}
function get_user_postcode(results, status) {
if (status === 'OK') {
if (results[0]) {
user_postcode = results[0].address_components.filter(word => word.types[0] == "postal_code")[0].short_name
} else {
console.log("Something went wrong. Here's what we know: GEOCODER_FAILED_TO_FIND_ADDRESS");
}
} else {
console.log("Something went wrong. Here's what we know: GEOCODER_FAILED_RETURN");
}
mark_user_position()
}
function error_geocode_user_position() {
console.error("Something went wrong. Here's what we know: GEOCODING SERVICE FAILED.")
}
function geocode_user_position(position) {
accuracy_radius = position.coords.accuracy/2
user_pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude)
let geocoder = new google.maps.Geocoder;
let geocoder_opts = {
maximumAge:600000,
timeout:5000,
enableHighAccuracy: true
}
// Use REGION: AU to bias location searches to Australia
geocoder.geocode({'location': user_pos, 'region': "au"}, get_user_postcode, error_geocode_user_position, geocoder_opts)
}
function error_user_position() {
console.error("Something went wrong: ERR_FAILED_USER_POSITION")
}
function get_user_position() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(geocode_user_position, error_user_position)
}
}
function init_map() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8,
disableDefaultUI: true,
fullscreenControl: false,
streetViewControl: false,
})
get_user_position()
}