-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.js
executable file
·114 lines (99 loc) · 2.64 KB
/
events.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
(function($, google) {
var map;
var places;
$(function() { // onload handler
var melbourne = new google.maps.LatLng(-37.813611, 144.963056);
var mapOptions = {
zoom: 12,
center: melbourne,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map($("#map_canvas")[0], mapOptions);
places = loadPlaces();
drawPlaces(places, map);
$("form").submit(function(submitEvent) {
submitEvent.preventDefault();
addPlaceBasedOnForm(this);
drawPlaces(places, map);
});
});
function addPlaceBasedOnForm(formElement) {
var formSelector = $(formElement);
var lat = parseFloat(formSelector.find("[name=lat]").val());
var lng = parseFloat(formSelector.find("[name=lng]").val());
var newPlace = {
"title": formSelector.find("[name=name]").val(),
"description": formSelector.find("[name=description]").val(),
"thumbnail": "gvrv.jpg",
"position": [ lat, lng ]
}
places.push(newPlace)
}
function loadPlaces() {
return [
{
"title": "Woodfire BBQ - Meet other students from Honk Kong!",
"description": "Come join the Hong Kong students association... for an evening of socialising!",
"thumbnail": "gvrv.jpg",
"position": [
-37.818078,
144.966811
]
},
{
"title": "Let's play chess",
"description": "Have a passion for chess? Can you beat the clock? Join our club!",
"thumbnail": "andre.jpg",
"position": [
-37.818358,
144.952417
]
}
];
}
function drawPlaces(places, map) {
var currentPlace = null;
var info = $('#placeDetails');
var icons = {
//'train': 'http://blogs.sitepoint.com/wp-content/uploads/2011/04/train.png',
'train': 'images/party.png',
'train-selected': 'images/party-selected.png'
}
//$.getJSON('places.json', function(places) {
$(places).each(function() {
var place = this;
var marker = new google.maps.Marker({
position: new google.maps.LatLng(place.position[0], place.position[1]),
map: map,
title: place.title,
icon: icons['train']
});
google.maps.event.addListener(marker, 'click', function() {
var hidingMarker = currentPlace;
var slideIn = function(marker) {
$('h1', info).text(place.title);
$('p', info).text(place.description);
$('img', info).attr("src","images/"+place.thumbnail);
info.animate({right: '0'});
}
marker.setIcon(icons['train-selected']);
if (currentPlace) {
currentPlace.setIcon(icons['train']);
info.animate(
{ right: '-320px' },
{ complete: function() {
if (hidingMarker != marker) {
slideIn(marker);
} else {
currentPlace = null;
}
}}
);
} else {
slideIn(marker);
}
currentPlace = marker;
});
});
}
})(jQuery, google);