-
Notifications
You must be signed in to change notification settings - Fork 382
Adding an id to markers and access them later
Jérémy FRERE edited this page Apr 30, 2014
·
10 revisions
markers = ... // Fetch markers
Gmaps.store.markers = markers.map(function(m) {
marker = handler.addMarker(m);
marker.serviceObject.set('id', m.id); // You can add other attributes using set
return marker;
}
handler.bounds.extendWith(Gmaps.store.markers);
handler.fitMapToBounds();
Gmaps.store.markers.filter(function(m) { return m.serviceObject.id == id; })[0]
For instance, here's how to define a function selectMarker(id)
that adds a bouncing animation and pans to a specific marker
Gmaps.selectMarker = function(id) {
$.each(Gmaps.store.markers, function() {
if (this.serviceObject.id == id) {
this.panTo();
this.serviceObject.setAnimation(google.maps.Animation.BOUNCE);
}
else this.serviceObject.setAnimation(null);
}
}
Usage
Gmaps.selectMarker(1);