gmapsjs 0.2.4 → 0.2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/assets/javascripts/gmapsjs/gmapsjs.js +1011 -979
- data/lib/gmapsjs/version.rb +1 -1
- metadata +3 -3
@@ -6,1240 +6,1272 @@
|
|
6
6
|
* Released under the MIT License.
|
7
7
|
*/
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
var
|
15
|
-
|
16
|
-
ele
|
17
|
-
|
18
|
-
|
9
|
+
if(window.google && window.google.maps){
|
10
|
+
|
11
|
+
var GMaps = (function(global) {
|
12
|
+
"use strict";
|
13
|
+
|
14
|
+
var doc = document;
|
15
|
+
var getElementById = function(id, context) {
|
16
|
+
var ele
|
17
|
+
if('jQuery' in global && context){
|
18
|
+
ele = $("#"+id.replace('#', ''), context)[0]
|
19
|
+
}else{
|
20
|
+
ele = doc.getElementById(id.replace('#', ''));
|
21
|
+
};
|
22
|
+
return ele;
|
19
23
|
};
|
20
|
-
return ele;
|
21
|
-
};
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
if(typeof(options.div)=='string'){
|
28
|
-
this.div = getElementById(options.div, options.context);
|
29
|
-
}else{this.div = options.div;};
|
30
|
-
this.div.style.width = this.div.clientWidth || options.width;
|
31
|
-
this.div.style.height = this.div.clientHeight || options.height;
|
32
|
-
|
33
|
-
this.controls = [];
|
34
|
-
this.overlays = [];
|
35
|
-
this.layers = [];
|
36
|
-
this.markers = [];
|
37
|
-
this.polylines = [];
|
38
|
-
this.routes = [];
|
39
|
-
this.polygons = [];
|
40
|
-
this.infoWindow = null;
|
41
|
-
this.overlay_div = null;
|
42
|
-
this.zoom = options.zoom || 15;
|
43
|
-
|
44
|
-
//'Hybrid', 'Roadmap', 'Satellite' or 'Terrain'
|
45
|
-
var mapType;
|
46
|
-
|
47
|
-
if (options.mapType) {
|
48
|
-
mapType = google.maps.MapTypeId[options.mapType.toUpperCase()];
|
49
|
-
}
|
50
|
-
else {
|
51
|
-
mapType = google.maps.MapTypeId.ROADMAP;
|
52
|
-
}
|
25
|
+
var GMaps = function(options) {
|
26
|
+
var self = this;
|
27
|
+
window.context_menu = {};
|
53
28
|
|
54
|
-
|
29
|
+
if(typeof(options.div)=='string'){
|
30
|
+
this.div = getElementById(options.div, options.context);
|
31
|
+
}else{this.div = options.div;};
|
32
|
+
this.div.style.width = this.div.clientWidth || options.width;
|
33
|
+
this.div.style.height = this.div.clientHeight || options.height;
|
55
34
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
35
|
+
this.controls = [];
|
36
|
+
this.overlays = [];
|
37
|
+
this.layers = [];
|
38
|
+
this.markers = [];
|
39
|
+
this.polylines = [];
|
40
|
+
this.routes = [];
|
41
|
+
this.polygons = [];
|
42
|
+
this.infoWindow = null;
|
43
|
+
this.overlay_div = null;
|
44
|
+
this.zoom = options.zoom || 15;
|
62
45
|
|
63
|
-
|
64
|
-
|
65
|
-
position: 'TOP_LEFT'
|
66
|
-
};
|
46
|
+
//'Hybrid', 'Roadmap', 'Satellite' or 'Terrain'
|
47
|
+
var mapType;
|
67
48
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
streetViewControl = options.streetViewControl || true,
|
75
|
-
overviewMapControl = overviewMapControl || true;
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
var map_base_options = {
|
80
|
-
zoom: this.zoom,
|
81
|
-
center: map_center,
|
82
|
-
mapTypeId: mapType,
|
83
|
-
panControl: panControl,
|
84
|
-
zoomControl: zoomControl,
|
85
|
-
zoomControlOptions: {
|
86
|
-
style: google.maps.ZoomControlStyle[zoomControlStyle], // DEFAULT LARGE SMALL
|
87
|
-
position: google.maps.ControlPosition[zoomControlPosition]
|
88
|
-
},
|
89
|
-
mapTypeControl: mapTypeControl,
|
90
|
-
scaleControl: scaleControl,
|
91
|
-
streetViewControl: streetViewControl,
|
92
|
-
overviewMapControl: overviewMapControl
|
93
|
-
};
|
49
|
+
if (options.mapType) {
|
50
|
+
mapType = google.maps.MapTypeId[options.mapType.toUpperCase()];
|
51
|
+
}
|
52
|
+
else {
|
53
|
+
mapType = google.maps.MapTypeId.ROADMAP;
|
54
|
+
}
|
94
55
|
|
95
|
-
|
56
|
+
var map_center = new google.maps.LatLng(options.lat, options.lng);
|
96
57
|
|
97
|
-
|
58
|
+
delete options.div;
|
59
|
+
delete options.lat;
|
60
|
+
delete options.lng;
|
61
|
+
delete options.mapType;
|
62
|
+
delete options.width;
|
63
|
+
delete options.height;
|
98
64
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
for (var i in options){
|
104
|
-
if (options.hasOwnProperty(i)){
|
105
|
-
var option = options[i];
|
106
|
-
html += '<li><a id="' + control + '_' + i + '" href="#">' +
|
107
|
-
option.title + '</a></li>';
|
108
|
-
}
|
109
|
-
}
|
110
|
-
if(!getElementById('gmaps_context_menu')) return;
|
111
|
-
var context_menu_element = getElementById('gmaps_context_menu');
|
112
|
-
context_menu_element.innerHTML = html;
|
65
|
+
var zoomControlOpt = options.zoomControlOpt || {
|
66
|
+
style: 'DEFAULT',
|
67
|
+
position: 'TOP_LEFT'
|
68
|
+
};
|
113
69
|
|
114
|
-
|
70
|
+
var zoomControl = options.zoomControl || true,
|
71
|
+
zoomControlStyle = zoomControlOpt.style || 'DEFAULT',
|
72
|
+
zoomControlPosition = zoomControlOpt.position || 'TOP_LEFT',
|
73
|
+
panControl = options.panControl || true,
|
74
|
+
mapTypeControl = options.mapTypeControl || true,
|
75
|
+
scaleControl = options.scaleControl || true,
|
76
|
+
streetViewControl = options.streetViewControl || true,
|
77
|
+
overviewMapControl = overviewMapControl || true;
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
var map_base_options = {
|
82
|
+
zoom: this.zoom,
|
83
|
+
center: map_center,
|
84
|
+
mapTypeId: mapType,
|
85
|
+
panControl: panControl,
|
86
|
+
zoomControl: zoomControl,
|
87
|
+
zoomControlOptions: {
|
88
|
+
style: google.maps.ZoomControlStyle[zoomControlStyle], // DEFAULT LARGE SMALL
|
89
|
+
position: google.maps.ControlPosition[zoomControlPosition]
|
90
|
+
},
|
91
|
+
mapTypeControl: mapTypeControl,
|
92
|
+
scaleControl: scaleControl,
|
93
|
+
streetViewControl: streetViewControl,
|
94
|
+
overviewMapControl: overviewMapControl
|
95
|
+
};
|
115
96
|
|
116
|
-
|
97
|
+
var map_options = extend_object(map_base_options, options);
|
117
98
|
|
118
|
-
|
119
|
-
var context_menu_item = context_menu_items[i];
|
99
|
+
this.map = new google.maps.Map(this.div, map_options);
|
120
100
|
|
121
|
-
|
122
|
-
|
101
|
+
// Context menus
|
102
|
+
var buildContextMenuHTML = function(control, e) {
|
103
|
+
var html = '';
|
104
|
+
var options = window.context_menu[control];
|
105
|
+
for (var i in options){
|
106
|
+
if (options.hasOwnProperty(i)){
|
107
|
+
var option = options[i];
|
108
|
+
html += '<li><a id="' + control + '_' + i + '" href="#">' +
|
109
|
+
option.title + '</a></li>';
|
110
|
+
}
|
111
|
+
}
|
112
|
+
if(!getElementById('gmaps_context_menu')) return;
|
113
|
+
var context_menu_element = getElementById('gmaps_context_menu');
|
114
|
+
context_menu_element.innerHTML = html;
|
123
115
|
|
124
|
-
|
125
|
-
self.hideContextMenu();
|
126
|
-
};
|
116
|
+
var context_menu_items = context_menu_element.getElementsByTagName('a');
|
127
117
|
|
128
|
-
|
129
|
-
google.maps.event.addDomListenerOnce(context_menu_item, 'click', assign_menu_item_action, false);
|
130
|
-
}
|
118
|
+
var context_menu_items_count = context_menu_items.length;
|
131
119
|
|
132
|
-
|
133
|
-
|
120
|
+
for(var i=0;i<context_menu_items_count;i++){
|
121
|
+
var context_menu_item = context_menu_items[i];
|
134
122
|
|
135
|
-
|
136
|
-
|
123
|
+
var assign_menu_item_action = function(ev){
|
124
|
+
ev.preventDefault();
|
137
125
|
|
138
|
-
|
139
|
-
|
126
|
+
options[this.id.replace(control + '_', '')].action.call(self, e);
|
127
|
+
self.hideContextMenu();
|
128
|
+
};
|
140
129
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
var overlay = new google.maps.OverlayView();
|
145
|
-
overlay.setMap(self.map);
|
146
|
-
overlay.draw = function() {
|
147
|
-
var projection = overlay.getProjection();
|
148
|
-
var position = e.marker.getPosition();
|
149
|
-
e.pixel = projection.fromLatLngToContainerPixel(position);
|
130
|
+
google.maps.event.clearListeners(context_menu_item, 'click');
|
131
|
+
google.maps.event.addDomListenerOnce(context_menu_item, 'click', assign_menu_item_action, false);
|
132
|
+
}
|
150
133
|
|
151
|
-
|
152
|
-
|
153
|
-
}
|
154
|
-
else {
|
155
|
-
buildContextMenuHTML(control, e);
|
156
|
-
}
|
157
|
-
};
|
134
|
+
var left = self.div.offsetLeft + e.pixel.x - 15;
|
135
|
+
var top = self.div.offsetTop + e.pixel.y - 15;
|
158
136
|
|
159
|
-
|
160
|
-
|
161
|
-
for (var i in options.options){
|
162
|
-
if (options.options.hasOwnProperty(i)){
|
163
|
-
var option = options.options[i];
|
164
|
-
window.context_menu[options.control][option.name] = {
|
165
|
-
title: option.title,
|
166
|
-
action: option.action
|
167
|
-
};
|
168
|
-
}
|
169
|
-
}
|
170
|
-
var ul = doc.createElement('ul');
|
171
|
-
ul.id = 'gmaps_context_menu';
|
172
|
-
ul.style.display = 'none';
|
173
|
-
ul.style.position = 'absolute';
|
174
|
-
ul.style.minWidth = '100px';
|
175
|
-
ul.style.background = 'white';
|
176
|
-
ul.style.listStyle = 'none';
|
177
|
-
ul.style.padding = '8px';
|
178
|
-
ul.style.boxShadow = '2px 2px 6px #ccc';
|
179
|
-
|
180
|
-
doc.body.appendChild(ul);
|
181
|
-
|
182
|
-
var context_menu_element = getElementById('gmaps_context_menu');
|
183
|
-
|
184
|
-
google.maps.event.addDomListener(context_menu_element, 'mouseout', function(ev) {
|
185
|
-
if(!ev.relatedTarget || !this.contains(ev.relatedTarget)){
|
186
|
-
window.setTimeout(function(){
|
187
|
-
context_menu_element.style.display = 'none';
|
188
|
-
}, 400);
|
189
|
-
}
|
190
|
-
}, false);
|
191
|
-
};
|
137
|
+
context_menu_element.style.left = left + "px";
|
138
|
+
context_menu_element.style.top = top + "px";
|
192
139
|
|
193
|
-
|
194
|
-
|
195
|
-
if(context_menu_element)
|
196
|
-
context_menu_element.style.display = 'none';
|
197
|
-
};
|
140
|
+
context_menu_element.style.display = 'block';
|
141
|
+
};
|
198
142
|
|
199
|
-
|
143
|
+
var buildContextMenu = function(control, e) {
|
144
|
+
if (control === 'marker') {
|
145
|
+
e.pixel = {};
|
146
|
+
var overlay = new google.maps.OverlayView();
|
147
|
+
overlay.setMap(self.map);
|
148
|
+
overlay.draw = function() {
|
149
|
+
var projection = overlay.getProjection();
|
150
|
+
var position = e.marker.getPosition();
|
151
|
+
e.pixel = projection.fromLatLngToContainerPixel(position);
|
152
|
+
|
153
|
+
buildContextMenuHTML(control, e);
|
154
|
+
};
|
155
|
+
}
|
156
|
+
else {
|
157
|
+
buildContextMenuHTML(control, e);
|
158
|
+
}
|
159
|
+
};
|
200
160
|
|
201
|
-
|
202
|
-
|
161
|
+
this.setContextMenu = function(options) {
|
162
|
+
window.context_menu[options.control] = {};
|
163
|
+
for (var i in options.options){
|
164
|
+
if (options.options.hasOwnProperty(i)){
|
165
|
+
var option = options.options[i];
|
166
|
+
window.context_menu[options.control][option.name] = {
|
167
|
+
title: option.title,
|
168
|
+
action: option.action
|
169
|
+
};
|
170
|
+
}
|
171
|
+
}
|
172
|
+
var ul = doc.createElement('ul');
|
173
|
+
ul.id = 'gmaps_context_menu';
|
174
|
+
ul.style.display = 'none';
|
175
|
+
ul.style.position = 'absolute';
|
176
|
+
ul.style.minWidth = '100px';
|
177
|
+
ul.style.background = 'white';
|
178
|
+
ul.style.listStyle = 'none';
|
179
|
+
ul.style.padding = '8px';
|
180
|
+
ul.style.boxShadow = '2px 2px 6px #ccc';
|
181
|
+
|
182
|
+
doc.body.appendChild(ul);
|
203
183
|
|
204
|
-
|
205
|
-
(function(object, name) {
|
206
|
-
google.maps.event.addListener(object, name, function(e){
|
207
|
-
if (options[name])
|
208
|
-
options[name].apply(this, [e]);
|
184
|
+
var context_menu_element = getElementById('gmaps_context_menu');
|
209
185
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
186
|
+
google.maps.event.addDomListener(context_menu_element, 'mouseout', function(ev) {
|
187
|
+
if(!ev.relatedTarget || !this.contains(ev.relatedTarget)){
|
188
|
+
window.setTimeout(function(){
|
189
|
+
context_menu_element.style.display = 'none';
|
190
|
+
}, 400);
|
191
|
+
}
|
192
|
+
}, false);
|
193
|
+
};
|
214
194
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
});
|
221
|
-
})(this.map, events_that_doesnt_hide_context_menu[ev]);
|
222
|
-
}
|
195
|
+
this.hideContextMenu = function() {
|
196
|
+
var context_menu_element = getElementById('gmaps_context_menu');
|
197
|
+
if(context_menu_element)
|
198
|
+
context_menu_element.style.display = 'none';
|
199
|
+
};
|
223
200
|
|
224
|
-
|
225
|
-
if (options.rightclick) {
|
226
|
-
options.rightclick.apply(this, [e]);
|
227
|
-
}
|
201
|
+
//Events
|
228
202
|
|
229
|
-
|
230
|
-
|
203
|
+
var events_that_hide_context_menu = ['bounds_changed', 'center_changed', 'click', 'dblclick', 'drag', 'dragend', 'dragstart', 'idle', 'maptypeid_changed', 'projection_changed', 'resize', 'tilesloaded', 'zoom_changed'];
|
204
|
+
var events_that_doesnt_hide_context_menu = ['mousemove', 'mouseout', 'mouseover'];
|
231
205
|
|
232
|
-
|
233
|
-
|
234
|
-
|
206
|
+
for (var ev = 0; ev < events_that_hide_context_menu.length; ev++) {
|
207
|
+
(function(object, name) {
|
208
|
+
google.maps.event.addListener(object, name, function(e){
|
209
|
+
if (options[name])
|
210
|
+
options[name].apply(this, [e]);
|
235
211
|
|
236
|
-
|
237
|
-
|
238
|
-
|
212
|
+
self.hideContextMenu();
|
213
|
+
});
|
214
|
+
})(this.map, events_that_hide_context_menu[ev]);
|
215
|
+
}
|
239
216
|
|
240
|
-
for(var
|
241
|
-
|
217
|
+
for (var ev = 0; ev < events_that_doesnt_hide_context_menu.length; ev++) {
|
218
|
+
(function(object, name) {
|
219
|
+
google.maps.event.addListener(object, name, function(e){
|
220
|
+
if (options[name])
|
221
|
+
options[name].apply(this, [e]);
|
222
|
+
});
|
223
|
+
})(this.map, events_that_doesnt_hide_context_menu[ev]);
|
242
224
|
}
|
243
225
|
|
244
|
-
this.
|
245
|
-
|
226
|
+
google.maps.event.addListener(this.map, 'rightclick', function(e) {
|
227
|
+
if (options.rightclick) {
|
228
|
+
options.rightclick.apply(this, [e]);
|
229
|
+
}
|
246
230
|
|
247
|
-
|
248
|
-
|
249
|
-
var bounds = new google.maps.LatLngBounds();
|
231
|
+
buildContextMenu('map', e);
|
232
|
+
});
|
250
233
|
|
251
|
-
|
252
|
-
|
253
|
-
}
|
234
|
+
this.refresh = function() {
|
235
|
+
google.maps.event.trigger(this.map, 'resize');
|
236
|
+
};
|
254
237
|
|
255
|
-
this.
|
256
|
-
|
238
|
+
this.fitZoom = function() {
|
239
|
+
var latLngs = [];
|
240
|
+
var markers_length = this.markers.length;
|
257
241
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
if (callback) {
|
262
|
-
callback();
|
263
|
-
}
|
264
|
-
};
|
242
|
+
for(var i=0; i < markers_length; i++) {
|
243
|
+
latLngs.push(this.markers[i].getPosition());
|
244
|
+
}
|
265
245
|
|
266
|
-
|
267
|
-
|
268
|
-
};
|
246
|
+
this.fitBounds(latLngs);
|
247
|
+
};
|
269
248
|
|
270
|
-
|
271
|
-
|
272
|
-
|
249
|
+
this.fitBounds = function(latLngs) {
|
250
|
+
var total = latLngs.length;
|
251
|
+
var bounds = new google.maps.LatLngBounds();
|
273
252
|
|
274
|
-
|
275
|
-
|
276
|
-
|
253
|
+
for(var i=0; i < total; i++) {
|
254
|
+
bounds.extend(latLngs[i]);
|
255
|
+
}
|
277
256
|
|
278
|
-
|
279
|
-
|
280
|
-
};
|
257
|
+
this.map.fitBounds(bounds);
|
258
|
+
};
|
281
259
|
|
282
|
-
|
283
|
-
this.
|
284
|
-
|
260
|
+
// Map methods
|
261
|
+
this.setCenter = function(lat, lng, callback) {
|
262
|
+
this.map.panTo(new google.maps.LatLng(lat, lng));
|
263
|
+
if (callback) {
|
264
|
+
callback();
|
265
|
+
}
|
266
|
+
};
|
285
267
|
|
286
|
-
|
287
|
-
|
288
|
-
|
268
|
+
this.getCenter = function() {
|
269
|
+
return this.map.getCenter();
|
270
|
+
};
|
289
271
|
|
290
|
-
|
291
|
-
|
272
|
+
this.getDiv = function() {
|
273
|
+
return this.div;
|
274
|
+
};
|
292
275
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
control.style.boxShadow = 'rgba(0, 0, 0, 0.398438) 0px 2px 4px';
|
276
|
+
this.setZoom = function(value) {
|
277
|
+
this.map.setZoom(value);
|
278
|
+
};
|
297
279
|
|
298
|
-
|
299
|
-
|
300
|
-
}
|
280
|
+
this.getZoom = function() {
|
281
|
+
return this.map.getZoom();
|
282
|
+
};
|
301
283
|
|
302
|
-
|
284
|
+
this.zoomIn = function(value) {
|
285
|
+
this.map.setZoom(this.map.getZoom() + value);
|
286
|
+
};
|
303
287
|
|
304
|
-
|
305
|
-
(
|
306
|
-
|
307
|
-
options.events[name].apply(this, [this]);
|
308
|
-
});
|
309
|
-
})(control, ev);
|
310
|
-
}
|
288
|
+
this.zoomOut = function(value) {
|
289
|
+
this.map.setZoom(this.map.getZoom() - value);
|
290
|
+
};
|
311
291
|
|
312
|
-
|
292
|
+
this.createControl = function(options) {
|
293
|
+
var control = doc.createElement('div');
|
313
294
|
|
314
|
-
|
315
|
-
|
295
|
+
control.style.cursor = 'pointer';
|
296
|
+
control.style.fontFamily = 'Arial, sans-serif';
|
297
|
+
control.style.fontSize = '13px';
|
298
|
+
control.style.boxShadow = 'rgba(0, 0, 0, 0.398438) 0px 2px 4px';
|
316
299
|
|
317
|
-
|
318
|
-
|
300
|
+
for(var option in options.style){
|
301
|
+
control.style[option] = options.style[option];
|
302
|
+
}
|
319
303
|
|
320
|
-
|
304
|
+
control.textContent = options.text;
|
321
305
|
|
322
|
-
|
323
|
-
|
324
|
-
|
306
|
+
for (var ev in options.events) {
|
307
|
+
(function(object, name) {
|
308
|
+
google.maps.event.addDomListener(object, name, function(){
|
309
|
+
options.events[name].apply(this, [this]);
|
310
|
+
});
|
311
|
+
})(control, ev);
|
312
|
+
}
|
325
313
|
|
326
|
-
|
327
|
-
};
|
314
|
+
control.index = 1;
|
328
315
|
|
329
|
-
|
330
|
-
|
331
|
-
if (options.lat && options.lng) {
|
332
|
-
var self = this;
|
333
|
-
var details = options.details;
|
334
|
-
var fences = options.fences;
|
335
|
-
var outside = options.outside;
|
316
|
+
return control;
|
317
|
+
};
|
336
318
|
|
337
|
-
|
338
|
-
|
339
|
-
map: null
|
340
|
-
};
|
319
|
+
this.addControl = function(options) {
|
320
|
+
var position = google.maps.ControlPosition[options.position.toUpperCase()];
|
341
321
|
|
342
|
-
delete options.
|
343
|
-
delete options.lng;
|
344
|
-
delete options.fences;
|
345
|
-
delete options.outside;
|
322
|
+
delete options.position;
|
346
323
|
|
347
|
-
var
|
324
|
+
var control = this.createControl(options);
|
325
|
+
this.controls.push(control);
|
326
|
+
this.map.controls[position].push(control);
|
348
327
|
|
349
|
-
|
328
|
+
return control;
|
329
|
+
};
|
350
330
|
|
351
|
-
|
331
|
+
// Markers
|
332
|
+
this.createMarker = function(options) {
|
333
|
+
if ((options.lat && options.lng) || options.position) {
|
334
|
+
var self = this;
|
335
|
+
var details = options.details;
|
336
|
+
var fences = options.fences;
|
337
|
+
var outside = options.outside;
|
338
|
+
|
339
|
+
var base_options = {
|
340
|
+
position: new google.maps.LatLng(options.lat, options.lng),
|
341
|
+
map: null
|
342
|
+
};
|
352
343
|
|
353
|
-
|
354
|
-
|
344
|
+
delete options.lat;
|
345
|
+
delete options.lng;
|
346
|
+
delete options.fences;
|
347
|
+
delete options.outside;
|
355
348
|
|
356
|
-
var
|
349
|
+
var marker_options = extend_object(base_options, options);
|
357
350
|
|
358
|
-
|
359
|
-
(function(object, name) {
|
360
|
-
google.maps.event.addListener(object, name, function(e){
|
361
|
-
if (options.infoWindow[name])
|
362
|
-
options.infoWindow[name].apply(this, [e]);
|
363
|
-
});
|
364
|
-
})(marker.infoWindow, info_window_events[ev]);
|
365
|
-
}
|
366
|
-
}
|
351
|
+
var marker = new google.maps.Marker(marker_options);
|
367
352
|
|
368
|
-
|
353
|
+
marker.fences = fences;
|
369
354
|
|
370
|
-
|
371
|
-
|
372
|
-
google.maps.event.addListener(object, name, function(){
|
373
|
-
if (options[name])
|
374
|
-
options[name].apply(this, [this]);
|
375
|
-
});
|
376
|
-
})(marker, marker_events[ev]);
|
377
|
-
}
|
355
|
+
if (options.infoWindow) {
|
356
|
+
marker.infoWindow = new google.maps.InfoWindow(options.infoWindow);
|
378
357
|
|
379
|
-
|
380
|
-
this.details = details;
|
358
|
+
var info_window_events = ['closeclick', 'content_changed', 'domready', 'position_changed', 'zindex_changed'];
|
381
359
|
|
382
|
-
|
383
|
-
|
360
|
+
for (var ev = 0; ev < info_window_events.length; ev++) {
|
361
|
+
(function(object, name) {
|
362
|
+
google.maps.event.addListener(object, name, function(e){
|
363
|
+
if (options.infoWindow[name])
|
364
|
+
options.infoWindow[name].apply(this, [e]);
|
365
|
+
});
|
366
|
+
})(marker.infoWindow, info_window_events[ev]);
|
367
|
+
}
|
384
368
|
}
|
385
369
|
|
386
|
-
|
387
|
-
|
388
|
-
|
370
|
+
var marker_events = ['drag', 'dragstart', 'mouseout', 'mouseover', 'mouseup', 'position_changed'];
|
371
|
+
|
372
|
+
for (var ev = 0; ev < marker_events.length; ev++) {
|
373
|
+
(function(object, name) {
|
374
|
+
google.maps.event.addListener(object, name, function(){
|
375
|
+
if (options[name])
|
376
|
+
options[name].apply(this, [this]);
|
377
|
+
});
|
378
|
+
})(marker, marker_events[ev]);
|
389
379
|
}
|
390
|
-
});
|
391
380
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
381
|
+
google.maps.event.addListener(marker, 'click', function() {
|
382
|
+
this.details = details;
|
383
|
+
|
384
|
+
if (options.click) {
|
385
|
+
options.click.apply(this, [this]);
|
396
386
|
}
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
387
|
+
|
388
|
+
if (marker.infoWindow) {
|
389
|
+
self.hideInfoWindows();
|
390
|
+
marker.infoWindow.open(self.map, marker);
|
401
391
|
}
|
402
392
|
});
|
393
|
+
|
394
|
+
if (options.dragend || marker.fences) {
|
395
|
+
google.maps.event.addListener(marker, 'dragend', function() {
|
396
|
+
if (options.dragend) {
|
397
|
+
options.dragend.apply(this, [this]);
|
398
|
+
}
|
399
|
+
if (marker.fences) {
|
400
|
+
self.checkMarkerGeofence(marker, function(m, f) {
|
401
|
+
outside(m, f);
|
402
|
+
});
|
403
|
+
}
|
404
|
+
});
|
405
|
+
}
|
406
|
+
|
407
|
+
return marker;
|
403
408
|
}
|
409
|
+
else {
|
410
|
+
throw 'No latitude or longitude defined';
|
411
|
+
}
|
412
|
+
};
|
404
413
|
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
};
|
414
|
+
this.addMarker = function(options) {
|
415
|
+
if ((options.lat && options.lng) || options.position) {
|
416
|
+
var marker = this.createMarker(options);
|
417
|
+
marker.setMap(this.map);
|
418
|
+
this.markers.push(marker);
|
411
419
|
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
420
|
+
return marker;
|
421
|
+
}
|
422
|
+
else {
|
423
|
+
throw 'No latitude or longitude defined';
|
424
|
+
}
|
425
|
+
};
|
417
426
|
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
427
|
+
this.addMarkers = function(array) {
|
428
|
+
for (var i=0, marker; marker=array[i]; i++) {
|
429
|
+
this.addMarker(marker);
|
430
|
+
}
|
431
|
+
return this.markers;
|
432
|
+
};
|
424
433
|
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
434
|
+
this.hideInfoWindows = function() {
|
435
|
+
for (var i=0, marker; marker=this.markers[i]; i++){
|
436
|
+
if (marker.infoWindow){
|
437
|
+
marker.infoWindow.close();
|
438
|
+
}
|
439
|
+
}
|
440
|
+
};
|
431
441
|
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
marker.infoWindow.close();
|
442
|
+
this.removeMarkers = function() {
|
443
|
+
for (var i=0, marker; marker=this.markers[i]; i++){
|
444
|
+
marker.setMap(null);
|
436
445
|
}
|
437
|
-
|
438
|
-
|
446
|
+
this.markers = [];
|
447
|
+
};
|
439
448
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
this.markers = [];
|
445
|
-
};
|
449
|
+
// Overlays
|
450
|
+
this.drawOverlay = function(options) {
|
451
|
+
var overlay = new google.maps.OverlayView();
|
452
|
+
overlay.setMap(self.map);
|
446
453
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
454
|
+
overlay.onAdd = function() {
|
455
|
+
var div = doc.createElement('div');
|
456
|
+
div.style.borderStyle = "none";
|
457
|
+
div.style.borderWidth = "0px";
|
458
|
+
div.style.position = "absolute";
|
459
|
+
div.style.zIndex = 100;
|
460
|
+
div.innerHTML = options.content;
|
451
461
|
|
452
|
-
|
453
|
-
var div = doc.createElement('div');
|
454
|
-
div.style.borderStyle = "none";
|
455
|
-
div.style.borderWidth = "0px";
|
456
|
-
div.style.position = "absolute";
|
457
|
-
div.style.zIndex = 100;
|
458
|
-
div.innerHTML = options.content;
|
462
|
+
self.overlay_div = div;
|
459
463
|
|
460
|
-
|
464
|
+
var panes = this.getPanes();
|
465
|
+
if (!options.layer) {
|
466
|
+
options.layer = 'overlayLayer';
|
467
|
+
}
|
468
|
+
var overlayLayer = panes[options.layer];
|
469
|
+
overlayLayer.appendChild(div);
|
470
|
+
};
|
461
471
|
|
462
|
-
|
463
|
-
|
464
|
-
options.
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
472
|
+
overlay.draw = function() {
|
473
|
+
var projection = this.getProjection();
|
474
|
+
var pixel = projection.fromLatLngToDivPixel(new google.maps.LatLng(options.lat, options.lng));
|
475
|
+
|
476
|
+
options.horizontalOffset = options.horizontalOffset || 0;
|
477
|
+
options.verticalOffset = options.verticalOffset || 0;
|
478
|
+
|
479
|
+
var div = self.overlay_div;
|
480
|
+
var content = div.children[0];
|
481
|
+
|
482
|
+
var content_height = content.clientHeight;
|
483
|
+
var content_width = content.clientWidth;
|
484
|
+
|
485
|
+
switch (options.verticalAlign) {
|
486
|
+
case 'top':
|
487
|
+
div.style.top = (pixel.y - content_height + options.verticalOffset) + 'px';
|
488
|
+
break;
|
489
|
+
default:
|
490
|
+
case 'middle':
|
491
|
+
div.style.top = (pixel.y - (content_height / 2) + options.verticalOffset) + 'px';
|
492
|
+
break;
|
493
|
+
case 'bottom':
|
494
|
+
div.style.top = (pixel.y + options.verticalOffset) + 'px';
|
495
|
+
break;
|
496
|
+
}
|
469
497
|
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
switch (options.verticalAlign) {
|
484
|
-
case 'top':
|
485
|
-
div.style.top = (pixel.y - content_height + options.verticalOffset) + 'px';
|
486
|
-
break;
|
487
|
-
default:
|
488
|
-
case 'middle':
|
489
|
-
div.style.top = (pixel.y - (content_height / 2) + options.verticalOffset) + 'px';
|
490
|
-
break;
|
491
|
-
case 'bottom':
|
492
|
-
div.style.top = (pixel.y + options.verticalOffset) + 'px';
|
493
|
-
break;
|
494
|
-
}
|
498
|
+
switch (options.horizontalAlign) {
|
499
|
+
case 'left':
|
500
|
+
div.style.left = (pixel.x - content_width + options.horizontalOffset) + 'px';
|
501
|
+
break;
|
502
|
+
default:
|
503
|
+
case 'center':
|
504
|
+
div.style.left = (pixel.x - (content_width / 2) + options.horizontalOffset) + 'px';
|
505
|
+
break;
|
506
|
+
case 'right':
|
507
|
+
div.style.left = (pixel.x + options.horizontalOffset) + 'px';
|
508
|
+
break;
|
509
|
+
}
|
510
|
+
};
|
495
511
|
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
div.style.left = (pixel.x - (content_width / 2) + options.horizontalOffset) + 'px';
|
503
|
-
break;
|
504
|
-
case 'right':
|
505
|
-
div.style.left = (pixel.x + options.horizontalOffset) + 'px';
|
506
|
-
break;
|
507
|
-
}
|
512
|
+
overlay.onRemove = function() {
|
513
|
+
self.overlay_div.parentNode.removeChild(self.overlay_div);
|
514
|
+
self.overlay_div = null;
|
515
|
+
};
|
516
|
+
self.overlays.push(overlay);
|
517
|
+
return overlay;
|
508
518
|
};
|
509
519
|
|
510
|
-
|
511
|
-
|
512
|
-
self.overlay_div = null;
|
520
|
+
this.removeOverlay = function(overlay) {
|
521
|
+
overlay.setMap(null);
|
513
522
|
};
|
514
|
-
self.overlays.push(overlay);
|
515
|
-
return overlay;
|
516
|
-
};
|
517
|
-
|
518
|
-
this.removeOverlay = function(overlay) {
|
519
|
-
overlay.setMap(null);
|
520
|
-
};
|
521
523
|
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
524
|
+
this.removeOverlays = function() {
|
525
|
+
for (var i=0, item; item=self.overlays[i]; i++){
|
526
|
+
item.setMap(null);
|
527
|
+
}
|
528
|
+
self.overlays = [];
|
529
|
+
};
|
528
530
|
|
529
|
-
|
530
|
-
|
531
|
-
|
531
|
+
this.drawPolyline = function(options) {
|
532
|
+
var path = [];
|
533
|
+
var points = options.path;
|
532
534
|
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
535
|
+
if (points.length){
|
536
|
+
if (points[0][0] === undefined){
|
537
|
+
path = points;
|
538
|
+
}
|
539
|
+
else {
|
540
|
+
for (var i=0, latlng; latlng=points[i]; i++){
|
541
|
+
path.push(new google.maps.LatLng(latlng[0], latlng[1]));
|
542
|
+
}
|
540
543
|
}
|
541
544
|
}
|
542
|
-
}
|
543
545
|
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
546
|
+
var polyline = new google.maps.Polyline({
|
547
|
+
map: this.map,
|
548
|
+
path: path,
|
549
|
+
strokeColor: options.strokeColor,
|
550
|
+
strokeOpacity: options.strokeOpacity,
|
551
|
+
strokeWeight: options.strokeWeight
|
552
|
+
});
|
551
553
|
|
552
|
-
|
554
|
+
var polyline_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
|
553
555
|
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
556
|
+
for (var ev = 0; ev < polyline_events.length; ev++) {
|
557
|
+
(function(object, name) {
|
558
|
+
google.maps.event.addListener(object, name, function(e){
|
559
|
+
if (options[name])
|
560
|
+
options[name].apply(this, [e]);
|
561
|
+
});
|
562
|
+
})(polyline, polyline_events[ev]);
|
563
|
+
}
|
562
564
|
|
563
|
-
|
565
|
+
this.polylines.push(polyline);
|
564
566
|
|
565
|
-
|
566
|
-
|
567
|
+
return polyline;
|
568
|
+
};
|
567
569
|
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
570
|
+
this.drawCircle = function(options) {
|
571
|
+
options = extend_object({
|
572
|
+
map: this.map,
|
573
|
+
center: new google.maps.LatLng(options.lat, options.lng)
|
574
|
+
}, options);
|
573
575
|
|
574
|
-
|
575
|
-
|
576
|
-
|
576
|
+
delete options.lat;
|
577
|
+
delete options.lng;
|
578
|
+
var polygon = new google.maps.Circle(options);
|
577
579
|
|
578
|
-
|
580
|
+
var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
|
579
581
|
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
582
|
+
for (var ev = 0; ev < polygon_events.length; ev++) {
|
583
|
+
(function(object, name) {
|
584
|
+
google.maps.event.addListener(object, name, function(e){
|
585
|
+
if (options[name])
|
586
|
+
options[name].apply(this, [e]);
|
587
|
+
});
|
588
|
+
})(polygon, polygon_events[ev]);
|
589
|
+
}
|
588
590
|
|
589
|
-
|
590
|
-
|
591
|
+
return polygon;
|
592
|
+
};
|
593
|
+
|
594
|
+
this.drawRectangle = function(options) {
|
595
|
+
options = extend_object({
|
596
|
+
map: this.map
|
597
|
+
}, options);
|
591
598
|
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
599
|
+
var latLngBounds = new google.maps.LatLngBounds(
|
600
|
+
new google.maps.LatLng(options.bounds[0][0], options.bounds[0][1]),
|
601
|
+
new google.maps.LatLng(options.bounds[1][0], options.bounds[1][1])
|
602
|
+
);
|
603
|
+
|
604
|
+
options.bounds = latLngBounds;
|
596
605
|
|
597
|
-
|
598
|
-
if(options.paths[0].length > 0) {
|
599
|
-
options.paths = array_map(options.paths, arrayToLatLng);
|
600
|
-
}
|
601
|
-
}
|
606
|
+
var polygon = new google.maps.Rectangle(options);
|
602
607
|
|
603
|
-
|
608
|
+
var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
|
604
609
|
|
605
|
-
|
610
|
+
for (var ev = 0; ev < polygon_events.length; ev++) {
|
611
|
+
(function(object, name) {
|
612
|
+
google.maps.event.addListener(object, name, function(e){
|
613
|
+
if (options[name])
|
614
|
+
options[name].apply(this, [e]);
|
615
|
+
});
|
616
|
+
})(polygon, polygon_events[ev]);
|
617
|
+
}
|
606
618
|
|
607
|
-
|
608
|
-
|
609
|
-
google.maps.event.addListener(object, name, function(e){
|
610
|
-
if (options[name])
|
611
|
-
options[name].apply(this, [e]);
|
612
|
-
});
|
613
|
-
})(polygon, polygon_events[ev]);
|
614
|
-
}
|
619
|
+
return polygon;
|
620
|
+
};
|
615
621
|
|
616
|
-
this.
|
622
|
+
this.drawPolygon = function(options) {
|
623
|
+
options = extend_object({
|
624
|
+
map: this.map
|
625
|
+
}, options);
|
617
626
|
|
618
|
-
|
619
|
-
|
627
|
+
if(options.paths.length > 0) {
|
628
|
+
if(options.paths[0].length > 0) {
|
629
|
+
options.paths = array_map(options.paths, arrayToLatLng);
|
630
|
+
}
|
631
|
+
}
|
620
632
|
|
621
|
-
|
622
|
-
var events = options.events;
|
633
|
+
var polygon = new google.maps.Polygon(options);
|
623
634
|
|
624
|
-
|
635
|
+
var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
|
625
636
|
|
626
|
-
|
637
|
+
for (var ev = 0; ev < polygon_events.length; ev++) {
|
638
|
+
(function(object, name) {
|
639
|
+
google.maps.event.addListener(object, name, function(e){
|
640
|
+
if (options[name])
|
641
|
+
options[name].apply(this, [e]);
|
642
|
+
});
|
643
|
+
})(polygon, polygon_events[ev]);
|
644
|
+
}
|
627
645
|
|
628
|
-
|
646
|
+
this.polygons.push(polygon);
|
629
647
|
|
630
|
-
|
631
|
-
|
632
|
-
google.maps.event.addListener(object, name, function(e){
|
633
|
-
events[name].apply(this, [e]);
|
634
|
-
});
|
635
|
-
})(layer, ev);
|
636
|
-
}
|
648
|
+
return polygon;
|
649
|
+
};
|
637
650
|
|
638
|
-
this.
|
651
|
+
this.getFromFusionTables = function(options) {
|
652
|
+
var events = options.events;
|
639
653
|
|
640
|
-
|
641
|
-
};
|
654
|
+
delete options.events;
|
642
655
|
|
643
|
-
|
644
|
-
var layer = this.getFromFusionTables(options);
|
645
|
-
layer.setMap(this.map);
|
656
|
+
var fusion_tables_options = options;
|
646
657
|
|
647
|
-
|
648
|
-
};
|
658
|
+
var layer = new google.maps.FusionTablesLayer(fusion_tables_options);
|
649
659
|
|
650
|
-
|
651
|
-
|
652
|
-
|
660
|
+
for (var ev in events) {
|
661
|
+
(function(object, name) {
|
662
|
+
google.maps.event.addListener(object, name, function(e){
|
663
|
+
events[name].apply(this, [e]);
|
664
|
+
});
|
665
|
+
})(layer, ev);
|
666
|
+
}
|
653
667
|
|
654
|
-
|
655
|
-
delete options.events;
|
668
|
+
this.layers.push(layer);
|
656
669
|
|
657
|
-
|
670
|
+
return layer;
|
671
|
+
};
|
658
672
|
|
659
|
-
|
673
|
+
this.loadFromFusionTables = function(options) {
|
674
|
+
var layer = this.getFromFusionTables(options);
|
675
|
+
layer.setMap(this.map);
|
660
676
|
|
661
|
-
|
662
|
-
|
663
|
-
google.maps.event.addListener(object, name, function(e){
|
664
|
-
events[name].apply(this, [e]);
|
665
|
-
});
|
666
|
-
})(layer, ev);
|
667
|
-
}
|
677
|
+
return layer;
|
678
|
+
};
|
668
679
|
|
669
|
-
this.
|
680
|
+
this.getFromKML = function(options) {
|
681
|
+
var url = options.url;
|
682
|
+
var events = options.events;
|
670
683
|
|
671
|
-
|
672
|
-
|
684
|
+
delete options.url;
|
685
|
+
delete options.events;
|
673
686
|
|
674
|
-
|
675
|
-
var layer = this.getFromKML(options);
|
676
|
-
layer.setMap(this.map);
|
687
|
+
var kml_options = options;
|
677
688
|
|
678
|
-
|
679
|
-
};
|
689
|
+
var layer = new google.maps.KmlLayer(url, kml_options);
|
680
690
|
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
case 'driving':
|
689
|
-
travelMode = google.maps.TravelMode.DRIVING;
|
690
|
-
break;
|
691
|
-
// case 'walking':
|
692
|
-
default:
|
693
|
-
travelMode = google.maps.TravelMode.WALKING;
|
694
|
-
break;
|
695
|
-
}
|
691
|
+
for (var ev in events) {
|
692
|
+
(function(object, name) {
|
693
|
+
google.maps.event.addListener(object, name, function(e){
|
694
|
+
events[name].apply(this, [e]);
|
695
|
+
});
|
696
|
+
})(layer, ev);
|
697
|
+
}
|
696
698
|
|
697
|
-
|
698
|
-
unitSystem = google.maps.UnitSystem.IMPERIAL;
|
699
|
-
}
|
700
|
-
else {
|
701
|
-
unitSystem = google.maps.UnitSystem.METRIC;
|
702
|
-
}
|
699
|
+
this.layers.push(layer);
|
703
700
|
|
704
|
-
|
705
|
-
avoidHighways: false,
|
706
|
-
avoidTolls: false,
|
707
|
-
optimizeWaypoints: false,
|
708
|
-
waypoints: []
|
701
|
+
return layer;
|
709
702
|
};
|
710
703
|
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
request_options.destination = new google.maps.LatLng(options.destination[0], options.destination[1]);
|
715
|
-
request_options.travelMode = travelMode;
|
716
|
-
request_options.unitSystem = unitSystem;
|
704
|
+
this.loadFromKML = function(options) {
|
705
|
+
var layer = this.getFromKML(options);
|
706
|
+
layer.setMap(this.map);
|
717
707
|
|
718
|
-
|
708
|
+
return layer;
|
709
|
+
};
|
719
710
|
|
720
|
-
|
721
|
-
var
|
711
|
+
// Services
|
712
|
+
var travelMode, unitSystem;
|
713
|
+
this.getRoutes = function(options) {
|
714
|
+
switch (options.travelMode) {
|
715
|
+
case 'bicycling':
|
716
|
+
travelMode = google.maps.TravelMode.BICYCLING;
|
717
|
+
break;
|
718
|
+
case 'driving':
|
719
|
+
travelMode = google.maps.TravelMode.DRIVING;
|
720
|
+
break;
|
721
|
+
// case 'walking':
|
722
|
+
default:
|
723
|
+
travelMode = google.maps.TravelMode.WALKING;
|
724
|
+
break;
|
725
|
+
}
|
722
726
|
|
723
|
-
|
724
|
-
|
725
|
-
for (var r in result.routes) {
|
726
|
-
if (result.routes.hasOwnProperty(r)) {
|
727
|
-
self.routes.push(result.routes[r]);
|
728
|
-
}
|
729
|
-
}
|
727
|
+
if (options.unitSystem === 'imperial') {
|
728
|
+
unitSystem = google.maps.UnitSystem.IMPERIAL;
|
730
729
|
}
|
731
|
-
|
732
|
-
|
730
|
+
else {
|
731
|
+
unitSystem = google.maps.UnitSystem.METRIC;
|
733
732
|
}
|
734
|
-
});
|
735
|
-
};
|
736
733
|
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
734
|
+
var base_options = {
|
735
|
+
avoidHighways: false,
|
736
|
+
avoidTolls: false,
|
737
|
+
optimizeWaypoints: false,
|
738
|
+
waypoints: []
|
739
|
+
};
|
743
740
|
|
744
|
-
|
745
|
-
if(options.locations[0].length > 0) {
|
746
|
-
options.locations = array_map(options.locations, arrayToLatLng);
|
747
|
-
}
|
748
|
-
}
|
741
|
+
var request_options = extend_object(base_options, options);
|
749
742
|
|
750
|
-
|
751
|
-
|
743
|
+
request_options.origin = new google.maps.LatLng(options.origin[0], options.origin[1]);
|
744
|
+
request_options.destination = new google.maps.LatLng(options.destination[0], options.destination[1]);
|
745
|
+
request_options.travelMode = travelMode;
|
746
|
+
request_options.unitSystem = unitSystem;
|
752
747
|
|
753
|
-
|
748
|
+
delete request_options.callback;
|
754
749
|
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
750
|
+
var self = this;
|
751
|
+
var service = new google.maps.DirectionsService();
|
752
|
+
|
753
|
+
service.route(request_options, function(result, status) {
|
754
|
+
if (status === google.maps.DirectionsStatus.OK) {
|
755
|
+
for (var r in result.routes) {
|
756
|
+
if (result.routes.hasOwnProperty(r)) {
|
757
|
+
self.routes.push(result.routes[r]);
|
758
|
+
}
|
759
|
+
}
|
760
|
+
}
|
761
|
+
if (options.callback) {
|
762
|
+
options.callback(self.routes);
|
762
763
|
}
|
763
764
|
});
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
765
|
+
};
|
766
|
+
|
767
|
+
this.getElevations = function(options) {
|
768
|
+
options = extend_object({
|
769
|
+
locations: [],
|
770
|
+
path : false,
|
771
|
+
samples : 256
|
772
|
+
}, options);
|
770
773
|
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
+
if(options.locations.length > 0) {
|
775
|
+
if(options.locations[0].length > 0) {
|
776
|
+
options.locations = array_map(options.locations, arrayToLatLng);
|
774
777
|
}
|
775
|
-
}
|
776
|
-
}
|
777
|
-
};
|
778
|
+
}
|
778
779
|
|
779
|
-
|
780
|
-
|
781
|
-
for(index in this.polylines){
|
782
|
-
this.polylines[index].setMap(null);
|
783
|
-
}
|
784
|
-
this.polylines = [];
|
785
|
-
}
|
780
|
+
var callback = options.callback;
|
781
|
+
delete options.callback;
|
786
782
|
|
787
|
-
|
788
|
-
this.cleanRoute = this.removePolylines;
|
783
|
+
var service = new google.maps.ElevationService();
|
789
784
|
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
callback: function(e) {
|
798
|
-
if (e.length > 0) {
|
799
|
-
self.drawPolyline({
|
800
|
-
path: e[e.length - 1].overview_path,
|
801
|
-
strokeColor: options.strokeColor,
|
802
|
-
strokeOpacity: options.strokeOpacity,
|
803
|
-
strokeWeight: options.strokeWeight
|
804
|
-
});
|
805
|
-
if (options.callback) {
|
806
|
-
options.callback(e[e.length - 1]);
|
785
|
+
//location request
|
786
|
+
if (!options.path) {
|
787
|
+
delete options.path;
|
788
|
+
delete options.samples;
|
789
|
+
service.getElevationForLocations(options, function(result, status){
|
790
|
+
if (callback && typeof(callback) === "function") {
|
791
|
+
callback(result, status);
|
807
792
|
}
|
808
|
-
}
|
793
|
+
});
|
794
|
+
//path request
|
795
|
+
} else {
|
796
|
+
var pathRequest = {
|
797
|
+
path : options.locations,
|
798
|
+
samples : options.samples
|
799
|
+
};
|
800
|
+
|
801
|
+
service.getElevationAlongPath(pathRequest, function(result, status){
|
802
|
+
if (callback && typeof(callback) === "function") {
|
803
|
+
callback(result, status);
|
804
|
+
}
|
805
|
+
});
|
809
806
|
}
|
810
|
-
}
|
811
|
-
};
|
807
|
+
};
|
812
808
|
|
813
|
-
|
814
|
-
|
809
|
+
this.removePolylines = function(){
|
810
|
+
var index;
|
811
|
+
for(index in this.polylines){
|
812
|
+
this.polylines[index].setMap(null);
|
813
|
+
}
|
814
|
+
this.polylines = [];
|
815
|
+
}
|
816
|
+
|
817
|
+
// Alias for the method "drawRoute"
|
818
|
+
this.cleanRoute = this.removePolylines;
|
819
|
+
|
820
|
+
this.drawRoute = function(options) {
|
821
|
+
var self = this;
|
815
822
|
this.getRoutes({
|
816
823
|
origin: options.origin,
|
817
824
|
destination: options.destination,
|
818
825
|
travelMode: options.travelMode,
|
819
826
|
waypoints : options.waypoints,
|
820
827
|
callback: function(e) {
|
821
|
-
if (e.length > 0
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
828
|
+
if (e.length > 0) {
|
829
|
+
self.drawPolyline({
|
830
|
+
path: e[e.length - 1].overview_path,
|
831
|
+
strokeColor: options.strokeColor,
|
832
|
+
strokeOpacity: options.strokeOpacity,
|
833
|
+
strokeWeight: options.strokeWeight
|
834
|
+
});
|
835
|
+
if (options.callback) {
|
836
|
+
options.callback(e[e.length - 1]);
|
829
837
|
}
|
830
838
|
}
|
831
839
|
}
|
832
840
|
});
|
833
|
-
}
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
options.
|
841
|
+
};
|
842
|
+
|
843
|
+
this.travelRoute = function(options) {
|
844
|
+
if (options.origin && options.destination) {
|
845
|
+
this.getRoutes({
|
846
|
+
origin: options.origin,
|
847
|
+
destination: options.destination,
|
848
|
+
travelMode: options.travelMode,
|
849
|
+
waypoints : options.waypoints,
|
850
|
+
callback: function(e) {
|
851
|
+
if (e.length > 0 && options.step) {
|
852
|
+
var route = e[e.length - 1];
|
853
|
+
if (route.legs.length > 0) {
|
854
|
+
var steps = route.legs[0].steps;
|
855
|
+
for (var i=0, step; step=steps[i]; i++) {
|
856
|
+
step.step_number = i;
|
857
|
+
options.step(step);
|
858
|
+
}
|
859
|
+
}
|
860
|
+
}
|
861
|
+
}
|
862
|
+
});
|
863
|
+
}
|
864
|
+
else if (options.route) {
|
865
|
+
if (options.route.legs.length > 0) {
|
866
|
+
var steps = options.route.legs[0].steps;
|
867
|
+
for (var i=0, step; step=steps[i]; i++) {
|
868
|
+
step.step_number = i;
|
869
|
+
options.step(step);
|
870
|
+
}
|
840
871
|
}
|
841
872
|
}
|
842
|
-
}
|
843
|
-
};
|
873
|
+
};
|
844
874
|
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
875
|
+
this.drawSteppedRoute = function(options) {
|
876
|
+
if (options.origin && options.destination) {
|
877
|
+
this.getRoutes({
|
878
|
+
origin: options.origin,
|
879
|
+
destination: options.destination,
|
880
|
+
travelMode: options.travelMode,
|
881
|
+
callback: function(e) {
|
882
|
+
if (e.length > 0 && options.step) {
|
883
|
+
var route = e[e.length - 1];
|
884
|
+
if (route.legs.length > 0) {
|
885
|
+
var steps = route.legs[0].steps;
|
886
|
+
for (var i=0, step; step=steps[i]; i++) {
|
887
|
+
step.step_number = i;
|
888
|
+
self.drawPolyline({
|
889
|
+
path: step.path,
|
890
|
+
strokeColor: options.strokeColor,
|
891
|
+
strokeOpacity: options.strokeOpacity,
|
892
|
+
strokeWeight: options.strokeWeight
|
893
|
+
});
|
894
|
+
options.step(step);
|
895
|
+
}
|
865
896
|
}
|
866
897
|
}
|
867
898
|
}
|
868
|
-
}
|
869
|
-
}
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
899
|
+
});
|
900
|
+
}
|
901
|
+
else if (options.route) {
|
902
|
+
if (options.route.legs.length > 0) {
|
903
|
+
var steps = options.route.legs[0].steps;
|
904
|
+
for (var i=0, step; step=steps[i]; i++) {
|
905
|
+
step.step_number = i;
|
906
|
+
self.drawPolyline({
|
907
|
+
path: step.path,
|
908
|
+
strokeColor: options.strokeColor,
|
909
|
+
strokeOpacity: options.strokeOpacity,
|
910
|
+
strokeWeight: options.strokeWeight
|
911
|
+
});
|
912
|
+
options.step(step);
|
913
|
+
}
|
883
914
|
}
|
884
915
|
}
|
885
|
-
}
|
886
|
-
};
|
916
|
+
};
|
887
917
|
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
918
|
+
// Geofence
|
919
|
+
this.checkGeofence = function(lat, lng, fence) {
|
920
|
+
return fence.containsLatLng(new google.maps.LatLng(lat, lng));
|
921
|
+
};
|
892
922
|
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
923
|
+
this.checkMarkerGeofence = function(marker, outside_callback) {
|
924
|
+
if (marker.fences) {
|
925
|
+
for (var i=0, fence; fence=marker.fences[i]; i++) {
|
926
|
+
var pos = marker.getPosition();
|
927
|
+
if (!self.checkGeofence(pos.lat(), pos.lng(), fence)) {
|
928
|
+
outside_callback(marker, fence);
|
929
|
+
}
|
899
930
|
}
|
900
931
|
}
|
901
|
-
}
|
932
|
+
};
|
902
933
|
};
|
903
|
-
};
|
904
934
|
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
935
|
+
GMaps.Route = function(options) {
|
936
|
+
this.map = options.map;
|
937
|
+
this.route = options.route;
|
938
|
+
this.step_count = 0;
|
939
|
+
this.steps = this.route.legs[0].steps;
|
940
|
+
this.steps_length = this.steps.length;
|
941
|
+
|
942
|
+
this.polyline = this.map.drawPolyline({
|
943
|
+
path: new google.maps.MVCArray(),
|
944
|
+
strokeColor: options.strokeColor,
|
945
|
+
strokeOpacity: options.strokeOpacity,
|
946
|
+
strokeWeight: options.strokeWeight
|
947
|
+
}).getPath();
|
948
|
+
|
949
|
+
this.back = function() {
|
950
|
+
if (this.step_count > 0) {
|
951
|
+
this.step_count--;
|
952
|
+
var path = this.route.legs[0].steps[this.step_count].path;
|
953
|
+
for (var p in path){
|
954
|
+
if (path.hasOwnProperty(p)){
|
955
|
+
this.polyline.pop();
|
956
|
+
}
|
926
957
|
}
|
927
958
|
}
|
928
|
-
}
|
929
|
-
};
|
959
|
+
};
|
930
960
|
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
961
|
+
this.forward = function() {
|
962
|
+
if (this.step_count < this.steps_length) {
|
963
|
+
var path = this.route.legs[0].steps[this.step_count].path;
|
964
|
+
for (var p in path){
|
965
|
+
if (path.hasOwnProperty(p)){
|
966
|
+
this.polyline.push(path[p]);
|
967
|
+
}
|
937
968
|
}
|
969
|
+
this.step_count++;
|
938
970
|
}
|
939
|
-
|
940
|
-
}
|
971
|
+
};
|
941
972
|
};
|
942
|
-
};
|
943
973
|
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
974
|
+
// Geolocation (Modern browsers only)
|
975
|
+
GMaps.geolocate = function(options) {
|
976
|
+
if (navigator.geolocation) {
|
977
|
+
navigator.geolocation.getCurrentPosition(function(position) {
|
978
|
+
options.success(position);
|
979
|
+
if (options.always) {
|
980
|
+
options.always();
|
981
|
+
}
|
982
|
+
}, function(error) {
|
983
|
+
options.error(error);
|
984
|
+
if (options.always) {
|
985
|
+
options.always();
|
986
|
+
}
|
987
|
+
}, options.options);
|
988
|
+
}
|
989
|
+
else {
|
990
|
+
options.not_supported();
|
954
991
|
if (options.always) {
|
955
992
|
options.always();
|
956
993
|
}
|
957
|
-
}, options.options);
|
958
|
-
}
|
959
|
-
else {
|
960
|
-
options.not_supported();
|
961
|
-
if (options.always) {
|
962
|
-
options.always();
|
963
994
|
}
|
964
|
-
}
|
965
|
-
};
|
966
|
-
|
967
|
-
// Geocoding
|
968
|
-
GMaps.geocode = function(options) {
|
969
|
-
this.geocoder = new google.maps.Geocoder();
|
970
|
-
var callback = options.callback;
|
971
|
-
if (options.lat && options.lng) {
|
972
|
-
options.latLng = new google.maps.LatLng(options.lat, options.lng);
|
973
|
-
}
|
974
|
-
|
975
|
-
delete options.lat;
|
976
|
-
delete options.lng;
|
977
|
-
delete options.callback;
|
978
|
-
this.geocoder.geocode(options, function(results, status) {
|
979
|
-
callback(results, status);
|
980
|
-
});
|
981
|
-
};
|
982
|
-
|
983
|
-
// Static maps
|
984
|
-
GMaps.staticMapURL = function(options){
|
985
|
-
var parameters = [];
|
986
|
-
var data;
|
987
|
-
|
988
|
-
var static_root = 'http://maps.googleapis.com/maps/api/staticmap';
|
989
|
-
if (options.url){
|
990
|
-
static_root = options.url;
|
991
|
-
delete options.url;
|
992
|
-
}
|
993
|
-
static_root += '?';
|
994
|
-
|
995
|
-
var markers = options.markers;
|
996
|
-
delete options.markers;
|
997
|
-
if (!markers && options.marker){
|
998
|
-
markers = [options.marker];
|
999
|
-
delete options.marker;
|
1000
|
-
}
|
995
|
+
};
|
1001
996
|
|
1002
|
-
|
1003
|
-
|
997
|
+
// Geocoding
|
998
|
+
GMaps.geocode = function(options) {
|
999
|
+
this.geocoder = new google.maps.Geocoder();
|
1000
|
+
var callback = options.callback;
|
1001
|
+
if (options.lat && options.lng) {
|
1002
|
+
options.latLng = new google.maps.LatLng(options.lat, options.lng);
|
1003
|
+
}
|
1004
1004
|
|
1005
|
-
/** Map options **/
|
1006
|
-
if (options.center){
|
1007
|
-
parameters.push('center=' + options.center);
|
1008
|
-
delete options.center;
|
1009
|
-
}
|
1010
|
-
else if (options.address){
|
1011
|
-
parameters.push('center=' + options.address);
|
1012
|
-
delete options.address;
|
1013
|
-
}
|
1014
|
-
else if (options.lat){
|
1015
|
-
parameters.push(['center=', options.lat, ',', options.lng].join(''));
|
1016
1005
|
delete options.lat;
|
1017
1006
|
delete options.lng;
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
}
|
1023
|
-
|
1024
|
-
var size = options.size;
|
1025
|
-
if (size){
|
1026
|
-
if (size.join){
|
1027
|
-
size = size.join('x');
|
1028
|
-
}
|
1029
|
-
delete options.size;
|
1030
|
-
}
|
1031
|
-
else {
|
1032
|
-
size = '630x300';
|
1033
|
-
}
|
1034
|
-
parameters.push('size=' + size);
|
1035
|
-
|
1036
|
-
if (!options.zoom){
|
1037
|
-
options.zoom = 15;
|
1038
|
-
}
|
1007
|
+
delete options.callback;
|
1008
|
+
this.geocoder.geocode(options, function(results, status) {
|
1009
|
+
callback(results, status);
|
1010
|
+
});
|
1011
|
+
};
|
1039
1012
|
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1013
|
+
// Static maps
|
1014
|
+
GMaps.staticMapURL = function(options){
|
1015
|
+
var parameters = [];
|
1016
|
+
var data;
|
1043
1017
|
|
1044
|
-
|
1045
|
-
if (options.
|
1046
|
-
|
1018
|
+
var static_root = 'http://maps.googleapis.com/maps/api/staticmap';
|
1019
|
+
if (options.url){
|
1020
|
+
static_root = options.url;
|
1021
|
+
delete options.url;
|
1047
1022
|
}
|
1048
|
-
|
1023
|
+
static_root += '?';
|
1049
1024
|
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1025
|
+
var markers = options.markers;
|
1026
|
+
delete options.markers;
|
1027
|
+
if (!markers && options.marker){
|
1028
|
+
markers = [options.marker];
|
1029
|
+
delete options.marker;
|
1030
|
+
}
|
1053
1031
|
|
1054
|
-
|
1055
|
-
|
1032
|
+
var polyline = options.polyline;
|
1033
|
+
delete options.polyline;
|
1056
1034
|
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1035
|
+
/** Map options **/
|
1036
|
+
if (options.center){
|
1037
|
+
parameters.push('center=' + options.center);
|
1038
|
+
delete options.center;
|
1039
|
+
}
|
1040
|
+
else if (options.address){
|
1041
|
+
parameters.push('center=' + options.address);
|
1042
|
+
delete options.address;
|
1043
|
+
}
|
1044
|
+
else if (options.lat){
|
1045
|
+
parameters.push(['center=', options.lat, ',', options.lng].join(''));
|
1046
|
+
delete options.lat;
|
1047
|
+
delete options.lng;
|
1048
|
+
}
|
1049
|
+
else if (options.visible){
|
1050
|
+
var visible = encodeURI(options.visible.join('|'));
|
1051
|
+
parameters.push('visible=' + visible);
|
1052
|
+
}
|
1063
1053
|
|
1064
|
-
|
1065
|
-
|
1054
|
+
var size = options.size;
|
1055
|
+
if (size){
|
1056
|
+
if (size.join){
|
1057
|
+
size = size.join('x');
|
1066
1058
|
}
|
1059
|
+
delete options.size;
|
1060
|
+
}
|
1061
|
+
else {
|
1062
|
+
size = '630x300';
|
1063
|
+
}
|
1064
|
+
parameters.push('size=' + size);
|
1067
1065
|
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1066
|
+
if (!options.zoom){
|
1067
|
+
options.zoom = 15;
|
1068
|
+
}
|
1071
1069
|
|
1072
|
-
|
1070
|
+
var sensor = options.hasOwnProperty('sensor') ? !!options.sensor : true;
|
1071
|
+
delete options.sensor;
|
1072
|
+
parameters.push('sensor=' + sensor);
|
1073
1073
|
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
parameters.push('markers=' + encodeURI(marker));
|
1078
|
-
}
|
1079
|
-
// New marker without styles
|
1080
|
-
else {
|
1081
|
-
marker = parameters.pop() + encodeURI('|' + loc);
|
1082
|
-
parameters.push(marker);
|
1074
|
+
for (var param in options){
|
1075
|
+
if (options.hasOwnProperty(param)){
|
1076
|
+
parameters.push(param + '=' + options[param]);
|
1083
1077
|
}
|
1084
1078
|
}
|
1085
|
-
}
|
1086
1079
|
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
color = color.replace('#', '0x');
|
1080
|
+
/** Markers **/
|
1081
|
+
if (markers){
|
1082
|
+
var marker, loc;
|
1091
1083
|
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
if (
|
1096
|
-
|
1084
|
+
for (var i=0; data=markers[i]; i++){
|
1085
|
+
marker = [];
|
1086
|
+
|
1087
|
+
if (data.size && data.size !== 'normal'){
|
1088
|
+
marker.push('size:' + data.size);
|
1097
1089
|
}
|
1098
|
-
|
1099
|
-
|
1100
|
-
opacity += opacity;
|
1090
|
+
else if (data.icon){
|
1091
|
+
marker.push('icon:' + encodeURI(data.icon));
|
1101
1092
|
}
|
1102
1093
|
|
1103
|
-
|
1094
|
+
if (data.color){
|
1095
|
+
marker.push('color:' + data.color.replace('#', '0x'));
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
if (data.label){
|
1099
|
+
marker.push('label:' + data.label[0].toUpperCase());
|
1100
|
+
}
|
1101
|
+
|
1102
|
+
loc = (data.address ? data.address : data.lat + ',' + data.lng);
|
1103
|
+
|
1104
|
+
if (marker.length || i === 0){
|
1105
|
+
marker.push(loc);
|
1106
|
+
marker = marker.join('|');
|
1107
|
+
parameters.push('markers=' + encodeURI(marker));
|
1108
|
+
}
|
1109
|
+
// New marker without styles
|
1110
|
+
else {
|
1111
|
+
marker = parameters.pop() + encodeURI('|' + loc);
|
1112
|
+
parameters.push(marker);
|
1113
|
+
}
|
1104
1114
|
}
|
1105
1115
|
}
|
1106
|
-
return color;
|
1107
|
-
}
|
1108
1116
|
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1117
|
+
/** Polylines **/
|
1118
|
+
function parseColor(color, opacity){
|
1119
|
+
if (color[0] === '#'){
|
1120
|
+
color = color.replace('#', '0x');
|
1112
1121
|
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1122
|
+
if (opacity){
|
1123
|
+
opacity = parseFloat(opacity);
|
1124
|
+
opacity = Math.min(1, Math.max(opacity, 0));
|
1125
|
+
if (opacity === 0){
|
1126
|
+
return '0x00000000';
|
1127
|
+
}
|
1128
|
+
opacity = (opacity * 255).toString(16);
|
1129
|
+
if (opacity.length === 1){
|
1130
|
+
opacity += opacity;
|
1131
|
+
}
|
1116
1132
|
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1133
|
+
color = color.slice(0,8) + opacity;
|
1134
|
+
}
|
1135
|
+
}
|
1136
|
+
return color;
|
1120
1137
|
}
|
1121
1138
|
|
1122
|
-
if (
|
1123
|
-
|
1124
|
-
polyline
|
1125
|
-
}
|
1139
|
+
if (polyline){
|
1140
|
+
data = polyline;
|
1141
|
+
polyline = [];
|
1126
1142
|
|
1127
|
-
|
1128
|
-
|
1129
|
-
for (var j=0, pos; pos=path[j]; j++){
|
1130
|
-
polyline.push(pos.join(','));
|
1143
|
+
if (data.strokeWeight){
|
1144
|
+
polyline.push('weight:' + parseInt(data.strokeWeight, 10));
|
1131
1145
|
}
|
1132
|
-
}
|
1133
|
-
else {
|
1134
|
-
polyline.push('enc:' + path);
|
1135
|
-
}
|
1136
1146
|
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1147
|
+
if (data.strokeColor){
|
1148
|
+
var color = parseColor(data.strokeColor, data.strokeOpacity);
|
1149
|
+
polyline.push('color:' + color);
|
1150
|
+
}
|
1140
1151
|
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1152
|
+
if (data.fillColor){
|
1153
|
+
var fillcolor = parseColor(data.fillColor, data.fillOpacity);
|
1154
|
+
polyline.push('fillcolor:' + fillcolor);
|
1155
|
+
}
|
1144
1156
|
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
if (!google.maps.Polygon.prototype.getBounds) {
|
1151
|
-
google.maps.Polygon.prototype.getBounds = function(latLng) {
|
1152
|
-
var bounds = new google.maps.LatLngBounds();
|
1153
|
-
var paths = this.getPaths();
|
1154
|
-
var path;
|
1155
|
-
|
1156
|
-
for (var p = 0; p < paths.getLength(); p++) {
|
1157
|
-
path = paths.getAt(p);
|
1158
|
-
for (var i = 0; i < path.getLength(); i++) {
|
1159
|
-
bounds.extend(path.getAt(i));
|
1157
|
+
var path = data.path;
|
1158
|
+
if (path.join){
|
1159
|
+
for (var j=0, pos; pos=path[j]; j++){
|
1160
|
+
polyline.push(pos.join(','));
|
1161
|
+
}
|
1160
1162
|
}
|
1163
|
+
else {
|
1164
|
+
polyline.push('enc:' + path);
|
1165
|
+
}
|
1166
|
+
|
1167
|
+
polyline = polyline.join('|');
|
1168
|
+
parameters.push('path=' + encodeURI(polyline));
|
1161
1169
|
}
|
1162
1170
|
|
1163
|
-
|
1171
|
+
parameters = parameters.join('&');
|
1172
|
+
return static_root + parameters;
|
1164
1173
|
};
|
1165
|
-
}
|
1166
1174
|
|
1167
|
-
|
1168
|
-
|
1169
|
-
//
|
1170
|
-
|
1175
|
+
//==========================
|
1176
|
+
// Polygon containsLatLng
|
1177
|
+
// https://github.com/tparkin/Google-Maps-Point-in-Polygon
|
1178
|
+
// Poygon getBounds extension - google-maps-extensions
|
1179
|
+
// http://code.google.com/p/google-maps-extensions/source/browse/google.maps.Polygon.getBounds.js
|
1180
|
+
if (!google.maps.Polygon.prototype.getBounds) {
|
1181
|
+
google.maps.Polygon.prototype.getBounds = function(latLng) {
|
1182
|
+
var bounds = new google.maps.LatLngBounds();
|
1183
|
+
var paths = this.getPaths();
|
1184
|
+
var path;
|
1185
|
+
|
1186
|
+
for (var p = 0; p < paths.getLength(); p++) {
|
1187
|
+
path = paths.getAt(p);
|
1188
|
+
for (var i = 0; i < path.getLength(); i++) {
|
1189
|
+
bounds.extend(path.getAt(i));
|
1190
|
+
}
|
1191
|
+
}
|
1171
1192
|
|
1172
|
-
|
1173
|
-
|
1193
|
+
return bounds;
|
1194
|
+
};
|
1174
1195
|
}
|
1175
1196
|
|
1176
|
-
//
|
1177
|
-
|
1197
|
+
// Polygon containsLatLng - method to determine if a latLng is within a polygon
|
1198
|
+
google.maps.Polygon.prototype.containsLatLng = function(latLng) {
|
1199
|
+
// Exclude points outside of bounds as there is no way they are in the poly
|
1200
|
+
var bounds = this.getBounds();
|
1178
1201
|
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
var numPoints = path.getLength();
|
1183
|
-
var j = numPoints - 1;
|
1202
|
+
if (bounds !== null && !bounds.contains(latLng)) {
|
1203
|
+
return false;
|
1204
|
+
}
|
1184
1205
|
|
1185
|
-
|
1186
|
-
|
1187
|
-
var vertex2 = path.getAt(j);
|
1206
|
+
// Raycast point in polygon method
|
1207
|
+
var inPoly = false;
|
1188
1208
|
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1209
|
+
var numPaths = this.getPaths().getLength();
|
1210
|
+
for (var p = 0; p < numPaths; p++) {
|
1211
|
+
var path = this.getPaths().getAt(p);
|
1212
|
+
var numPoints = path.getLength();
|
1213
|
+
var j = numPoints - 1;
|
1214
|
+
|
1215
|
+
for (var i = 0; i < numPoints; i++) {
|
1216
|
+
var vertex1 = path.getAt(i);
|
1217
|
+
var vertex2 = path.getAt(j);
|
1218
|
+
|
1219
|
+
if (vertex1.lng() < latLng.lng() && vertex2.lng() >= latLng.lng() || vertex2.lng() < latLng.lng() && vertex1.lng() >= latLng.lng()) {
|
1220
|
+
if (vertex1.lat() + (latLng.lng() - vertex1.lng()) / (vertex2.lng() - vertex1.lng()) * (vertex2.lat() - vertex1.lat()) < latLng.lat()) {
|
1221
|
+
inPoly = !inPoly;
|
1222
|
+
}
|
1192
1223
|
}
|
1193
|
-
}
|
1194
1224
|
|
1195
|
-
|
1225
|
+
j = i;
|
1226
|
+
}
|
1196
1227
|
}
|
1197
|
-
}
|
1198
1228
|
|
1199
|
-
|
1200
|
-
|
1229
|
+
return inPoly;
|
1230
|
+
};
|
1201
1231
|
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1232
|
+
google.maps.LatLngBounds.prototype.containsLatLng = function(latLng) {
|
1233
|
+
return this.contains(latLng);
|
1234
|
+
};
|
1205
1235
|
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1236
|
+
google.maps.Marker.prototype.setFences = function(fences) {
|
1237
|
+
this.fences = fences;
|
1238
|
+
};
|
1209
1239
|
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1240
|
+
google.maps.Marker.prototype.addFence = function(fence) {
|
1241
|
+
this.fences.push(fence);
|
1242
|
+
};
|
1213
1243
|
|
1214
|
-
|
1215
|
-
}(this));
|
1244
|
+
return GMaps;
|
1245
|
+
}(this));
|
1216
1246
|
|
1217
1247
|
var arrayToLatLng = function(coords) {
|
1218
1248
|
return new google.maps.LatLng(coords[0], coords[1]);
|
1219
1249
|
}
|
1220
1250
|
|
1221
|
-
var extend_object = function(obj, new_obj) {
|
1222
|
-
|
1251
|
+
var extend_object = function(obj, new_obj) {
|
1252
|
+
if(obj === new_obj) return obj;
|
1223
1253
|
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1254
|
+
for(var name in new_obj){
|
1255
|
+
obj[name] = new_obj[name];
|
1256
|
+
}
|
1227
1257
|
|
1228
|
-
|
1229
|
-
};
|
1258
|
+
return obj;
|
1259
|
+
};
|
1230
1260
|
|
1231
|
-
var array_map = function(array, callback) {
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1261
|
+
var array_map = function(array, callback) {
|
1262
|
+
if (Array.prototype.map && array.map === Array.prototype.map) {
|
1263
|
+
return array.map(callback);
|
1264
|
+
} else {
|
1265
|
+
var array_return = [];
|
1236
1266
|
|
1237
|
-
|
1267
|
+
var array_length = array.length;
|
1238
1268
|
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1269
|
+
for(var i = 0; i < array_length; i++) {
|
1270
|
+
array_return.push(callback(array[i]));
|
1271
|
+
}
|
1242
1272
|
|
1243
|
-
|
1273
|
+
return array_return;
|
1274
|
+
}
|
1244
1275
|
}
|
1276
|
+
|
1245
1277
|
}
|