gmapsjs 0.1.12 → 0.2.3
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 +351 -353
- data/lib/gmapsjs/version.rb +1 -1
- metadata +2 -2
@@ -1,13 +1,35 @@
|
|
1
|
-
|
1
|
+
/*!
|
2
|
+
* GMaps.js
|
3
|
+
* http://hpneo.github.com/gmaps/
|
4
|
+
*
|
5
|
+
* Copyright 2012, Gustavo Leon
|
6
|
+
* Released under the MIT License.
|
7
|
+
*/
|
8
|
+
|
9
|
+
var GMaps = (function(global) {
|
2
10
|
"use strict";
|
3
11
|
|
12
|
+
var doc = document;
|
13
|
+
var getElementById = function(id, context) {
|
14
|
+
var ele
|
15
|
+
if('jQuery' in global && context){
|
16
|
+
ele = $("#"+id.replace('#', ''), context)[0]
|
17
|
+
}else{
|
18
|
+
ele = doc.getElementById(id.replace('#', ''));
|
19
|
+
};
|
20
|
+
return ele;
|
21
|
+
};
|
22
|
+
|
4
23
|
var GMaps = function(options) {
|
5
24
|
var self = this;
|
6
|
-
var context_menu_style = 'position:absolute;display:none;min-width:100px;' +
|
7
|
-
'background:white;list-style:none;padding:8px;box-shadow:2px 2px 6px #ccc';
|
8
25
|
window.context_menu = {};
|
9
26
|
|
10
|
-
|
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
|
+
|
11
33
|
this.controls = [];
|
12
34
|
this.overlays = [];
|
13
35
|
this.layers = [];
|
@@ -31,17 +53,46 @@ var GMaps = (function($) {
|
|
31
53
|
|
32
54
|
var map_center = new google.maps.LatLng(options.lat, options.lng);
|
33
55
|
|
56
|
+
delete options.div;
|
34
57
|
delete options.lat;
|
35
58
|
delete options.lng;
|
36
59
|
delete options.mapType;
|
60
|
+
delete options.width;
|
61
|
+
delete options.height;
|
62
|
+
|
63
|
+
var zoomControlOpt = options.zoomControlOpt || {
|
64
|
+
style: 'DEFAULT',
|
65
|
+
position: 'TOP_LEFT'
|
66
|
+
};
|
67
|
+
|
68
|
+
var zoomControl = options.zoomControl || true,
|
69
|
+
zoomControlStyle = zoomControlOpt.style || 'DEFAULT',
|
70
|
+
zoomControlPosition = zoomControlOpt.position || 'TOP_LEFT',
|
71
|
+
panControl = options.panControl || true,
|
72
|
+
mapTypeControl = options.mapTypeControl || true,
|
73
|
+
scaleControl = options.scaleControl || true,
|
74
|
+
streetViewControl = options.streetViewControl || true,
|
75
|
+
overviewMapControl = overviewMapControl || true;
|
76
|
+
|
77
|
+
|
37
78
|
|
38
79
|
var map_base_options = {
|
39
80
|
zoom: this.zoom,
|
40
81
|
center: map_center,
|
41
|
-
mapTypeId: mapType
|
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
|
42
93
|
};
|
43
94
|
|
44
|
-
var map_options =
|
95
|
+
var map_options = extend_object(map_base_options, options);
|
45
96
|
|
46
97
|
this.map = new google.maps.Map(this.div, map_options);
|
47
98
|
|
@@ -52,25 +103,39 @@ var GMaps = (function($) {
|
|
52
103
|
for (var i in options){
|
53
104
|
if (options.hasOwnProperty(i)){
|
54
105
|
var option = options[i];
|
55
|
-
html += '<li><a id="' + control + '_' + i + '" href="#">' +
|
106
|
+
html += '<li><a id="' + control + '_' + i + '" href="#">' +
|
56
107
|
option.title + '</a></li>';
|
57
108
|
}
|
58
109
|
}
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
});
|
110
|
+
if(!getElementById('gmaps_context_menu')) return;
|
111
|
+
var context_menu_element = getElementById('gmaps_context_menu');
|
112
|
+
context_menu_element.innerHTML = html;
|
113
|
+
|
114
|
+
var context_menu_items = context_menu_element.getElementsByTagName('a');
|
115
|
+
|
116
|
+
var context_menu_items_count = context_menu_items.length;
|
67
117
|
|
68
|
-
var
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
118
|
+
for(var i=0;i<context_menu_items_count;i++){
|
119
|
+
var context_menu_item = context_menu_items[i];
|
120
|
+
|
121
|
+
var assign_menu_item_action = function(ev){
|
122
|
+
ev.preventDefault();
|
123
|
+
|
124
|
+
options[this.id.replace(control + '_', '')].action.call(self, e);
|
125
|
+
self.hideContextMenu();
|
126
|
+
};
|
127
|
+
|
128
|
+
google.maps.event.clearListeners(context_menu_item, 'click');
|
129
|
+
google.maps.event.addDomListenerOnce(context_menu_item, 'click', assign_menu_item_action, false);
|
130
|
+
}
|
131
|
+
|
132
|
+
var left = self.div.offsetLeft + e.pixel.x - 15;
|
133
|
+
var top = self.div.offsetTop + e.pixel.y - 15;
|
134
|
+
|
135
|
+
context_menu_element.style.left = left + "px";
|
136
|
+
context_menu_element.style.top = top + "px";
|
137
|
+
|
138
|
+
context_menu_element.style.display = 'block';
|
74
139
|
};
|
75
140
|
|
76
141
|
var buildContextMenu = function(control, e) {
|
@@ -93,7 +158,6 @@ var GMaps = (function($) {
|
|
93
158
|
|
94
159
|
this.setContextMenu = function(options) {
|
95
160
|
window.context_menu[options.control] = {};
|
96
|
-
var html = '<ul id="gmaps_context_menu" style="' + context_menu_style + '"></ul>';
|
97
161
|
for (var i in options.options){
|
98
162
|
if (options.options.hasOwnProperty(i)){
|
99
163
|
var option = options.options[i];
|
@@ -103,117 +167,93 @@ var GMaps = (function($) {
|
|
103
167
|
};
|
104
168
|
}
|
105
169
|
}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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);
|
110
191
|
};
|
111
192
|
|
112
193
|
this.hideContextMenu = function() {
|
113
|
-
|
194
|
+
var context_menu_element = getElementById('gmaps_context_menu');
|
195
|
+
if(context_menu_element)
|
196
|
+
context_menu_element.style.display = 'none';
|
114
197
|
};
|
115
198
|
|
116
199
|
//Events
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
}
|
139
|
-
|
140
|
-
|
141
|
-
google.maps.event.addListener(this.map, 'drag', function(e) {
|
142
|
-
if (options.drag) {
|
143
|
-
options.drag(e);
|
144
|
-
}
|
145
|
-
self.hideContextMenu();
|
146
|
-
});
|
147
|
-
google.maps.event.addListener(this.map, 'dragend', function(e) {
|
148
|
-
if (options.dragend) {
|
149
|
-
options.dragend(e);
|
150
|
-
}
|
151
|
-
self.hideContextMenu();
|
152
|
-
});
|
153
|
-
google.maps.event.addListener(this.map, 'dragstart', function(e) {
|
154
|
-
if (options.dragstart) {
|
155
|
-
options.dragstart(e);
|
156
|
-
}
|
157
|
-
self.hideContextMenu();
|
158
|
-
});
|
159
|
-
google.maps.event.addListener(this.map, 'idle', function(e) {
|
160
|
-
if (options.idle) {
|
161
|
-
options.idle(e);
|
162
|
-
}
|
163
|
-
self.hideContextMenu();
|
164
|
-
});
|
165
|
-
google.maps.event.addListener(this.map, 'maptypeid_changed', function(e) {
|
166
|
-
if (options.maptypeid_changed) {
|
167
|
-
options.maptypeid_changed(e);
|
168
|
-
}
|
169
|
-
self.hideContextMenu();
|
170
|
-
});
|
171
|
-
google.maps.event.addListener(this.map, 'mousemove', function(e) {
|
172
|
-
if (options.mousemove) {
|
173
|
-
options.mousemove(e);
|
174
|
-
}
|
175
|
-
});
|
176
|
-
google.maps.event.addListener(this.map, 'mouseout', function(e) {
|
177
|
-
if (options.mouseout) {
|
178
|
-
options.mouseout(e);
|
179
|
-
}
|
180
|
-
});
|
181
|
-
google.maps.event.addListener(this.map, 'mouseover', function(e) {
|
182
|
-
if (options.mouseover) {
|
183
|
-
options.mouseover(e);
|
184
|
-
}
|
185
|
-
});
|
186
|
-
google.maps.event.addListener(this.map, 'projection_changed', function(e) {
|
187
|
-
if (options.projection_changed) {
|
188
|
-
options.projection_changed(e);
|
189
|
-
}
|
190
|
-
self.hideContextMenu();
|
191
|
-
});
|
192
|
-
google.maps.event.addListener(this.map, 'resize', function(e) {
|
193
|
-
if (options.resize) {
|
194
|
-
options.resize(e);
|
195
|
-
}
|
196
|
-
self.hideContextMenu();
|
197
|
-
});
|
200
|
+
|
201
|
+
var events_that_hide_context_menu = ['bounds_changed', 'center_changed', 'click', 'dblclick', 'drag', 'dragend', 'dragstart', 'idle', 'maptypeid_changed', 'projection_changed', 'resize', 'tilesloaded', 'zoom_changed'];
|
202
|
+
var events_that_doesnt_hide_context_menu = ['mousemove', 'mouseout', 'mouseover'];
|
203
|
+
|
204
|
+
for (var ev = 0; ev < events_that_hide_context_menu.length; ev++) {
|
205
|
+
(function(object, name) {
|
206
|
+
google.maps.event.addListener(object, name, function(e){
|
207
|
+
if (options[name])
|
208
|
+
options[name].apply(this, [e]);
|
209
|
+
|
210
|
+
self.hideContextMenu();
|
211
|
+
});
|
212
|
+
})(this.map, events_that_hide_context_menu[ev]);
|
213
|
+
}
|
214
|
+
|
215
|
+
for (var ev = 0; ev < events_that_doesnt_hide_context_menu.length; ev++) {
|
216
|
+
(function(object, name) {
|
217
|
+
google.maps.event.addListener(object, name, function(e){
|
218
|
+
if (options[name])
|
219
|
+
options[name].apply(this, [e]);
|
220
|
+
});
|
221
|
+
})(this.map, events_that_doesnt_hide_context_menu[ev]);
|
222
|
+
}
|
223
|
+
|
198
224
|
google.maps.event.addListener(this.map, 'rightclick', function(e) {
|
199
225
|
if (options.rightclick) {
|
200
|
-
options.rightclick(e);
|
226
|
+
options.rightclick.apply(this, [e]);
|
201
227
|
}
|
202
228
|
|
203
229
|
buildContextMenu('map', e);
|
204
230
|
});
|
205
|
-
|
206
|
-
|
207
|
-
|
231
|
+
|
232
|
+
this.refresh = function() {
|
233
|
+
google.maps.event.trigger(this.map, 'resize');
|
234
|
+
};
|
235
|
+
|
236
|
+
this.fitZoom = function() {
|
237
|
+
var latLngs = [];
|
238
|
+
var markers_length = this.markers.length;
|
239
|
+
|
240
|
+
for(var i=0; i < markers_length; i++) {
|
241
|
+
latLngs.push(this.markers[i].getPosition());
|
208
242
|
}
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
243
|
+
|
244
|
+
this.fitBounds(latLngs);
|
245
|
+
};
|
246
|
+
|
247
|
+
this.fitBounds = function(latLngs) {
|
248
|
+
var total = latLngs.length;
|
249
|
+
var bounds = new google.maps.LatLngBounds();
|
250
|
+
|
251
|
+
for(var i=0; i < total; i++) {
|
252
|
+
bounds.extend(latLngs[i]);
|
214
253
|
}
|
215
|
-
|
216
|
-
|
254
|
+
|
255
|
+
this.map.fitBounds(bounds);
|
256
|
+
};
|
217
257
|
|
218
258
|
// Map methods
|
219
259
|
this.setCenter = function(lat, lng, callback) {
|
@@ -235,6 +275,10 @@ var GMaps = (function($) {
|
|
235
275
|
this.map.setZoom(value);
|
236
276
|
};
|
237
277
|
|
278
|
+
this.getZoom = function() {
|
279
|
+
return this.map.getZoom();
|
280
|
+
};
|
281
|
+
|
238
282
|
this.zoomIn = function(value) {
|
239
283
|
this.map.setZoom(this.map.getZoom() + value);
|
240
284
|
};
|
@@ -244,21 +288,25 @@ var GMaps = (function($) {
|
|
244
288
|
};
|
245
289
|
|
246
290
|
this.createControl = function(options) {
|
247
|
-
|
248
|
-
options.style.fontFamily = 'Arial, sans-serif';
|
249
|
-
options.style.fontSize = '13px';
|
250
|
-
options.style.boxShadow = 'rgba(0, 0, 0, 0.398438) 0px 2px 4px';
|
291
|
+
var control = doc.createElement('div');
|
251
292
|
|
252
|
-
|
253
|
-
|
254
|
-
|
293
|
+
control.style.cursor = 'pointer';
|
294
|
+
control.style.fontFamily = 'Arial, sans-serif';
|
295
|
+
control.style.fontSize = '13px';
|
296
|
+
control.style.boxShadow = 'rgba(0, 0, 0, 0.398438) 0px 2px 4px';
|
255
297
|
|
256
|
-
var
|
298
|
+
for(var option in options.style){
|
299
|
+
control.style[option] = options.style[option];
|
300
|
+
}
|
257
301
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
302
|
+
control.textContent = options.text;
|
303
|
+
|
304
|
+
for (var ev in options.events) {
|
305
|
+
(function(object, name) {
|
306
|
+
google.maps.event.addDomListener(object, name, function(){
|
307
|
+
options.events[name].apply(this, [this]);
|
308
|
+
});
|
309
|
+
})(control, ev);
|
262
310
|
}
|
263
311
|
|
264
312
|
control.index = 1;
|
@@ -285,16 +333,18 @@ var GMaps = (function($) {
|
|
285
333
|
var details = options.details;
|
286
334
|
var fences = options.fences;
|
287
335
|
var outside = options.outside;
|
336
|
+
|
288
337
|
var base_options = {
|
289
338
|
position: new google.maps.LatLng(options.lat, options.lng),
|
290
339
|
map: null
|
291
340
|
};
|
341
|
+
|
292
342
|
delete options.lat;
|
293
343
|
delete options.lng;
|
294
344
|
delete options.fences;
|
295
345
|
delete options.outside;
|
296
346
|
|
297
|
-
var marker_options =
|
347
|
+
var marker_options = extend_object(base_options, options);
|
298
348
|
|
299
349
|
var marker = new google.maps.Marker(marker_options);
|
300
350
|
|
@@ -303,31 +353,27 @@ var GMaps = (function($) {
|
|
303
353
|
if (options.infoWindow) {
|
304
354
|
marker.infoWindow = new google.maps.InfoWindow(options.infoWindow);
|
305
355
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
});
|
315
|
-
}
|
316
|
-
if (options.infoWindow.domready) {
|
317
|
-
google.maps.event.addListener(marker.infoWindow, 'domready', function() {
|
318
|
-
options.infoWindow.domready();
|
319
|
-
});
|
320
|
-
}
|
321
|
-
if (options.infoWindow.position_changed) {
|
322
|
-
google.maps.event.addListener(marker.infoWindow, 'position_changed', function() {
|
323
|
-
options.infoWindow.position_changed();
|
324
|
-
});
|
356
|
+
var info_window_events = ['closeclick', 'content_changed', 'domready', 'position_changed', 'zindex_changed'];
|
357
|
+
|
358
|
+
for (var ev = 0; ev < info_window_events.length; ev++) {
|
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]);
|
325
365
|
}
|
326
|
-
|
327
|
-
|
328
|
-
|
366
|
+
}
|
367
|
+
|
368
|
+
var marker_events = ['drag', 'dragstart', 'mouseout', 'mouseover', 'mouseup', 'position_changed'];
|
369
|
+
|
370
|
+
for (var ev = 0; ev < marker_events.length; ev++) {
|
371
|
+
(function(object, name) {
|
372
|
+
google.maps.event.addListener(object, name, function(){
|
373
|
+
if (options[name])
|
374
|
+
options[name].apply(this, [this]);
|
329
375
|
});
|
330
|
-
}
|
376
|
+
})(marker, marker_events[ev]);
|
331
377
|
}
|
332
378
|
|
333
379
|
google.maps.event.addListener(marker, 'click', function() {
|
@@ -343,15 +389,10 @@ var GMaps = (function($) {
|
|
343
389
|
}
|
344
390
|
});
|
345
391
|
|
346
|
-
if (options.drag) {
|
347
|
-
google.maps.event.addListener(marker, 'drag', function() {
|
348
|
-
options.drag(this);
|
349
|
-
});
|
350
|
-
}
|
351
392
|
if (options.dragend || marker.fences) {
|
352
393
|
google.maps.event.addListener(marker, 'dragend', function() {
|
353
394
|
if (options.dragend) {
|
354
|
-
options.dragend(this);
|
395
|
+
options.dragend.apply(this, [this]);
|
355
396
|
}
|
356
397
|
if (marker.fences) {
|
357
398
|
self.checkMarkerGeofence(marker, function(m, f) {
|
@@ -360,31 +401,6 @@ var GMaps = (function($) {
|
|
360
401
|
}
|
361
402
|
});
|
362
403
|
}
|
363
|
-
if (options.dragstart) {
|
364
|
-
google.maps.event.addListener(marker, 'dragstart', function() {
|
365
|
-
options.dragstart(this);
|
366
|
-
});
|
367
|
-
}
|
368
|
-
if (options.mouseout) {
|
369
|
-
google.maps.event.addListener(marker, 'mouseout', function() {
|
370
|
-
options.mouseout(this);
|
371
|
-
});
|
372
|
-
}
|
373
|
-
if (options.mouseover) {
|
374
|
-
google.maps.event.addListener(marker, 'mouseover', function() {
|
375
|
-
options.mouseover(this);
|
376
|
-
});
|
377
|
-
}
|
378
|
-
if (options.mouseup) {
|
379
|
-
google.maps.event.addListener(marker, 'mouseup', function() {
|
380
|
-
options.mouseup(this);
|
381
|
-
});
|
382
|
-
}
|
383
|
-
if (options.position_changed) {
|
384
|
-
google.maps.event.addListener(marker, 'position_changed', function() {
|
385
|
-
options.position_changed(this);
|
386
|
-
});
|
387
|
-
}
|
388
404
|
|
389
405
|
return marker;
|
390
406
|
}
|
@@ -412,7 +428,7 @@ var GMaps = (function($) {
|
|
412
428
|
}
|
413
429
|
return this.markers;
|
414
430
|
};
|
415
|
-
|
431
|
+
|
416
432
|
this.hideInfoWindows = function() {
|
417
433
|
for (var i=0, marker; marker=this.markers[i]; i++){
|
418
434
|
if (marker.infoWindow){
|
@@ -420,7 +436,7 @@ var GMaps = (function($) {
|
|
420
436
|
}
|
421
437
|
}
|
422
438
|
};
|
423
|
-
|
439
|
+
|
424
440
|
this.removeMarkers = function() {
|
425
441
|
for (var i=0, marker; marker=this.markers[i]; i++){
|
426
442
|
marker.setMap(null);
|
@@ -434,10 +450,11 @@ var GMaps = (function($) {
|
|
434
450
|
overlay.setMap(self.map);
|
435
451
|
|
436
452
|
overlay.onAdd = function() {
|
437
|
-
var div =
|
453
|
+
var div = doc.createElement('div');
|
438
454
|
div.style.borderStyle = "none";
|
439
455
|
div.style.borderWidth = "0px";
|
440
456
|
div.style.position = "absolute";
|
457
|
+
div.style.zIndex = 100;
|
441
458
|
div.innerHTML = options.content;
|
442
459
|
|
443
460
|
self.overlay_div = div;
|
@@ -458,32 +475,35 @@ var GMaps = (function($) {
|
|
458
475
|
options.verticalOffset = options.verticalOffset || 0;
|
459
476
|
|
460
477
|
var div = self.overlay_div;
|
461
|
-
var content = div.children;
|
478
|
+
var content = div.children[0];
|
479
|
+
|
480
|
+
var content_height = content.clientHeight;
|
481
|
+
var content_width = content.clientWidth;
|
462
482
|
|
463
483
|
switch (options.verticalAlign) {
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
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;
|
474
494
|
}
|
475
495
|
|
476
496
|
switch (options.horizontalAlign) {
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
497
|
+
case 'left':
|
498
|
+
div.style.left = (pixel.x - content_width + options.horizontalOffset) + 'px';
|
499
|
+
break;
|
500
|
+
default:
|
501
|
+
case 'center':
|
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;
|
487
507
|
}
|
488
508
|
};
|
489
509
|
|
@@ -529,45 +549,15 @@ var GMaps = (function($) {
|
|
529
549
|
strokeWeight: options.strokeWeight
|
530
550
|
});
|
531
551
|
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
});
|
541
|
-
}
|
542
|
-
if (options.mousedown) {
|
543
|
-
google.maps.event.addListener(polyline, 'mousedown', function(e) {
|
544
|
-
options.mousedown(e);
|
545
|
-
});
|
546
|
-
}
|
547
|
-
if (options.mousemove) {
|
548
|
-
google.maps.event.addListener(polyline, 'mousemove', function(e) {
|
549
|
-
options.mousemove(e);
|
550
|
-
});
|
551
|
-
}
|
552
|
-
if (options.mouseout) {
|
553
|
-
google.maps.event.addListener(polyline, 'mouseout', function(e) {
|
554
|
-
options.mouseout(e);
|
555
|
-
});
|
556
|
-
}
|
557
|
-
if (options.mouseover) {
|
558
|
-
google.maps.event.addListener(polyline, 'mouseover', function(e) {
|
559
|
-
options.mouseover(e);
|
560
|
-
});
|
561
|
-
}
|
562
|
-
if (options.mouseup) {
|
563
|
-
google.maps.event.addListener(polyline, 'mouseup', function(e) {
|
564
|
-
options.mouseup(e);
|
565
|
-
});
|
566
|
-
}
|
567
|
-
if (options.rightclick) {
|
568
|
-
google.maps.event.addListener(polyline, 'rightclick', function(e) {
|
569
|
-
options.rightclick(e);
|
570
|
-
});
|
552
|
+
var polyline_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
|
553
|
+
|
554
|
+
for (var ev = 0; ev < polyline_events.length; ev++) {
|
555
|
+
(function(object, name) {
|
556
|
+
google.maps.event.addListener(object, name, function(e){
|
557
|
+
if (options[name])
|
558
|
+
options[name].apply(this, [e]);
|
559
|
+
});
|
560
|
+
})(polyline, polyline_events[ev]);
|
571
561
|
}
|
572
562
|
|
573
563
|
this.polylines.push(polyline);
|
@@ -576,7 +566,7 @@ var GMaps = (function($) {
|
|
576
566
|
};
|
577
567
|
|
578
568
|
this.drawCircle = function(options) {
|
579
|
-
options =
|
569
|
+
options = extend_object({
|
580
570
|
map: this.map,
|
581
571
|
center: new google.maps.LatLng(options.lat, options.lng)
|
582
572
|
}, options);
|
@@ -585,100 +575,51 @@ var GMaps = (function($) {
|
|
585
575
|
delete options.lng;
|
586
576
|
var polygon = new google.maps.Circle(options);
|
587
577
|
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
}
|
597
|
-
}
|
598
|
-
google.maps.event.addListener(polygon, 'mousedown', function(e) {
|
599
|
-
if (options.mousedown) {
|
600
|
-
options.mousedown(e);
|
601
|
-
}
|
602
|
-
});
|
603
|
-
google.maps.event.addListener(polygon, 'mousemove', function(e) {
|
604
|
-
if (options.mousemove) {
|
605
|
-
options.mousemove(e);
|
606
|
-
}
|
607
|
-
});
|
608
|
-
google.maps.event.addListener(polygon, 'mouseout', function(e) {
|
609
|
-
if (options.mouseout) {
|
610
|
-
options.mouseout(e);
|
611
|
-
}
|
612
|
-
});
|
613
|
-
google.maps.event.addListener(polygon, 'mouseover', function(e) {
|
614
|
-
if (options.mouseover) {
|
615
|
-
options.mouseover(e);
|
616
|
-
}
|
617
|
-
});
|
618
|
-
google.maps.event.addListener(polygon, 'mouseup', function(e) {
|
619
|
-
if (options.mouseup) {
|
620
|
-
options.mouseup(e);
|
621
|
-
}
|
622
|
-
});
|
623
|
-
google.maps.event.addListener(polygon, 'rightclick', function(e) {
|
624
|
-
if (options.rightclick) {
|
625
|
-
options.rightclick(e);
|
626
|
-
}
|
627
|
-
});
|
578
|
+
var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
|
579
|
+
|
580
|
+
for (var ev = 0; ev < polygon_events.length; ev++) {
|
581
|
+
(function(object, name) {
|
582
|
+
google.maps.event.addListener(object, name, function(e){
|
583
|
+
if (options[name])
|
584
|
+
options[name].apply(this, [e]);
|
585
|
+
});
|
586
|
+
})(polygon, polygon_events[ev]);
|
587
|
+
}
|
628
588
|
|
629
589
|
return polygon;
|
630
590
|
};
|
631
591
|
|
632
592
|
this.drawPolygon = function(options) {
|
633
|
-
options =
|
593
|
+
options = extend_object({
|
634
594
|
map: this.map
|
635
595
|
}, options);
|
596
|
+
|
597
|
+
if(options.paths.length > 0) {
|
598
|
+
if(options.paths[0].length > 0) {
|
599
|
+
options.paths = array_map(options.paths, arrayToLatLng);
|
600
|
+
}
|
601
|
+
}
|
602
|
+
|
636
603
|
var polygon = new google.maps.Polygon(options);
|
637
604
|
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
}
|
647
|
-
}
|
648
|
-
google.maps.event.addListener(polygon, 'mousedown', function(e) {
|
649
|
-
if (options.mousedown) {
|
650
|
-
options.mousedown(e);
|
651
|
-
}
|
652
|
-
});
|
653
|
-
google.maps.event.addListener(polygon, 'mousemove', function(e) {
|
654
|
-
if (options.mousemove) {
|
655
|
-
options.mousemove(e);
|
656
|
-
}
|
657
|
-
});
|
658
|
-
google.maps.event.addListener(polygon, 'mouseout', function(e) {
|
659
|
-
if (options.mouseout) {
|
660
|
-
options.mouseout(e);
|
661
|
-
}
|
662
|
-
});
|
663
|
-
google.maps.event.addListener(polygon, 'mouseover', function(e) {
|
664
|
-
if (options.mouseover) {
|
665
|
-
options.mouseover(e);
|
666
|
-
}
|
667
|
-
});
|
668
|
-
google.maps.event.addListener(polygon, 'mouseup', function(e) {
|
669
|
-
if (options.mouseup) {
|
670
|
-
options.mouseup(e);
|
671
|
-
}
|
672
|
-
});
|
673
|
-
google.maps.event.addListener(polygon, 'rightclick', function(e) {
|
674
|
-
if (options.rightclick) {
|
675
|
-
options.rightclick(e);
|
676
|
-
}
|
677
|
-
});
|
605
|
+
var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
|
606
|
+
|
607
|
+
for (var ev = 0; ev < polygon_events.length; ev++) {
|
608
|
+
(function(object, name) {
|
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
|
+
}
|
678
615
|
|
679
616
|
this.polygons.push(polygon);
|
680
617
|
|
681
618
|
return polygon;
|
619
|
+
|
620
|
+
function arrayToLatLng(coords) {
|
621
|
+
return new google.maps.LatLng(coords[0], coords[1]);
|
622
|
+
}
|
682
623
|
};
|
683
624
|
|
684
625
|
this.getFromFusionTables = function(options) {
|
@@ -687,14 +628,15 @@ var GMaps = (function($) {
|
|
687
628
|
delete options.events;
|
688
629
|
|
689
630
|
var fusion_tables_options = options;
|
690
|
-
fusion_tables_options.map = this.map;
|
691
631
|
|
692
632
|
var layer = new google.maps.FusionTablesLayer(fusion_tables_options);
|
693
633
|
|
694
|
-
for (var
|
695
|
-
|
696
|
-
|
697
|
-
|
634
|
+
for (var ev in events) {
|
635
|
+
(function(object, name) {
|
636
|
+
google.maps.event.addListener(object, name, function(e){
|
637
|
+
events[name].apply(this, [e]);
|
638
|
+
});
|
639
|
+
})(layer, ev);
|
698
640
|
}
|
699
641
|
|
700
642
|
this.layers.push(layer);
|
@@ -702,22 +644,30 @@ var GMaps = (function($) {
|
|
702
644
|
return layer;
|
703
645
|
};
|
704
646
|
|
647
|
+
this.loadFromFusionTables = function(options) {
|
648
|
+
var layer = this.getFromFusionTables(options);
|
649
|
+
layer.setMap(this.map);
|
650
|
+
|
651
|
+
return layer;
|
652
|
+
};
|
653
|
+
|
705
654
|
this.getFromKML = function(options) {
|
706
655
|
var url = options.url;
|
707
656
|
var events = options.events;
|
708
657
|
|
709
658
|
delete options.url;
|
710
659
|
delete options.events;
|
711
|
-
|
660
|
+
|
712
661
|
var kml_options = options;
|
713
|
-
kml_options.map = this.map;
|
714
662
|
|
715
663
|
var layer = new google.maps.KmlLayer(url, kml_options);
|
716
664
|
|
717
|
-
for (var
|
718
|
-
|
719
|
-
|
720
|
-
|
665
|
+
for (var ev in events) {
|
666
|
+
(function(object, name) {
|
667
|
+
google.maps.event.addListener(object, name, function(e){
|
668
|
+
events[name].apply(this, [e]);
|
669
|
+
});
|
670
|
+
})(layer, ev);
|
721
671
|
}
|
722
672
|
|
723
673
|
this.layers.push(layer);
|
@@ -725,6 +675,13 @@ var GMaps = (function($) {
|
|
725
675
|
return layer;
|
726
676
|
};
|
727
677
|
|
678
|
+
this.loadFromKML = function(options) {
|
679
|
+
var layer = this.getFromKML(options);
|
680
|
+
layer.setMap(this.map);
|
681
|
+
|
682
|
+
return layer;
|
683
|
+
};
|
684
|
+
|
728
685
|
// Services
|
729
686
|
var travelMode, unitSystem;
|
730
687
|
this.getRoutes = function(options) {
|
@@ -749,12 +706,14 @@ var GMaps = (function($) {
|
|
749
706
|
}
|
750
707
|
|
751
708
|
var base_options = {
|
752
|
-
avoidHighways:
|
753
|
-
avoidTolls:
|
754
|
-
optimizeWaypoints:
|
709
|
+
avoidHighways: false,
|
710
|
+
avoidTolls: false,
|
711
|
+
optimizeWaypoints: false,
|
755
712
|
waypoints: []
|
756
713
|
};
|
757
|
-
|
714
|
+
|
715
|
+
var request_options = extend_object(base_options, options);
|
716
|
+
|
758
717
|
request_options.origin = new google.maps.LatLng(options.origin[0], options.origin[1]);
|
759
718
|
request_options.destination = new google.maps.LatLng(options.destination[0], options.destination[1]);
|
760
719
|
request_options.travelMode = travelMode;
|
@@ -779,12 +738,24 @@ var GMaps = (function($) {
|
|
779
738
|
});
|
780
739
|
};
|
781
740
|
|
741
|
+
this.removePolylines = function(){
|
742
|
+
var index;
|
743
|
+
for(index in this.polylines){
|
744
|
+
this.polylines[index].setMap(null);
|
745
|
+
}
|
746
|
+
this.polylines = [];
|
747
|
+
}
|
748
|
+
|
749
|
+
// Alias for the method "drawRoute"
|
750
|
+
this.cleanRoute = this.removePolylines;
|
751
|
+
|
782
752
|
this.drawRoute = function(options) {
|
783
753
|
var self = this;
|
784
754
|
this.getRoutes({
|
785
755
|
origin: options.origin,
|
786
756
|
destination: options.destination,
|
787
757
|
travelMode: options.travelMode,
|
758
|
+
waypoints : options.waypoints,
|
788
759
|
callback: function(e) {
|
789
760
|
if (e.length > 0) {
|
790
761
|
self.drawPolyline({
|
@@ -807,6 +778,7 @@ var GMaps = (function($) {
|
|
807
778
|
origin: options.origin,
|
808
779
|
destination: options.destination,
|
809
780
|
travelMode: options.travelMode,
|
781
|
+
waypoints : options.waypoints,
|
810
782
|
callback: function(e) {
|
811
783
|
if (e.length > 0 && options.step) {
|
812
784
|
var route = e[e.length - 1];
|
@@ -882,7 +854,7 @@ var GMaps = (function($) {
|
|
882
854
|
|
883
855
|
this.checkMarkerGeofence = function(marker, outside_callback) {
|
884
856
|
if (marker.fences) {
|
885
|
-
for (var i=0, fence; fence=marker.fences[i]; i++) {
|
857
|
+
for (var i=0, fence; fence=marker.fences[i]; i++) {
|
886
858
|
var pos = marker.getPosition();
|
887
859
|
if (!self.checkGeofence(pos.lat(), pos.lng(), fence)) {
|
888
860
|
outside_callback(marker, fence);
|
@@ -1000,7 +972,7 @@ var GMaps = (function($) {
|
|
1000
972
|
else if (options.address){
|
1001
973
|
parameters.push('center=' + options.address);
|
1002
974
|
delete options.address;
|
1003
|
-
}
|
975
|
+
}
|
1004
976
|
else if (options.lat){
|
1005
977
|
parameters.push(['center=', options.lat, ',', options.lng].join(''));
|
1006
978
|
delete options.lat;
|
@@ -1091,7 +1063,7 @@ var GMaps = (function($) {
|
|
1091
1063
|
}
|
1092
1064
|
|
1093
1065
|
color = color.slice(0,8) + opacity;
|
1094
|
-
}
|
1066
|
+
}
|
1095
1067
|
}
|
1096
1068
|
return color;
|
1097
1069
|
}
|
@@ -1099,7 +1071,7 @@ var GMaps = (function($) {
|
|
1099
1071
|
if (polyline){
|
1100
1072
|
data = polyline;
|
1101
1073
|
polyline = [];
|
1102
|
-
|
1074
|
+
|
1103
1075
|
if (data.strokeWeight){
|
1104
1076
|
polyline.push('weight:' + parseInt(data.strokeWeight, 10));
|
1105
1077
|
}
|
@@ -1113,7 +1085,7 @@ var GMaps = (function($) {
|
|
1113
1085
|
var fillcolor = parseColor(data.fillColor, data.fillOpacity);
|
1114
1086
|
polyline.push('fillcolor:' + fillcolor);
|
1115
1087
|
}
|
1116
|
-
|
1088
|
+
|
1117
1089
|
var path = data.path;
|
1118
1090
|
if (path.join){
|
1119
1091
|
for (var j=0, pos; pos=path[j]; j++){
|
@@ -1121,7 +1093,7 @@ var GMaps = (function($) {
|
|
1121
1093
|
}
|
1122
1094
|
}
|
1123
1095
|
else {
|
1124
|
-
polyline.push('enc:' + path);
|
1096
|
+
polyline.push('enc:' + path);
|
1125
1097
|
}
|
1126
1098
|
|
1127
1099
|
polyline = polyline.join('|');
|
@@ -1202,4 +1174,30 @@ var GMaps = (function($) {
|
|
1202
1174
|
};
|
1203
1175
|
|
1204
1176
|
return GMaps;
|
1205
|
-
}(
|
1177
|
+
}(this));
|
1178
|
+
|
1179
|
+
var extend_object = function(obj, new_obj) {
|
1180
|
+
if(obj === new_obj) return obj;
|
1181
|
+
|
1182
|
+
for(var name in new_obj){
|
1183
|
+
obj[name] = new_obj[name];
|
1184
|
+
}
|
1185
|
+
|
1186
|
+
return obj;
|
1187
|
+
};
|
1188
|
+
|
1189
|
+
var array_map = function(array, callback) {
|
1190
|
+
if (Array.prototype.map && array.map === Array.prototype.map) {
|
1191
|
+
return array.map(callback);
|
1192
|
+
} else {
|
1193
|
+
var array_return = [];
|
1194
|
+
|
1195
|
+
var array_length = array.length;
|
1196
|
+
|
1197
|
+
for(var i = 0; i < array_length; i++) {
|
1198
|
+
array_return.push(callback(array[i]));
|
1199
|
+
}
|
1200
|
+
|
1201
|
+
return array_return;
|
1202
|
+
}
|
1203
|
+
}
|
data/lib/gmapsjs/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmapsjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-07-18 00:00:00.000000000Z
|
14
14
|
dependencies: []
|
15
15
|
description: ! 'gmaps.js allows you to use the potential of Google Maps in a simple
|
16
16
|
way.
|