1 function GMarkerGroup(active, markers, markersById) {
\r
2 this.active = active;
\r
3 this.markers = markers || new Array();
\r
4 this.markersById = markersById || new Object();
\r
7 GMarkerGroup.prototype = new GOverlay();
\r
9 GMarkerGroup.prototype.initialize = function(map) {
\r
13 for(var i = 0 , len = this.markers.length; i < len; i++) {
\r
14 this.map.addOverlay(this.markers[i]);
\r
16 for(var id in this.markersById){
\r
17 this.map.addOverlay(this.markersById[id]);
\r
22 //If not already done (ie if not inactive) remove all the markers from the map
\r
23 GMarkerGroup.prototype.remove = function() {
\r
27 GMarkerGroup.prototype.redraw = function(force){
\r
28 //Nothing to do : markers are already taken care of
\r
31 //Copy the data to a new Marker Group
\r
32 GMarkerGroup.prototype.copy = function() {
\r
33 var overlay = new GMarkerGroup(this.active);
\r
34 overlay.markers = this.markers; //Need to do deep copy
\r
35 overlay.markersById = this.markersById; //Need to do deep copy
\r
39 //Inactivate the Marker group and clear the internal content
\r
40 GMarkerGroup.prototype.clear = function(){
\r
41 //deactivate the map first (which removes the markers from the map)
\r
43 //Clear the internal content
\r
44 this.markers = new Array();
\r
45 this.markersById = new Object();
\r
48 //Add a marker to the GMarkerGroup ; Adds it now to the map if the GMarkerGroup is active
\r
49 GMarkerGroup.prototype.addMarker = function(marker,id){
\r
50 if(id == undefined){
\r
51 this.markers.push(marker);
\r
53 this.markersById[id] = marker;
\r
55 if(this.active && this.map != undefined ){
\r
56 this.map.addOverlay(marker);
\r
60 //Open the info window (or info window tabs) of a marker
\r
61 GMarkerGroup.prototype.showMarker = function(id){
\r
62 var marker = this.markersById[id];
\r
63 if(marker != undefined){
\r
64 GEvent.trigger(marker,"click");
\r
68 //Activate (or deactivate depending on the argument) the GMarkerGroup
\r
69 GMarkerGroup.prototype.activate = function(active){
\r
70 active = (active == undefined) ? true : active;
\r
73 if(this.map != undefined){
\r
74 for(var i = 0 , len = this.markers.length; i < len; i++){
\r
75 this.map.removeOverlay(this.markers[i])
\r
77 for(var id in this.markersById){
\r
78 this.map.removeOverlay(this.markersById[id]);
\r
81 this.active = false;
\r
85 if(this.map != undefined){
\r
86 for(var i = 0 , len = this.markers.length; i < len; i++){
\r
87 this.map.addOverlay(this.markers[i]);
\r
89 for(var id in this.markersById){
\r
90 this.map.addOverlay(this.markersById[id]);
\r
98 GMarkerGroup.prototype.centerAndZoomOnMarkers = function() {
\r
99 if(this.map != undefined){
\r
100 //merge markers and markersById
\r
101 var tmpMarkers = this.markers.slice();
\r
102 for (var id in this.markersById){
\r
103 tmpMarkers.push(this.markersById[id]);
\r
105 if(tmpMarkers.length > 0){
\r
106 this.map.centerAndZoomOnMarkers(tmpMarkers);
\r
111 //Deactivate the Group Overlay (convenience method)
\r
112 GMarkerGroup.prototype.deactivate = function(){
\r
113 this.activate(false);
\r