gmapsjs 0.2.13 → 0.2.30
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 +473 -190
- data/lib/gmapsjs/version.rb +1 -1
- metadata +5 -5
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* GMaps.js v0.2.
|
2
|
+
* GMaps.js v0.2.30
|
3
3
|
* http://hpneo.github.com/gmaps/
|
4
4
|
*
|
5
5
|
* Copyright 2012, Gustavo Leon
|
@@ -24,13 +24,18 @@ if(window.google && window.google.maps){
|
|
24
24
|
|
25
25
|
var GMaps = function(options) {
|
26
26
|
var self = this;
|
27
|
+
var events_that_hide_context_menu = ['bounds_changed', 'center_changed', 'click', 'dblclick', 'drag', 'dragend', 'dragstart', 'idle', 'maptypeid_changed', 'projection_changed', 'resize', 'tilesloaded', 'zoom_changed'];
|
28
|
+
var events_that_doesnt_hide_context_menu = ['mousemove', 'mouseout', 'mouseover'];
|
29
|
+
|
27
30
|
window.context_menu = {};
|
28
31
|
|
29
|
-
if(typeof(options.div)
|
30
|
-
this.
|
31
|
-
}else{
|
32
|
-
|
33
|
-
|
32
|
+
if (typeof(options.el) === 'string' || typeof(options.div) === 'string') {
|
33
|
+
this.el = getElementById(options.el || options.div, options.context);
|
34
|
+
} else {
|
35
|
+
this.el = options.el || options.div;
|
36
|
+
};
|
37
|
+
this.el.style.width = options.width || this.el.scrollWidth || this.el.offsetWidth;
|
38
|
+
this.el.style.height = options.height || this.el.scrollHeight || this.el.offsetHeight;
|
34
39
|
|
35
40
|
this.controls = [];
|
36
41
|
this.overlays = [];
|
@@ -41,9 +46,11 @@ if(window.google && window.google.maps){
|
|
41
46
|
this.routes = [];
|
42
47
|
this.polygons = [];
|
43
48
|
this.infoWindow = null;
|
44
|
-
this.
|
49
|
+
this.overlay_el = null;
|
45
50
|
this.zoom = options.zoom || 15;
|
46
51
|
|
52
|
+
var markerClusterer = options.markerClusterer;
|
53
|
+
|
47
54
|
//'Hybrid', 'Roadmap', 'Satellite' or 'Terrain'
|
48
55
|
var mapType;
|
49
56
|
|
@@ -56,12 +63,13 @@ if(window.google && window.google.maps){
|
|
56
63
|
|
57
64
|
var map_center = new google.maps.LatLng(options.lat, options.lng);
|
58
65
|
|
59
|
-
delete options.
|
66
|
+
delete options.el;
|
60
67
|
delete options.lat;
|
61
68
|
delete options.lng;
|
62
69
|
delete options.mapType;
|
63
70
|
delete options.width;
|
64
71
|
delete options.height;
|
72
|
+
delete options.markerClusterer;
|
65
73
|
|
66
74
|
var zoomControlOpt = options.zoomControlOpt || {
|
67
75
|
style: 'DEFAULT',
|
@@ -77,10 +85,15 @@ if(window.google && window.google.maps){
|
|
77
85
|
streetViewControl = options.streetViewControl || true,
|
78
86
|
overviewMapControl = overviewMapControl || true;
|
79
87
|
|
88
|
+
var map_options = {};
|
89
|
+
|
80
90
|
var map_base_options = {
|
81
91
|
zoom: this.zoom,
|
82
92
|
center: map_center,
|
83
|
-
mapTypeId: mapType
|
93
|
+
mapTypeId: mapType
|
94
|
+
};
|
95
|
+
|
96
|
+
var map_controls_options = {
|
84
97
|
panControl: panControl,
|
85
98
|
zoomControl: zoomControl,
|
86
99
|
zoomControlOptions: {
|
@@ -91,76 +104,92 @@ if(window.google && window.google.maps){
|
|
91
104
|
scaleControl: scaleControl,
|
92
105
|
streetViewControl: streetViewControl,
|
93
106
|
overviewMapControl: overviewMapControl
|
94
|
-
}
|
107
|
+
}
|
108
|
+
|
109
|
+
if(options.disableDefaultUI != true)
|
110
|
+
map_base_options = extend_object(map_base_options, map_controls_options);
|
111
|
+
|
112
|
+
map_options = extend_object(map_base_options, options);
|
95
113
|
|
96
|
-
var
|
114
|
+
for(var i = 0; i < events_that_hide_context_menu.length; i++) {
|
115
|
+
delete map_options[events_that_hide_context_menu[i]];
|
116
|
+
}
|
117
|
+
|
118
|
+
for(var i = 0; i < events_that_doesnt_hide_context_menu.length; i++) {
|
119
|
+
delete map_options[events_that_doesnt_hide_context_menu[i]];
|
120
|
+
}
|
97
121
|
|
98
|
-
this.map = new google.maps.Map(this.
|
122
|
+
this.map = new google.maps.Map(this.el, map_options);
|
123
|
+
|
124
|
+
if(markerClusterer) {
|
125
|
+
this.markerClusterer = markerClusterer.apply(this, [this.map]);
|
126
|
+
}
|
99
127
|
|
100
128
|
// Context menus
|
101
129
|
var buildContextMenuHTML = function(control, e) {
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
}
|
130
|
+
var html = '';
|
131
|
+
var options = window.context_menu[control];
|
132
|
+
for (var i in options){
|
133
|
+
if (options.hasOwnProperty(i)){
|
134
|
+
var option = options[i];
|
135
|
+
html += '<li><a id="' + control + '_' + i + '" href="#">' +
|
136
|
+
option.title + '</a></li>';
|
110
137
|
}
|
138
|
+
}
|
111
139
|
|
112
|
-
|
140
|
+
if(!getElementById('gmaps_context_menu')) return;
|
113
141
|
|
114
|
-
|
115
|
-
|
142
|
+
var context_menu_element = getElementById('gmaps_context_menu');
|
143
|
+
context_menu_element.innerHTML = html;
|
116
144
|
|
117
|
-
|
145
|
+
var context_menu_items = context_menu_element.getElementsByTagName('a');
|
118
146
|
|
119
|
-
|
147
|
+
var context_menu_items_count = context_menu_items.length;
|
120
148
|
|
121
|
-
|
122
|
-
|
149
|
+
for(var i = 0; i < context_menu_items_count; i++){
|
150
|
+
var context_menu_item = context_menu_items[i];
|
123
151
|
|
124
|
-
|
125
|
-
|
152
|
+
var assign_menu_item_action = function(ev){
|
153
|
+
ev.preventDefault();
|
126
154
|
|
127
|
-
|
128
|
-
|
129
|
-
|
155
|
+
options[this.id.replace(control + '_', '')].action.apply(self, [e]);
|
156
|
+
self.hideContextMenu();
|
157
|
+
};
|
130
158
|
|
131
|
-
|
132
|
-
|
133
|
-
|
159
|
+
google.maps.event.clearListeners(context_menu_item, 'click');
|
160
|
+
google.maps.event.addDomListenerOnce(context_menu_item, 'click', assign_menu_item_action, false);
|
161
|
+
}
|
134
162
|
|
135
|
-
|
136
|
-
|
163
|
+
var left = self.el.offsetLeft + e.pixel.x - 15;
|
164
|
+
var top = self.el.offsetTop + e.pixel.y - 15;
|
137
165
|
|
138
|
-
|
139
|
-
|
166
|
+
context_menu_element.style.left = left + "px";
|
167
|
+
context_menu_element.style.top = top + "px";
|
140
168
|
|
141
|
-
|
142
|
-
|
169
|
+
context_menu_element.style.display = 'block';
|
170
|
+
};
|
143
171
|
|
144
172
|
var buildContextMenu = function(control, e) {
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
buildContextMenuHTML(control, e);
|
155
|
-
};
|
156
|
-
}
|
157
|
-
else {
|
173
|
+
if (control === 'marker') {
|
174
|
+
e.pixel = {};
|
175
|
+
var overlay = new google.maps.OverlayView();
|
176
|
+
overlay.setMap(self.map);
|
177
|
+
overlay.draw = function() {
|
178
|
+
var projection = overlay.getProjection();
|
179
|
+
var position = e.marker.getPosition();
|
180
|
+
e.pixel = projection.fromLatLngToContainerPixel(position);
|
181
|
+
|
158
182
|
buildContextMenuHTML(control, e);
|
159
|
-
}
|
160
|
-
}
|
183
|
+
};
|
184
|
+
}
|
185
|
+
else {
|
186
|
+
buildContextMenuHTML(control, e);
|
187
|
+
}
|
188
|
+
};
|
161
189
|
|
162
190
|
this.setContextMenu = function(options) {
|
163
191
|
window.context_menu[options.control] = {};
|
192
|
+
|
164
193
|
for (var i in options.options){
|
165
194
|
if (options.options.hasOwnProperty(i)){
|
166
195
|
var option = options.options[i];
|
@@ -170,7 +199,9 @@ if(window.google && window.google.maps){
|
|
170
199
|
};
|
171
200
|
}
|
172
201
|
}
|
202
|
+
|
173
203
|
var ul = doc.createElement('ul');
|
204
|
+
|
174
205
|
ul.id = 'gmaps_context_menu';
|
175
206
|
ul.style.display = 'none';
|
176
207
|
ul.style.position = 'absolute';
|
@@ -201,33 +232,32 @@ if(window.google && window.google.maps){
|
|
201
232
|
|
202
233
|
//Events
|
203
234
|
|
204
|
-
var
|
205
|
-
|
235
|
+
var setupListener = function(object, name) {
|
236
|
+
google.maps.event.addListener(object, name, function(e){
|
237
|
+
if(e == undefined) {
|
238
|
+
e = this;
|
239
|
+
}
|
206
240
|
|
207
|
-
|
208
|
-
(function(object, name) {
|
209
|
-
google.maps.event.addListener(object, name, function(e){
|
210
|
-
if(e == undefined)
|
211
|
-
e = this;
|
241
|
+
options[name].apply(this, [e]);
|
212
242
|
|
213
|
-
|
214
|
-
|
243
|
+
self.hideContextMenu();
|
244
|
+
});
|
245
|
+
}
|
215
246
|
|
216
|
-
|
217
|
-
|
218
|
-
|
247
|
+
for (var ev = 0; ev < events_that_hide_context_menu.length; ev++) {
|
248
|
+
var name = events_that_hide_context_menu[ev];
|
249
|
+
|
250
|
+
if (name in options) {
|
251
|
+
setupListener(this.map, name);
|
252
|
+
}
|
219
253
|
}
|
220
254
|
|
221
255
|
for (var ev = 0; ev < events_that_doesnt_hide_context_menu.length; ev++) {
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
if (options[name])
|
228
|
-
options[name].apply(this, [e]);
|
229
|
-
});
|
230
|
-
})(this.map, events_that_doesnt_hide_context_menu[ev]);
|
256
|
+
var name = events_that_doesnt_hide_context_menu[ev];
|
257
|
+
|
258
|
+
if (name in options) {
|
259
|
+
setupListener(this.map, name);
|
260
|
+
}
|
231
261
|
}
|
232
262
|
|
233
263
|
google.maps.event.addListener(this.map, 'rightclick', function(e) {
|
@@ -235,7 +265,9 @@ if(window.google && window.google.maps){
|
|
235
265
|
options.rightclick.apply(this, [e]);
|
236
266
|
}
|
237
267
|
|
238
|
-
|
268
|
+
if(window.context_menu['map'] != undefined) {
|
269
|
+
buildContextMenu('map', e);
|
270
|
+
}
|
239
271
|
});
|
240
272
|
|
241
273
|
this.refresh = function() {
|
@@ -250,10 +282,10 @@ if(window.google && window.google.maps){
|
|
250
282
|
latLngs.push(this.markers[i].getPosition());
|
251
283
|
}
|
252
284
|
|
253
|
-
this.
|
285
|
+
this.fitLatLngBounds(latLngs);
|
254
286
|
};
|
255
287
|
|
256
|
-
this.
|
288
|
+
this.fitLatLngBounds = function(latLngs) {
|
257
289
|
var total = latLngs.length;
|
258
290
|
var bounds = new google.maps.LatLngBounds();
|
259
291
|
|
@@ -272,8 +304,8 @@ if(window.google && window.google.maps){
|
|
272
304
|
}
|
273
305
|
};
|
274
306
|
|
275
|
-
this.
|
276
|
-
return this.
|
307
|
+
this.getElement = function() {
|
308
|
+
return this.el;
|
277
309
|
};
|
278
310
|
|
279
311
|
this.zoomIn = function(value) {
|
@@ -310,11 +342,20 @@ if(window.google && window.google.maps){
|
|
310
342
|
control.style.fontSize = '13px';
|
311
343
|
control.style.boxShadow = 'rgba(0, 0, 0, 0.398438) 0px 2px 4px';
|
312
344
|
|
313
|
-
for(var option in options.style)
|
345
|
+
for(var option in options.style)
|
314
346
|
control.style[option] = options.style[option];
|
347
|
+
|
348
|
+
if(options.id) {
|
349
|
+
control.id = options.id;
|
350
|
+
}
|
351
|
+
|
352
|
+
if(options.classes) {
|
353
|
+
control.className = options.classes;
|
315
354
|
}
|
316
355
|
|
317
|
-
|
356
|
+
if(options.content) {
|
357
|
+
control.innerHTML = options.content;
|
358
|
+
}
|
318
359
|
|
319
360
|
for (var ev in options.events) {
|
320
361
|
(function(object, name) {
|
@@ -393,16 +434,16 @@ if(window.google && window.google.maps){
|
|
393
434
|
})(marker, marker_events[ev]);
|
394
435
|
}
|
395
436
|
|
396
|
-
for (var ev = 0; ev <
|
397
|
-
(function(object, name) {
|
437
|
+
for (var ev = 0; ev < marker_events_with_mouse.length; ev++) {
|
438
|
+
(function(map, object, name) {
|
398
439
|
google.maps.event.addListener(object, name, function(me){
|
399
440
|
if(!me.pixel){
|
400
|
-
me.pixel =
|
441
|
+
me.pixel = map.getProjection().fromLatLngToPoint(me.latLng)
|
401
442
|
}
|
402
443
|
if (options[name])
|
403
444
|
options[name].apply(this, [me]);
|
404
445
|
});
|
405
|
-
})(marker, marker_events_with_mouse[ev]);
|
446
|
+
})(this.map, marker, marker_events_with_mouse[ev]);
|
406
447
|
}
|
407
448
|
|
408
449
|
google.maps.event.addListener(marker, 'click', function() {
|
@@ -418,6 +459,18 @@ if(window.google && window.google.maps){
|
|
418
459
|
}
|
419
460
|
});
|
420
461
|
|
462
|
+
google.maps.event.addListener(marker, 'rightclick', function(e) {
|
463
|
+
e.marker = this;
|
464
|
+
|
465
|
+
if (options.rightclick) {
|
466
|
+
options.rightclick.apply(this, [e]);
|
467
|
+
}
|
468
|
+
|
469
|
+
if (window.context_menu['marker'] != undefined) {
|
470
|
+
buildContextMenu('marker', e);
|
471
|
+
}
|
472
|
+
});
|
473
|
+
|
421
474
|
if (options.dragend || marker.fences) {
|
422
475
|
google.maps.event.addListener(marker, 'dragend', function() {
|
423
476
|
if (marker.fences) {
|
@@ -436,16 +489,28 @@ if(window.google && window.google.maps){
|
|
436
489
|
};
|
437
490
|
|
438
491
|
this.addMarker = function(options) {
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
return marker;
|
492
|
+
var marker;
|
493
|
+
if(options.hasOwnProperty('gm_accessors_')) {
|
494
|
+
// Native google.maps.Marker object
|
495
|
+
marker = options;
|
445
496
|
}
|
446
497
|
else {
|
447
|
-
|
498
|
+
if ((options.hasOwnProperty('lat') && options.hasOwnProperty('lng')) || options.position) {
|
499
|
+
marker = this.createMarker(options);
|
500
|
+
}
|
501
|
+
else {
|
502
|
+
throw 'No latitude or longitude defined';
|
503
|
+
}
|
448
504
|
}
|
505
|
+
|
506
|
+
marker.setMap(this.map);
|
507
|
+
|
508
|
+
if(this.markerClusterer)
|
509
|
+
this.markerClusterer.addMarker(marker);
|
510
|
+
|
511
|
+
this.markers.push(marker);
|
512
|
+
|
513
|
+
return marker;
|
449
514
|
};
|
450
515
|
|
451
516
|
this.addMarkers = function(array) {
|
@@ -463,6 +528,19 @@ if(window.google && window.google.maps){
|
|
463
528
|
}
|
464
529
|
};
|
465
530
|
|
531
|
+
this.removeMarker = function(marker) {
|
532
|
+
for(var i = 0; i < this.markers.length; i++) {
|
533
|
+
if(this.markers[i] === marker) {
|
534
|
+
this.markers[i].setMap(null);
|
535
|
+
this.markers.splice(i, 1);
|
536
|
+
|
537
|
+
break;
|
538
|
+
}
|
539
|
+
}
|
540
|
+
|
541
|
+
return marker;
|
542
|
+
};
|
543
|
+
|
466
544
|
this.removeMarkers = function(collection) {
|
467
545
|
var collection = (collection || this.markers);
|
468
546
|
|
@@ -482,6 +560,7 @@ if(window.google && window.google.maps){
|
|
482
560
|
};
|
483
561
|
|
484
562
|
// Overlays
|
563
|
+
|
485
564
|
this.drawOverlay = function(options) {
|
486
565
|
var overlay = new google.maps.OverlayView();
|
487
566
|
overlay.setMap(self.map);
|
@@ -492,21 +571,21 @@ if(window.google && window.google.maps){
|
|
492
571
|
auto_show = options.auto_show;
|
493
572
|
|
494
573
|
overlay.onAdd = function() {
|
495
|
-
var
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
574
|
+
var el = doc.createElement('div');
|
575
|
+
el.style.borderStyle = "none";
|
576
|
+
el.style.borderWidth = "0px";
|
577
|
+
el.style.position = "absolute";
|
578
|
+
el.style.zIndex = 100;
|
579
|
+
el.innerHTML = options.content;
|
501
580
|
|
502
|
-
overlay.
|
581
|
+
overlay.el = el;
|
503
582
|
|
504
583
|
var panes = this.getPanes();
|
505
584
|
if (!options.layer) {
|
506
585
|
options.layer = 'overlayLayer';
|
507
586
|
}
|
508
587
|
var overlayLayer = panes[options.layer];
|
509
|
-
overlayLayer.appendChild(
|
588
|
+
overlayLayer.appendChild(el);
|
510
589
|
|
511
590
|
var stop_overlay_events = ['contextmenu', 'DOMMouseScroll', 'dblclick', 'mousedown'];
|
512
591
|
|
@@ -521,7 +600,7 @@ if(window.google && window.google.maps){
|
|
521
600
|
e.stopPropagation();
|
522
601
|
}
|
523
602
|
});
|
524
|
-
})(
|
603
|
+
})(el, stop_overlay_events[ev]);
|
525
604
|
}
|
526
605
|
|
527
606
|
google.maps.event.trigger(this, 'ready');
|
@@ -534,54 +613,54 @@ if(window.google && window.google.maps){
|
|
534
613
|
options.horizontalOffset = options.horizontalOffset || 0;
|
535
614
|
options.verticalOffset = options.verticalOffset || 0;
|
536
615
|
|
537
|
-
var
|
538
|
-
var content =
|
616
|
+
var el = overlay.el;
|
617
|
+
var content = el.children[0];
|
539
618
|
|
540
619
|
var content_height = content.clientHeight;
|
541
620
|
var content_width = content.clientWidth;
|
542
621
|
|
543
622
|
switch (options.verticalAlign) {
|
544
623
|
case 'top':
|
545
|
-
|
624
|
+
el.style.top = (pixel.y - content_height + options.verticalOffset) + 'px';
|
546
625
|
break;
|
547
626
|
default:
|
548
627
|
case 'middle':
|
549
|
-
|
628
|
+
el.style.top = (pixel.y - (content_height / 2) + options.verticalOffset) + 'px';
|
550
629
|
break;
|
551
630
|
case 'bottom':
|
552
|
-
|
631
|
+
el.style.top = (pixel.y + options.verticalOffset) + 'px';
|
553
632
|
break;
|
554
633
|
}
|
555
634
|
|
556
635
|
switch (options.horizontalAlign) {
|
557
636
|
case 'left':
|
558
|
-
|
637
|
+
el.style.left = (pixel.x - content_width + options.horizontalOffset) + 'px';
|
559
638
|
break;
|
560
639
|
default:
|
561
640
|
case 'center':
|
562
|
-
|
641
|
+
el.style.left = (pixel.x - (content_width / 2) + options.horizontalOffset) + 'px';
|
563
642
|
break;
|
564
643
|
case 'right':
|
565
|
-
|
644
|
+
el.style.left = (pixel.x + options.horizontalOffset) + 'px';
|
566
645
|
break;
|
567
646
|
}
|
568
647
|
|
569
|
-
|
648
|
+
el.style.display = auto_show ? 'block' : 'none';
|
570
649
|
|
571
650
|
if(!auto_show){
|
572
|
-
options.show.apply(this, [
|
651
|
+
options.show.apply(this, [el]);
|
573
652
|
}
|
574
653
|
};
|
575
654
|
|
576
655
|
overlay.onRemove = function() {
|
577
|
-
var
|
656
|
+
var el = overlay.el;
|
578
657
|
|
579
658
|
if(options.remove){
|
580
|
-
options.remove.apply(this, [
|
659
|
+
options.remove.apply(this, [el]);
|
581
660
|
}
|
582
661
|
else{
|
583
|
-
overlay.
|
584
|
-
overlay.
|
662
|
+
overlay.el.parentNode.removeChild(overlay.el);
|
663
|
+
overlay.el = null;
|
585
664
|
}
|
586
665
|
};
|
587
666
|
|
@@ -590,7 +669,14 @@ if(window.google && window.google.maps){
|
|
590
669
|
};
|
591
670
|
|
592
671
|
this.removeOverlay = function(overlay) {
|
593
|
-
|
672
|
+
for(var i = 0; i < this.overlays.length; i++) {
|
673
|
+
if(this.overlays[i] === overlay) {
|
674
|
+
this.overlays[i].setMap(null);
|
675
|
+
this.overlays.splice(i, 1);
|
676
|
+
|
677
|
+
break;
|
678
|
+
}
|
679
|
+
}
|
594
680
|
};
|
595
681
|
|
596
682
|
this.removeOverlays = function() {
|
@@ -600,12 +686,7 @@ if(window.google && window.google.maps){
|
|
600
686
|
self.overlays = [];
|
601
687
|
};
|
602
688
|
|
603
|
-
|
604
|
-
for (var i=0, item; item=self.polylines[i]; i++){
|
605
|
-
item.setMap(null);
|
606
|
-
}
|
607
|
-
self.polylines = [];
|
608
|
-
};
|
689
|
+
// Geometry
|
609
690
|
|
610
691
|
this.drawPolyline = function(options) {
|
611
692
|
var path = [];
|
@@ -622,14 +703,31 @@ if(window.google && window.google.maps){
|
|
622
703
|
}
|
623
704
|
}
|
624
705
|
|
625
|
-
var
|
706
|
+
var polyline_options = {
|
626
707
|
map: this.map,
|
627
708
|
path: path,
|
628
709
|
strokeColor: options.strokeColor,
|
629
710
|
strokeOpacity: options.strokeOpacity,
|
630
711
|
strokeWeight: options.strokeWeight,
|
631
|
-
geodesic: options.geodesic
|
632
|
-
|
712
|
+
geodesic: options.geodesic,
|
713
|
+
clickable: true,
|
714
|
+
editable: false,
|
715
|
+
visible: true
|
716
|
+
};
|
717
|
+
|
718
|
+
if(options.hasOwnProperty("clickable"))
|
719
|
+
polyline_options.clickable = options.clickable;
|
720
|
+
|
721
|
+
if(options.hasOwnProperty("editable"))
|
722
|
+
polyline_options.editable = options.editable;
|
723
|
+
|
724
|
+
if(options.hasOwnProperty("icons"))
|
725
|
+
polyline_options.icons = options.icons;
|
726
|
+
|
727
|
+
if(options.hasOwnProperty("zIndex"))
|
728
|
+
polyline_options.zIndex = options.zIndex;
|
729
|
+
|
730
|
+
var polyline = new google.maps.Polyline(polyline_options);
|
633
731
|
|
634
732
|
var polyline_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
|
635
733
|
|
@@ -647,6 +745,24 @@ if(window.google && window.google.maps){
|
|
647
745
|
return polyline;
|
648
746
|
};
|
649
747
|
|
748
|
+
this.removePolyline = function(polyline) {
|
749
|
+
for(var i = 0; i < this.polylines.length; i++) {
|
750
|
+
if(this.polylines[i] === polyline) {
|
751
|
+
this.polylines[i].setMap(null);
|
752
|
+
this.polylines.splice(i, 1);
|
753
|
+
|
754
|
+
break;
|
755
|
+
}
|
756
|
+
}
|
757
|
+
};
|
758
|
+
|
759
|
+
this.removePolylines = function() {
|
760
|
+
for (var i=0, item; item=self.polylines[i]; i++){
|
761
|
+
item.setMap(null);
|
762
|
+
}
|
763
|
+
self.polylines = [];
|
764
|
+
};
|
765
|
+
|
650
766
|
this.drawCircle = function(options) {
|
651
767
|
options = extend_object({
|
652
768
|
map: this.map,
|
@@ -697,21 +813,30 @@ if(window.google && window.google.maps){
|
|
697
813
|
});
|
698
814
|
})(polygon, polygon_events[ev]);
|
699
815
|
}
|
700
|
-
|
816
|
+
|
701
817
|
this.polygons.push(polygon);
|
702
|
-
|
818
|
+
|
703
819
|
return polygon;
|
704
820
|
};
|
705
821
|
|
706
822
|
this.drawPolygon = function(options) {
|
823
|
+
var useGeoJSON = false;
|
824
|
+
if(options.hasOwnProperty("useGeoJSON"))
|
825
|
+
useGeoJSON = options.useGeoJSON;
|
826
|
+
|
827
|
+
delete options.useGeoJSON;
|
828
|
+
|
707
829
|
options = extend_object({
|
708
830
|
map: this.map
|
709
831
|
}, options);
|
710
832
|
|
833
|
+
if(useGeoJSON == false)
|
834
|
+
options.paths = [options.paths.slice(0)];
|
835
|
+
|
711
836
|
if(options.paths.length > 0) {
|
712
|
-
|
713
|
-
|
714
|
-
|
837
|
+
if(options.paths[0].length > 0) {
|
838
|
+
options.paths = array_flat(array_map(options.paths, arrayToLatLng, useGeoJSON));
|
839
|
+
}
|
715
840
|
}
|
716
841
|
|
717
842
|
var polygon = new google.maps.Polygon(options);
|
@@ -732,7 +857,16 @@ if(window.google && window.google.maps){
|
|
732
857
|
return polygon;
|
733
858
|
};
|
734
859
|
|
735
|
-
this.removePolygon =
|
860
|
+
this.removePolygon = function(polygon) {
|
861
|
+
for(var i = 0; i < this.polygons.length; i++) {
|
862
|
+
if(this.polygons[i] === polygon) {
|
863
|
+
this.polygons[i].setMap(null);
|
864
|
+
this.polygons.splice(i, 1);
|
865
|
+
|
866
|
+
break;
|
867
|
+
}
|
868
|
+
}
|
869
|
+
};
|
736
870
|
|
737
871
|
this.removePolygons = function() {
|
738
872
|
for (var i=0, item; item=self.polygons[i]; i++){
|
@@ -741,6 +875,8 @@ if(window.google && window.google.maps){
|
|
741
875
|
self.polygons = [];
|
742
876
|
};
|
743
877
|
|
878
|
+
// Fusion Tables
|
879
|
+
|
744
880
|
this.getFromFusionTables = function(options) {
|
745
881
|
var events = options.events;
|
746
882
|
|
@@ -770,6 +906,8 @@ if(window.google && window.google.maps){
|
|
770
906
|
return layer;
|
771
907
|
};
|
772
908
|
|
909
|
+
// KML
|
910
|
+
|
773
911
|
this.getFromKML = function(options) {
|
774
912
|
var url = options.url;
|
775
913
|
var events = options.events;
|
@@ -801,7 +939,8 @@ if(window.google && window.google.maps){
|
|
801
939
|
return layer;
|
802
940
|
};
|
803
941
|
|
804
|
-
//
|
942
|
+
// Routes
|
943
|
+
|
805
944
|
var travelMode, unitSystem;
|
806
945
|
this.getRoutes = function(options) {
|
807
946
|
switch (options.travelMode) {
|
@@ -873,7 +1012,7 @@ if(window.google && window.google.maps){
|
|
873
1012
|
|
874
1013
|
if(options.locations.length > 0) {
|
875
1014
|
if(options.locations[0].length > 0) {
|
876
|
-
options.locations = array_map(options.locations, arrayToLatLng);
|
1015
|
+
options.locations = array_flat(array_map([options.locations], arrayToLatLng, false));
|
877
1016
|
}
|
878
1017
|
}
|
879
1018
|
|
@@ -915,7 +1054,8 @@ if(window.google && window.google.maps){
|
|
915
1054
|
origin: options.origin,
|
916
1055
|
destination: options.destination,
|
917
1056
|
travelMode: options.travelMode,
|
918
|
-
waypoints
|
1057
|
+
waypoints: options.waypoints,
|
1058
|
+
unitSystem: options.unitSystem,
|
919
1059
|
callback: function(e) {
|
920
1060
|
if (e.length > 0) {
|
921
1061
|
self.drawPolyline({
|
@@ -1031,6 +1171,7 @@ if(window.google && window.google.maps){
|
|
1031
1171
|
};
|
1032
1172
|
|
1033
1173
|
// Geofence
|
1174
|
+
|
1034
1175
|
this.checkGeofence = function(lat, lng, fence) {
|
1035
1176
|
return fence.containsLatLng(new google.maps.LatLng(lat, lng));
|
1036
1177
|
};
|
@@ -1046,7 +1187,8 @@ if(window.google && window.google.maps){
|
|
1046
1187
|
}
|
1047
1188
|
};
|
1048
1189
|
|
1049
|
-
//
|
1190
|
+
// Layers
|
1191
|
+
|
1050
1192
|
this.addLayer = function(layerName, options) {
|
1051
1193
|
//var default_layers = ['weather', 'clouds', 'traffic', 'transit', 'bicycling', 'panoramio', 'places'];
|
1052
1194
|
options = options || {};
|
@@ -1126,18 +1268,19 @@ if(window.google && window.google.maps){
|
|
1126
1268
|
}
|
1127
1269
|
};
|
1128
1270
|
|
1129
|
-
//remove layers
|
1130
1271
|
this.removeLayer = function(layerName) {
|
1131
1272
|
if(this.singleLayers[layerName] !== undefined) {
|
1132
1273
|
this.singleLayers[layerName].setMap(null);
|
1133
1274
|
delete this.singleLayers[layerName];
|
1134
1275
|
}
|
1135
1276
|
};
|
1277
|
+
|
1278
|
+
// Static Maps
|
1136
1279
|
|
1137
1280
|
this.toImage = function(options) {
|
1138
1281
|
var options = options || {};
|
1139
1282
|
var static_map_options = {};
|
1140
|
-
static_map_options['size'] = options['size'] || [this.
|
1283
|
+
static_map_options['size'] = options['size'] || [this.el.clientWidth, this.el.clientHeight];
|
1141
1284
|
static_map_options['lat'] = this.getCenter().lat();
|
1142
1285
|
static_map_options['lng'] = this.getCenter().lng();
|
1143
1286
|
|
@@ -1163,6 +1306,97 @@ if(window.google && window.google.maps){
|
|
1163
1306
|
return GMaps.staticMapURL(static_map_options);
|
1164
1307
|
};
|
1165
1308
|
|
1309
|
+
// Map Types
|
1310
|
+
|
1311
|
+
this.addMapType = function(mapTypeId, options) {
|
1312
|
+
if(options.hasOwnProperty("getTileUrl") && typeof(options["getTileUrl"]) == "function") {
|
1313
|
+
options.tileSize = options.tileSize || new google.maps.Size(256, 256);
|
1314
|
+
|
1315
|
+
var mapType = new google.maps.ImageMapType(options);
|
1316
|
+
|
1317
|
+
this.map.mapTypes.set(mapTypeId, mapType);
|
1318
|
+
}
|
1319
|
+
else {
|
1320
|
+
throw "'getTileUrl' function required";
|
1321
|
+
}
|
1322
|
+
};
|
1323
|
+
|
1324
|
+
this.addOverlayMapType = function(options) {
|
1325
|
+
if(options.hasOwnProperty("getTile") && typeof(options["getTile"]) == "function") {
|
1326
|
+
var overlayMapTypeIndex = options.index;
|
1327
|
+
|
1328
|
+
delete options.index;
|
1329
|
+
|
1330
|
+
this.map.overlayMapTypes.insertAt(overlayMapTypeIndex, options);
|
1331
|
+
}
|
1332
|
+
else {
|
1333
|
+
throw "'getTile' function required";
|
1334
|
+
}
|
1335
|
+
};
|
1336
|
+
|
1337
|
+
this.removeOverlayMapType = function(overlayMapTypeIndex) {
|
1338
|
+
this.map.overlayMapTypes.removeAt(overlayMapTypeIndex);
|
1339
|
+
};
|
1340
|
+
|
1341
|
+
// Styles
|
1342
|
+
|
1343
|
+
this.addStyle = function(options) {
|
1344
|
+
var styledMapType = new google.maps.StyledMapType(options.styles, options.styledMapName);
|
1345
|
+
|
1346
|
+
this.map.mapTypes.set(options.mapTypeId, styledMapType);
|
1347
|
+
};
|
1348
|
+
|
1349
|
+
this.setStyle = function(mapTypeId) {
|
1350
|
+
this.map.setMapTypeId(mapTypeId);
|
1351
|
+
};
|
1352
|
+
|
1353
|
+
// StreetView
|
1354
|
+
|
1355
|
+
this.createPanorama = function(streetview_options) {
|
1356
|
+
if (!streetview_options.hasOwnProperty('lat') || !streetview_options.hasOwnProperty('lng')) {
|
1357
|
+
streetview_options.lat = this.getCenter().lat();
|
1358
|
+
streetview_options.lng = this.getCenter().lng();
|
1359
|
+
}
|
1360
|
+
|
1361
|
+
this.panorama = GMaps.createPanorama(streetview_options);
|
1362
|
+
|
1363
|
+
this.map.setStreetView(this.panorama);
|
1364
|
+
|
1365
|
+
return this.panorama;
|
1366
|
+
};
|
1367
|
+
};
|
1368
|
+
|
1369
|
+
GMaps.createPanorama = function(options) {
|
1370
|
+
var el = getElementById(options.el, options.context);
|
1371
|
+
|
1372
|
+
options.position = new google.maps.LatLng(options.lat, options.lng);
|
1373
|
+
|
1374
|
+
delete options.el;
|
1375
|
+
delete options.context;
|
1376
|
+
delete options.lat;
|
1377
|
+
delete options.lng;
|
1378
|
+
|
1379
|
+
var streetview_events = ['closeclick', 'links_changed', 'pano_changed', 'position_changed', 'pov_changed', 'resize', 'visible_changed'];
|
1380
|
+
|
1381
|
+
var streetview_options = extend_object({visible : true}, options);
|
1382
|
+
|
1383
|
+
for(var i = 0; i < streetview_events.length; i++) {
|
1384
|
+
delete streetview_options[streetview_events[i]];
|
1385
|
+
}
|
1386
|
+
|
1387
|
+
var panorama = new google.maps.StreetViewPanorama(el, streetview_options);
|
1388
|
+
|
1389
|
+
for(var i = 0; i < streetview_events.length; i++) {
|
1390
|
+
(function(object, name) {
|
1391
|
+
google.maps.event.addListener(object, name, function(){
|
1392
|
+
if (options[name]) {
|
1393
|
+
options[name].apply(this);
|
1394
|
+
}
|
1395
|
+
});
|
1396
|
+
})(panorama, streetview_events[i]);
|
1397
|
+
}
|
1398
|
+
|
1399
|
+
return panorama;
|
1166
1400
|
};
|
1167
1401
|
|
1168
1402
|
GMaps.Route = function(options) {
|
@@ -1206,23 +1440,28 @@ if(window.google && window.google.maps){
|
|
1206
1440
|
|
1207
1441
|
// Geolocation (Modern browsers only)
|
1208
1442
|
GMaps.geolocate = function(options) {
|
1443
|
+
var complete_callback = options.always || options.complete;
|
1444
|
+
|
1209
1445
|
if (navigator.geolocation) {
|
1210
1446
|
navigator.geolocation.getCurrentPosition(function(position) {
|
1211
1447
|
options.success(position);
|
1212
|
-
|
1213
|
-
|
1448
|
+
|
1449
|
+
if (complete_callback) {
|
1450
|
+
complete_callback();
|
1214
1451
|
}
|
1215
1452
|
}, function(error) {
|
1216
1453
|
options.error(error);
|
1217
|
-
|
1218
|
-
|
1454
|
+
|
1455
|
+
if (complete_callback) {
|
1456
|
+
complete_callback();
|
1219
1457
|
}
|
1220
1458
|
}, options.options);
|
1221
1459
|
}
|
1222
1460
|
else {
|
1223
1461
|
options.not_supported();
|
1224
|
-
|
1225
|
-
|
1462
|
+
|
1463
|
+
if (complete_callback) {
|
1464
|
+
complete_callback();
|
1226
1465
|
}
|
1227
1466
|
}
|
1228
1467
|
};
|
@@ -1427,40 +1666,42 @@ if(window.google && window.google.maps){
|
|
1427
1666
|
};
|
1428
1667
|
}
|
1429
1668
|
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1669
|
+
if (!google.maps.Polygon.prototype.containsLatLng) {
|
1670
|
+
// Polygon containsLatLng - method to determine if a latLng is within a polygon
|
1671
|
+
google.maps.Polygon.prototype.containsLatLng = function(latLng) {
|
1672
|
+
// Exclude points outside of bounds as there is no way they are in the poly
|
1673
|
+
var bounds = this.getBounds();
|
1434
1674
|
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1675
|
+
if (bounds !== null && !bounds.contains(latLng)) {
|
1676
|
+
return false;
|
1677
|
+
}
|
1438
1678
|
|
1439
|
-
|
1440
|
-
|
1679
|
+
// Raycast point in polygon method
|
1680
|
+
var inPoly = false;
|
1441
1681
|
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1682
|
+
var numPaths = this.getPaths().getLength();
|
1683
|
+
for (var p = 0; p < numPaths; p++) {
|
1684
|
+
var path = this.getPaths().getAt(p);
|
1685
|
+
var numPoints = path.getLength();
|
1686
|
+
var j = numPoints - 1;
|
1447
1687
|
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1688
|
+
for (var i = 0; i < numPoints; i++) {
|
1689
|
+
var vertex1 = path.getAt(i);
|
1690
|
+
var vertex2 = path.getAt(j);
|
1451
1691
|
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1692
|
+
if (vertex1.lng() < latLng.lng() && vertex2.lng() >= latLng.lng() || vertex2.lng() < latLng.lng() && vertex1.lng() >= latLng.lng()) {
|
1693
|
+
if (vertex1.lat() + (latLng.lng() - vertex1.lng()) / (vertex2.lng() - vertex1.lng()) * (vertex2.lat() - vertex1.lat()) < latLng.lat()) {
|
1694
|
+
inPoly = !inPoly;
|
1695
|
+
}
|
1455
1696
|
}
|
1456
|
-
}
|
1457
1697
|
|
1458
|
-
|
1698
|
+
j = i;
|
1699
|
+
}
|
1459
1700
|
}
|
1460
|
-
}
|
1461
1701
|
|
1462
|
-
|
1463
|
-
|
1702
|
+
return inPoly;
|
1703
|
+
};
|
1704
|
+
}
|
1464
1705
|
|
1465
1706
|
google.maps.LatLngBounds.prototype.containsLatLng = function(latLng) {
|
1466
1707
|
return this.contains(latLng);
|
@@ -1477,43 +1718,85 @@ if(window.google && window.google.maps){
|
|
1477
1718
|
return GMaps;
|
1478
1719
|
}(this));
|
1479
1720
|
|
1480
|
-
var
|
1481
|
-
|
1721
|
+
var coordsToLatLngs = function(coords, useGeoJSON) {
|
1722
|
+
var first_coord = coords[0];
|
1723
|
+
var second_coord = coords[1];
|
1724
|
+
|
1725
|
+
if(useGeoJSON) {
|
1726
|
+
first_coord = coords[1];
|
1727
|
+
second_coord = coords[0];
|
1728
|
+
}
|
1729
|
+
|
1730
|
+
return new google.maps.LatLng(first_coord, second_coord);
|
1731
|
+
};
|
1732
|
+
|
1733
|
+
var arrayToLatLng = function(coords, useGeoJSON) {
|
1734
|
+
for(var i=0; i < coords.length; i++) {
|
1735
|
+
if(coords[i].length > 0 && typeof(coords[i][0]) != "number") {
|
1736
|
+
coords[i] = arrayToLatLng(coords[i], useGeoJSON);
|
1737
|
+
}
|
1738
|
+
else {
|
1739
|
+
coords[i] = coordsToLatLngs(coords[i], useGeoJSON);
|
1740
|
+
}
|
1741
|
+
}
|
1742
|
+
|
1743
|
+
return coords;
|
1482
1744
|
};
|
1483
1745
|
|
1484
1746
|
var extend_object = function(obj, new_obj) {
|
1485
1747
|
if(obj === new_obj) return obj;
|
1486
1748
|
|
1487
|
-
for(var name in new_obj){
|
1749
|
+
for(var name in new_obj) {
|
1488
1750
|
obj[name] = new_obj[name];
|
1489
1751
|
}
|
1490
1752
|
|
1491
1753
|
return obj;
|
1492
1754
|
};
|
1493
1755
|
|
1756
|
+
var replace_object = function(obj, replace) {
|
1757
|
+
if(obj === replace) return obj;
|
1758
|
+
|
1759
|
+
for(var name in replace) {
|
1760
|
+
if(obj[name] != undefined)
|
1761
|
+
obj[name] = replace[name];
|
1762
|
+
}
|
1763
|
+
|
1764
|
+
return obj;
|
1765
|
+
};
|
1766
|
+
|
1494
1767
|
var array_map = function(array, callback) {
|
1768
|
+
var original_callback_params = Array.prototype.slice.call(arguments, 2);
|
1769
|
+
|
1495
1770
|
if (Array.prototype.map && array.map === Array.prototype.map) {
|
1496
|
-
return
|
1497
|
-
|
1498
|
-
|
1771
|
+
return Array.prototype.map.call(array, function(item) {
|
1772
|
+
callback_params = original_callback_params;
|
1773
|
+
callback_params.splice(0, 0, item);
|
1499
1774
|
|
1775
|
+
return callback.apply(this, callback_params);
|
1776
|
+
});
|
1777
|
+
}
|
1778
|
+
else {
|
1779
|
+
var array_return = [];
|
1500
1780
|
var array_length = array.length;
|
1501
1781
|
|
1502
1782
|
for(var i = 0; i < array_length; i++) {
|
1503
|
-
|
1783
|
+
callback_params = original_callback_params;
|
1784
|
+
callback_params = callback_params.splice(0, 0, array[i]);
|
1785
|
+
array_return.push(callback.apply(this, callback_params));
|
1504
1786
|
}
|
1505
1787
|
|
1506
1788
|
return array_return;
|
1507
1789
|
}
|
1508
|
-
}
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1790
|
+
};
|
1791
|
+
|
1792
|
+
var array_flat = function(array) {
|
1793
|
+
new_array = [];
|
1794
|
+
|
1795
|
+
for(var i=0; i < array.length; i++) {
|
1796
|
+
new_array = new_array.concat(array[i]);
|
1797
|
+
}
|
1798
|
+
|
1799
|
+
return new_array;
|
1800
|
+
};
|
1801
|
+
|
1802
|
+
}
|
data/lib/gmapsjs/version.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmapsjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.13
|
5
4
|
prerelease:
|
5
|
+
version: 0.2.30
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Alvaro Pereyra
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-01-07 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: ! 'gmaps.js allows you to use the potential of Google Maps in a simple
|
16
16
|
way.
|
@@ -41,20 +41,20 @@ rdoc_options: []
|
|
41
41
|
require_paths:
|
42
42
|
- lib
|
43
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
44
|
requirements:
|
46
45
|
- - ! '>='
|
47
46
|
- !ruby/object:Gem::Version
|
48
47
|
version: '0'
|
49
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
48
|
none: false
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
50
|
requirements:
|
52
51
|
- - ! '>='
|
53
52
|
- !ruby/object:Gem::Version
|
54
53
|
version: '0'
|
54
|
+
none: false
|
55
55
|
requirements: []
|
56
56
|
rubyforge_project:
|
57
|
-
rubygems_version: 1.8.
|
57
|
+
rubygems_version: 1.8.23
|
58
58
|
signing_key:
|
59
59
|
specification_version: 3
|
60
60
|
summary: ''
|