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

Commit

Permalink
Allow specifying info windows and custom icons
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmeurer committed Feb 26, 2013
1 parent 3d2c384 commit 8440f11
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/angular-google-maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
_handlers = [], // event handlers
_windows = [], // InfoWindow objects
o = angular.extend({}, _defaults, opts),
that = this;
that = this,
currentInfoWindow = null;

this.center = opts.center;
this.zoom = o.zoom;
Expand Down Expand Up @@ -178,7 +179,7 @@
});
};

this.addMarker = function (lat, lng, label, url,
this.addMarker = function (lat, lng, icon, infoWindowContent, label, url,
thumbnail) {

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

var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
map: _instance
map: _instance,
icon: icon
});

if (label) {
Expand All @@ -197,6 +199,20 @@
if (url) {

}

if (infoWindowContent != null) {
var infoWindow = new google.maps.InfoWindow({
content: infoWindowContent
});

google.maps.event.addListener(marker, 'click', function() {
if (currentInfoWindow != null) {
currentInfoWindow.close();
}
infoWindow.open(_instance, marker);
currentInfoWindow = infoWindow;
});
}

// Cache marker
_markers.unshift(marker);
Expand All @@ -206,6 +222,8 @@
"lat": lat,
"lng": lng,
"draggable": false,
"icon": icon,
"infoWindowContent": infoWindowContent,
"label": label,
"url": url,
"thumbnail": thumbnail
Expand Down Expand Up @@ -438,7 +456,7 @@

angular.forEach(newValue, function (v, i) {
if (!_m.hasMarker(v.latitude, v.longitude)) {
_m.addMarker(v.latitude, v.longitude);
_m.addMarker(v.latitude, v.longitude, v.icon, v.infoWindow);
}
});

Expand Down

5 comments on commit 8440f11

@adrianboimvaser
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The info window feature is undocumented. Would you kindly explain how to use it?

@manuelmeurer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add a infoWindow key to one (or some or all) objects in your markers array and it will automatically create an info window and attach it to that marker (with the click event). The value for infoWindow should be the text or HTML that appears in the info window.

@adrianboimvaser
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@adrianboimvaser
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know how to make the HTML in the info window AngularJS controller-aware (or whatever)?

@manuelmeurer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope... as you see in the code, the HTML is passed directly to new google.maps.InfoWindow as the content.

Please sign in to comment.