+function GMarkerGroup(active, markers, markersById) {\r
+ this.active = active;\r
+ this.markers = markers || new Array();\r
+ this.markersById = markersById || new Object();\r
+}\r
+\r
+GMarkerGroup.prototype = new GOverlay();\r
+\r
+GMarkerGroup.prototype.initialize = function(map) {\r
+ this.map = map;\r
+ \r
+ if(this.active){\r
+ for(var i = 0 , len = this.markers.length; i < len; i++) {\r
+ this.map.addOverlay(this.markers[i]);\r
+ }\r
+ for(var id in this.markersById){\r
+ this.map.addOverlay(this.markersById[id]);\r
+ }\r
+ }\r
+}\r
+\r
+//If not already done (ie if not inactive) remove all the markers from the map\r
+GMarkerGroup.prototype.remove = function() {\r
+ this.deactivate();\r
+}\r
+\r
+GMarkerGroup.prototype.redraw = function(force){\r
+ //Nothing to do : markers are already taken care of\r
+}\r
+\r
+//Copy the data to a new Marker Group\r
+GMarkerGroup.prototype.copy = function() {\r
+ var overlay = new GMarkerGroup(this.active);\r
+ overlay.markers = this.markers; //Need to do deep copy\r
+ overlay.markersById = this.markersById; //Need to do deep copy\r
+ return overlay;\r
+}\r
+\r
+//Inactivate the Marker group and clear the internal content\r
+GMarkerGroup.prototype.clear = function(){\r
+ //deactivate the map first (which removes the markers from the map)\r
+ this.deactivate();\r
+ //Clear the internal content\r
+ this.markers = new Array();\r
+ this.markersById = new Object();\r
+}\r
+\r
+//Add a marker to the GMarkerGroup ; Adds it now to the map if the GMarkerGroup is active\r
+GMarkerGroup.prototype.addMarker = function(marker,id){\r
+ if(id == undefined){\r
+ this.markers.push(marker);\r
+ }else{\r
+ this.markersById[id] = marker;\r
+ }\r
+ if(this.active && this.map != undefined ){\r
+ this.map.addOverlay(marker);\r
+ }\r
+}\r
+\r
+//Open the info window (or info window tabs) of a marker\r
+GMarkerGroup.prototype.showMarker = function(id){\r
+ var marker = this.markersById[id];\r
+ if(marker != undefined){\r
+ GEvent.trigger(marker,"click");\r
+ }\r
+}\r
+\r
+//Activate (or deactivate depending on the argument) the GMarkerGroup\r
+GMarkerGroup.prototype.activate = function(active){\r
+ active = (active == undefined) ? true : active;\r
+ if(!active){\r
+ if(this.active){\r
+ if(this.map != undefined){\r
+ for(var i = 0 , len = this.markers.length; i < len; i++){\r
+ this.map.removeOverlay(this.markers[i])\r
+ }\r
+ for(var id in this.markersById){\r
+ this.map.removeOverlay(this.markersById[id]);\r
+ }\r
+ }\r
+ this.active = false;\r
+ }\r
+ }else{\r
+ if(!this.active){\r
+ if(this.map != undefined){\r
+ for(var i = 0 , len = this.markers.length; i < len; i++){\r
+ this.map.addOverlay(this.markers[i]);\r
+ }\r
+ for(var id in this.markersById){\r
+ this.map.addOverlay(this.markersById[id]);\r
+ }\r
+ }\r
+ this.active = true;\r
+ }\r
+ }\r
+}\r
+\r
+GMarkerGroup.prototype.centerAndZoomOnMarkers = function() {\r
+ if(this.map != undefined){\r
+ //merge markers and markersById\r
+ var tmpMarkers = this.markers.slice();\r
+ for (var id in this.markersById){\r
+ tmpMarkers.push(this.markersById[id]);\r
+ }\r
+ if(tmpMarkers.length > 0){\r
+ this.map.centerAndZoomOnMarkers(tmpMarkers);\r
+ } \r
+ }\r
+} \r
+\r
+//Deactivate the Group Overlay (convenience method)\r
+GMarkerGroup.prototype.deactivate = function(){\r
+ this.activate(false);\r
+}\r