forked from phillyrb/phillyrb.org
-
Notifications
You must be signed in to change notification settings - Fork 1
/
meetup_map_embedder.js
65 lines (54 loc) · 1.48 KB
/
meetup_map_embedder.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
define('meetup_map_embedder', [
'jquery'
], function (
$
) {
var Map = function (event) {
this.initialize(event);
};
Map.prototype.initialize = function (event) {
this.event = event;
this.geocoder = new google.maps.Geocoder();
this.geocodeAndMap(this.event.address);
};
Map.prototype.geocodeAndMap = function (address) {
var self = this;
self.geocoder.geocode({
'address': address
}, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
self.location = results[0].geometry.location;
self._createMap();
}
});
};
Map.prototype._createMap = function () {
var settings = {
mapId: 'map',
zoom: 14,
center: this.location,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
this.map = new google.maps.Map(document.getElementById(settings.mapId), settings);
this._addMarker();
this._addInfoWindow();
};
Map.prototype._addMarker = function () {
this.marker = new google.maps.Marker({
position: this.location,
map: this.map,
title: 'Hello World!'
});
};
Map.prototype._addInfoWindow = function () {
this.infoWindow = new google.maps.InfoWindow({
content: this._infoWindowContent()
});
this.infoWindow.open(this.map, this.marker);
};
Map.prototype._infoWindowContent = function () {
var template = $('#event-map-tmpl').html();
return _.template(template, { event: this.event });
};
return Map;
});