This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
placard.js
69 lines (55 loc) · 1.59 KB
/
placard.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
(function(window, google) {
'use strict';
var Placard = {};
Placard.Map = function(el, config) {
this.el = el;
this.config = config;
this._map = this._createMap();
};
Placard.Map.prototype._createMap = function() {
return new google.maps.Map(document.getElementById(this.el), this.config);
};
Placard.Map.prototype.addPoint = function(point) {
var newPoint = new Placard.Point(point, this);
newPoint.addToMap(this);
return this;
};
Placard.Point = function(point) {
this.lat = point.lat;
this.lng = point.lng;
this.info = point.info;
this.window = this._createWindow();
};
Placard.Point.prototype.addToMap = function(map) {
var self = this;
var marker = new google.maps.Marker({
position: new google.maps.LatLng(this.lat, this.lng),
map: map._map
});
if (this.info) {
google.maps.event.addListener(marker, 'click', function() {
self.window._infoWindow.open(map._map, marker);
});
}
return this;
};
Placard.Point.prototype._createWindow = function() {
if (this.info) {
return new Placard.Window(this.info);
}
};
Placard.Window = function(info) {
this.title = info.title;
this.text = info.text;
this._infoWindow = this.createInfoWindow();
};
Placard.Window.prototype.createInfoWindow = function() {
return new google.maps.InfoWindow({
content: '<div id="content">' +
'<h1>' + this.title + '</h1>' +
'<p>' + this.text + '</p>' +
'</div>'
});
};
window.Placard = Placard;
})(window, google);