Administrator
2022-09-14 58d006e05dcf2a20d0ec5367dd03d66a61db6849
提交 | 用户 | 时间
58d006 1 GMaps.prototype.drawPolyline = function(options) {
A 2   var path = [],
3       points = options.path;
4
5   if (points.length) {
6     if (points[0][0] === undefined) {
7       path = points;
8     }
9     else {
10       for (var i=0, latlng; latlng=points[i]; i++) {
11         path.push(new google.maps.LatLng(latlng[0], latlng[1]));
12       }
13     }
14   }
15
16   var polyline_options = {
17     map: this.map,
18     path: path,
19     strokeColor: options.strokeColor,
20     strokeOpacity: options.strokeOpacity,
21     strokeWeight: options.strokeWeight,
22     geodesic: options.geodesic,
23     clickable: true,
24     editable: false,
25     visible: true
26   };
27
28   if (options.hasOwnProperty("clickable")) {
29     polyline_options.clickable = options.clickable;
30   }
31
32   if (options.hasOwnProperty("editable")) {
33     polyline_options.editable = options.editable;
34   }
35
36   if (options.hasOwnProperty("icons")) {
37     polyline_options.icons = options.icons;
38   }
39
40   if (options.hasOwnProperty("zIndex")) {
41     polyline_options.zIndex = options.zIndex;
42   }
43
44   var polyline = new google.maps.Polyline(polyline_options);
45
46   var polyline_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
47
48   for (var ev = 0; ev < polyline_events.length; ev++) {
49     (function(object, name) {
50       if (options[name]) {
51         google.maps.event.addListener(object, name, function(e){
52           options[name].apply(this, [e]);
53         });
54       }
55     })(polyline, polyline_events[ev]);
56   }
57
58   this.polylines.push(polyline);
59
60   GMaps.fire('polyline_added', polyline, this);
61
62   return polyline;
63 };
64
65 GMaps.prototype.removePolyline = function(polyline) {
66   for (var i = 0; i < this.polylines.length; i++) {
67     if (this.polylines[i] === polyline) {
68       this.polylines[i].setMap(null);
69       this.polylines.splice(i, 1);
70
71       GMaps.fire('polyline_removed', polyline, this);
72
73       break;
74     }
75   }
76 };
77
78 GMaps.prototype.removePolylines = function() {
79   for (var i = 0, item; item = this.polylines[i]; i++) {
80     item.setMap(null);
81   }
82
83   this.polylines = [];
84 };
85
86 GMaps.prototype.drawCircle = function(options) {
87   options =  extend_object({
88     map: this.map,
89     center: new google.maps.LatLng(options.lat, options.lng)
90   }, options);
91
92   delete options.lat;
93   delete options.lng;
94
95   var polygon = new google.maps.Circle(options),
96       polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
97
98   for (var ev = 0; ev < polygon_events.length; ev++) {
99     (function(object, name) {
100       if (options[name]) {
101         google.maps.event.addListener(object, name, function(e){
102           options[name].apply(this, [e]);
103         });
104       }
105     })(polygon, polygon_events[ev]);
106   }
107
108   this.polygons.push(polygon);
109
110   return polygon;
111 };
112
113 GMaps.prototype.drawRectangle = function(options) {
114   options = extend_object({
115     map: this.map
116   }, options);
117
118   var latLngBounds = new google.maps.LatLngBounds(
119     new google.maps.LatLng(options.bounds[0][0], options.bounds[0][1]),
120     new google.maps.LatLng(options.bounds[1][0], options.bounds[1][1])
121   );
122
123   options.bounds = latLngBounds;
124
125   var polygon = new google.maps.Rectangle(options),
126       polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
127
128   for (var ev = 0; ev < polygon_events.length; ev++) {
129     (function(object, name) {
130       if (options[name]) {
131         google.maps.event.addListener(object, name, function(e){
132           options[name].apply(this, [e]);
133         });
134       }
135     })(polygon, polygon_events[ev]);
136   }
137
138   this.polygons.push(polygon);
139
140   return polygon;
141 };
142
143 GMaps.prototype.drawPolygon = function(options) {
144   var useGeoJSON = false;
145
146   if(options.hasOwnProperty("useGeoJSON")) {
147     useGeoJSON = options.useGeoJSON;
148   }
149
150   delete options.useGeoJSON;
151
152   options = extend_object({
153     map: this.map
154   }, options);
155
156   if (useGeoJSON == false) {
157     options.paths = [options.paths.slice(0)];
158   }
159
160   if (options.paths.length > 0) {
161     if (options.paths[0].length > 0) {
162       options.paths = array_flat(array_map(options.paths, arrayToLatLng, useGeoJSON));
163     }
164   }
165
166   var polygon = new google.maps.Polygon(options),
167       polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
168
169   for (var ev = 0; ev < polygon_events.length; ev++) {
170     (function(object, name) {
171       if (options[name]) {
172         google.maps.event.addListener(object, name, function(e){
173           options[name].apply(this, [e]);
174         });
175       }
176     })(polygon, polygon_events[ev]);
177   }
178
179   this.polygons.push(polygon);
180
181   GMaps.fire('polygon_added', polygon, this);
182
183   return polygon;
184 };
185
186 GMaps.prototype.removePolygon = function(polygon) {
187   for (var i = 0; i < this.polygons.length; i++) {
188     if (this.polygons[i] === polygon) {
189       this.polygons[i].setMap(null);
190       this.polygons.splice(i, 1);
191
192       GMaps.fire('polygon_removed', polygon, this);
193
194       break;
195     }
196   }
197 };
198
199 GMaps.prototype.removePolygons = function() {
200   for (var i = 0, item; item = this.polygons[i]; i++) {
201     item.setMap(null);
202   }
203
204   this.polygons = [];
205 };