Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Commit 8440f11

Browse files
committed
Allow specifying info windows and custom icons
1 parent 3d2c384 commit 8440f11

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/angular-google-maps.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
_handlers = [], // event handlers
6868
_windows = [], // InfoWindow objects
6969
o = angular.extend({}, _defaults, opts),
70-
that = this;
70+
that = this,
71+
currentInfoWindow = null;
7172

7273
this.center = opts.center;
7374
this.zoom = o.zoom;
@@ -178,7 +179,7 @@
178179
});
179180
};
180181

181-
this.addMarker = function (lat, lng, label, url,
182+
this.addMarker = function (lat, lng, icon, infoWindowContent, label, url,
182183
thumbnail) {
183184

184185
if (that.findMarker(lat, lng) != null) {
@@ -187,7 +188,8 @@
187188

188189
var marker = new google.maps.Marker({
189190
position: new google.maps.LatLng(lat, lng),
190-
map: _instance
191+
map: _instance,
192+
icon: icon
191193
});
192194

193195
if (label) {
@@ -197,6 +199,20 @@
197199
if (url) {
198200

199201
}
202+
203+
if (infoWindowContent != null) {
204+
var infoWindow = new google.maps.InfoWindow({
205+
content: infoWindowContent
206+
});
207+
208+
google.maps.event.addListener(marker, 'click', function() {
209+
if (currentInfoWindow != null) {
210+
currentInfoWindow.close();
211+
}
212+
infoWindow.open(_instance, marker);
213+
currentInfoWindow = infoWindow;
214+
});
215+
}
200216

201217
// Cache marker
202218
_markers.unshift(marker);
@@ -206,6 +222,8 @@
206222
"lat": lat,
207223
"lng": lng,
208224
"draggable": false,
225+
"icon": icon,
226+
"infoWindowContent": infoWindowContent,
209227
"label": label,
210228
"url": url,
211229
"thumbnail": thumbnail
@@ -438,7 +456,7 @@
438456

439457
angular.forEach(newValue, function (v, i) {
440458
if (!_m.hasMarker(v.latitude, v.longitude)) {
441-
_m.addMarker(v.latitude, v.longitude);
459+
_m.addMarker(v.latitude, v.longitude, v.icon, v.infoWindow);
442460
}
443461
});
444462

0 commit comments

Comments
 (0)