]> projects.mako.cc - selectricity-live/blob - public/javascripts/markerGroup.js
removed old debugger code that was accidentally committed
[selectricity-live] / public / javascripts / markerGroup.js
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
5 }\r
6 \r
7 GMarkerGroup.prototype = new GOverlay();\r
8 \r
9 GMarkerGroup.prototype.initialize = function(map) {\r
10     this.map = map;\r
11     \r
12     if(this.active){\r
13         for(var i = 0 , len = this.markers.length; i < len; i++) {\r
14             this.map.addOverlay(this.markers[i]);\r
15         }\r
16         for(var id in this.markersById){\r
17             this.map.addOverlay(this.markersById[id]);\r
18         }\r
19     }\r
20 }\r
21 \r
22 //If not already done (ie if not inactive) remove all the markers from the map\r
23 GMarkerGroup.prototype.remove = function() {\r
24     this.deactivate();\r
25 }\r
26 \r
27 GMarkerGroup.prototype.redraw = function(force){\r
28     //Nothing to do : markers are already taken care of\r
29 }\r
30 \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
36     return overlay;\r
37 }\r
38 \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
42     this.deactivate();\r
43     //Clear the internal content\r
44     this.markers = new Array();\r
45     this.markersById = new Object();\r
46 }\r
47 \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
52     }else{\r
53         this.markersById[id] = marker;\r
54     }\r
55     if(this.active && this.map != undefined ){\r
56         this.map.addOverlay(marker);\r
57     }\r
58 }\r
59 \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
65     }\r
66 }\r
67 \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
71     if(!active){\r
72         if(this.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
76                 }\r
77                 for(var id in this.markersById){\r
78                     this.map.removeOverlay(this.markersById[id]);\r
79                 }\r
80             }\r
81             this.active = false;\r
82         }\r
83     }else{\r
84         if(!this.active){\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
88                 }\r
89                 for(var id in this.markersById){\r
90                     this.map.addOverlay(this.markersById[id]);\r
91                 }\r
92             }\r
93             this.active = true;\r
94         }\r
95     }\r
96 }\r
97 \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
104         }\r
105         if(tmpMarkers.length > 0){\r
106             this.map.centerAndZoomOnMarkers(tmpMarkers);\r
107         } \r
108     }\r
109 }       \r
110 \r
111 //Deactivate the Group Overlay (convenience method)\r
112 GMarkerGroup.prototype.deactivate = function(){\r
113     this.activate(false);\r
114 }\r

Benjamin Mako Hill || Want to submit a patch?