iugu-ux 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +14 -0
- data/lib/iugu-ux.rb +41 -0
- data/lib/iugu-ux/railtie.rb +13 -0
- data/lib/iugu-ux/version.rb +3 -0
- data/sandbox/Rakefile +7 -0
- data/sandbox/app/assets/images/assets-hd-s827ab39c93.png +0 -0
- data/sandbox/app/assets/images/assets-sf5326dcc8f.png +0 -0
- data/sandbox/app/assets/images/iux-default-hd-sc9d2356e0b.png +0 -0
- data/sandbox/app/assets/images/iux-default-s80f46e65ce.png +0 -0
- data/sandbox/app/assets/images/rails.png +0 -0
- data/sandbox/app/assets/javascripts/application.js +0 -0
- data/sandbox/app/assets/javascripts/web-app/config.js.erb +9 -0
- data/sandbox/app/assets/javascripts/web-app/i18n-languages.js.erb +12 -0
- data/sandbox/app/assets/javascripts/web-app/locale/en.json +11 -0
- data/sandbox/app/assets/javascripts/web-app/locale/pt-BR.json +11 -0
- data/sandbox/app/assets/javascripts/web-app/models.js +1 -0
- data/sandbox/app/assets/javascripts/web-app/presenters.js +1 -0
- data/sandbox/app/assets/javascripts/web-app/presenters/main-view.jst.eco +50 -0
- data/sandbox/app/assets/javascripts/web-app/usecode.js +1 -0
- data/sandbox/app/assets/javascripts/web-app/usecode/root-view.coffee +13 -0
- data/sandbox/app/assets/javascripts/web-app/usecode/router.coffee +19 -0
- data/sandbox/app/assets/sprites/a/assets-hd/arrow-down.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/arrow-up.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/btn-dashboard.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/btn-yell.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/clock.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/dashboard-places.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/dashboard-products.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/dashboard-spaces.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/dashboard-user.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/header-letsyell-logo.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/icon-facebook.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/icon-google.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/icon-linkedin.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/icon-twitter.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/icon-windows.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/icon-yahoo.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/place-coffee.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/right-arrow.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/stars-five.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/stars-four-half.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/stars-four.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/stars-half.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/stars-one-half.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/stars-one.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/stars-three-half.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/stars-three.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/stars-two-half.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/stars-two.png +0 -0
- data/sandbox/app/assets/sprites/a/assets-hd/stars-zero.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/arrow-down.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/arrow-up.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/btn-dashboard.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/btn-yell.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/clock.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/dashboard-places.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/dashboard-products.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/dashboard-spaces.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/dashboard-user.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/header-letsyell-logo.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/icon-facebook.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/icon-google.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/icon-linkedin.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/icon-twitter.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/icon-windows.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/icon-yahoo.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/place-coffee.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/right-arrow.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/stars-five.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/stars-four-half.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/stars-four.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/stars-half.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/stars-one-half.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/stars-one.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/stars-three-half.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/stars-three.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/stars-two-half.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/stars-two.png +0 -0
- data/sandbox/app/assets/sprites/a/assets/stars-zero.png +0 -0
- data/sandbox/app/assets/sprites/assets-hd/arrow-down.png +0 -0
- data/sandbox/app/assets/sprites/assets-hd/arrow-up.png +0 -0
- data/sandbox/app/assets/sprites/assets/arrow-down.png +0 -0
- data/sandbox/app/assets/sprites/assets/arrow-up.png +0 -0
- data/sandbox/app/assets/stylesheets/application.css +3 -0
- data/sandbox/app/assets/stylesheets/default-sprites.sass +8 -0
- data/sandbox/app/assets/stylesheets/experiment.sass +178 -0
- data/sandbox/app/assets/stylesheets/sandbox-sprites.css +6 -0
- data/sandbox/app/controllers/application_controller.rb +3 -0
- data/sandbox/app/controllers/ui_library_controller.rb +15 -0
- data/sandbox/app/views/layouts/ui.html.haml +18 -0
- data/sandbox/app/views/ui_library/boiler.html.haml +32 -0
- data/sandbox/app/views/ui_library/components.html.haml +189 -0
- data/sandbox/app/views/ui_library/index.html.haml +300 -0
- data/sandbox/config.ru +4 -0
- data/sandbox/config/application.rb +55 -0
- data/sandbox/config/boot.rb +10 -0
- data/sandbox/config/environment.rb +5 -0
- data/sandbox/config/environments/development.rb +35 -0
- data/sandbox/config/environments/production.rb +67 -0
- data/sandbox/config/environments/test.rb +39 -0
- data/sandbox/config/initializers/backtrace_silencers.rb +7 -0
- data/sandbox/config/initializers/inflections.rb +10 -0
- data/sandbox/config/initializers/mime_types.rb +5 -0
- data/sandbox/config/initializers/secret_token.rb +7 -0
- data/sandbox/config/initializers/session_store.rb +8 -0
- data/sandbox/config/initializers/wrap_parameters.rb +10 -0
- data/sandbox/config/locales/en.yml +5 -0
- data/sandbox/config/routes.rb +5 -0
- data/sandbox/doc/README_FOR_APP +2 -0
- data/sandbox/lib/sass/sprite_relative.rb +7 -0
- data/sandbox/public/404.html +26 -0
- data/sandbox/public/422.html +26 -0
- data/sandbox/public/500.html +26 -0
- data/sandbox/public/favicon.ico +0 -0
- data/sandbox/public/robots.txt +5 -0
- data/sandbox/script/rails +6 -0
- data/vendor/assets/javascripts/iugu-ux.js +7 -0
- data/vendor/assets/javascripts/iugu-ux/capabilities.js +209 -0
- data/vendor/assets/javascripts/iugu-ux/enable-prettify.js +3 -0
- data/vendor/assets/javascripts/iugu-ux/google-code-prettify/prettify.js +28 -0
- data/vendor/assets/javascripts/iugu-ux/iugu-ux.js +11 -0
- data/vendor/assets/javascripts/iugu-ux/twitter-bootstrap/bootstrap.js +7 -0
- data/vendor/assets/javascripts/iugu-ux/twitter-bootstrap/notice.js +90 -0
- data/vendor/assets/javascripts/iugu-ux/web-app.js +24 -0
- data/vendor/assets/javascripts/vendor.js +15 -0
- data/vendor/assets/javascripts/vendor/backbone.js +1479 -0
- data/vendor/assets/javascripts/vendor/gmaps.js +1058 -0
- data/vendor/assets/javascripts/vendor/iscroll.js +1080 -0
- data/vendor/assets/javascripts/vendor/jquery.base64.js +190 -0
- data/vendor/assets/javascripts/vendor/jquery.checkboxes.js +284 -0
- data/vendor/assets/javascripts/vendor/jquery.cookie.js +47 -0
- data/vendor/assets/javascripts/vendor/jquery.js +9267 -0
- data/vendor/assets/javascripts/vendor/jquery.ui.js +11363 -0
- data/vendor/assets/javascripts/vendor/jquery.ui.touch-punch.js +160 -0
- data/vendor/assets/javascripts/vendor/jquery.web-storage.js +489 -0
- data/vendor/assets/javascripts/vendor/underscore.js +1204 -0
- data/vendor/assets/javascripts/web-app/comm.coffee +1 -0
- data/vendor/assets/javascripts/web-app/config.js.erb +3 -0
- data/vendor/assets/javascripts/web-app/controllers.js +0 -0
- data/vendor/assets/javascripts/web-app/environment.js.coffee +8 -0
- data/vendor/assets/javascripts/web-app/helpers.coffee +86 -0
- data/vendor/assets/javascripts/web-app/i18n-languages.js +0 -0
- data/vendor/assets/javascripts/web-app/i18n.coffee +37 -0
- data/vendor/assets/javascripts/web-app/models.js +0 -0
- data/vendor/assets/javascripts/web-app/sound.coffee +67 -0
- data/vendor/assets/javascripts/web-app/views.js +0 -0
- data/vendor/assets/sprites/iux-default-hd/menu-icon.png +0 -0
- data/vendor/assets/sprites/iux-default/menu-icon.png +0 -0
- data/vendor/assets/stylesheets/iugu-ux.css +8 -0
- data/vendor/assets/stylesheets/iugu-ux/adaptative-mixins.sass +50 -0
- data/vendor/assets/stylesheets/iugu-ux/components.sass +185 -0
- data/vendor/assets/stylesheets/iugu-ux/core.sass +10 -0
- data/vendor/assets/stylesheets/iugu-ux/google-code-prettify/prettify.css +48 -0
- data/vendor/assets/stylesheets/iugu-ux/iugu-ux.sass +16 -0
- data/vendor/assets/stylesheets/iugu-ux/iux-sprites.sass +8 -0
- data/vendor/assets/stylesheets/iugu-ux/mixins.sass +32 -0
- data/vendor/assets/stylesheets/iugu-ux/no-js.sass +15 -0
- data/vendor/assets/stylesheets/iugu-ux/reset.sass +229 -0
- data/vendor/assets/stylesheets/iugu-ux/sprite-mixins.sass +49 -0
- data/vendor/assets/stylesheets/iugu-ux/typography.sass +268 -0
- data/vendor/assets/stylesheets/iugu-ux/utilities.sass +51 -0
- data/vendor/assets/stylesheets/iugu-ux/variables.sass +46 -0
- metadata +485 -0
@@ -0,0 +1,1058 @@
|
|
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($) {
|
10
|
+
"use strict";
|
11
|
+
|
12
|
+
var GMaps = function(options) {
|
13
|
+
var self = this;
|
14
|
+
var context_menu_style = 'position:absolute;display:none;min-width:100px;' +
|
15
|
+
'background:white;list-style:none;padding:8px;box-shadow:2px 2px 6px #ccc';
|
16
|
+
window.context_menu = {};
|
17
|
+
|
18
|
+
this.div = $(options.div)[0];
|
19
|
+
this.div.style.width = this.div.clientWidth || options.width;
|
20
|
+
this.div.style.height = this.div.clientHeight || options.height;
|
21
|
+
|
22
|
+
this.controls = [];
|
23
|
+
this.overlays = [];
|
24
|
+
this.layers = [];
|
25
|
+
this.markers = [];
|
26
|
+
this.polylines = [];
|
27
|
+
this.routes = [];
|
28
|
+
this.polygons = [];
|
29
|
+
this.infoWindow = null;
|
30
|
+
this.overlay_div = null;
|
31
|
+
this.zoom = options.zoom || 15;
|
32
|
+
|
33
|
+
//'Hybrid', 'Roadmap', 'Satellite' or 'Terrain'
|
34
|
+
var mapType;
|
35
|
+
|
36
|
+
if (options.mapType) {
|
37
|
+
mapType = google.maps.MapTypeId[options.mapType.toUpperCase()];
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
mapType = google.maps.MapTypeId.ROADMAP;
|
41
|
+
}
|
42
|
+
|
43
|
+
var map_center = new google.maps.LatLng(options.lat, options.lng);
|
44
|
+
|
45
|
+
delete options.lat;
|
46
|
+
delete options.lng;
|
47
|
+
delete options.mapType;
|
48
|
+
delete options.width;
|
49
|
+
delete options.height;
|
50
|
+
|
51
|
+
var map_base_options = {
|
52
|
+
zoom: this.zoom,
|
53
|
+
center: map_center,
|
54
|
+
mapTypeId: mapType
|
55
|
+
};
|
56
|
+
|
57
|
+
var map_options = $.extend(map_base_options, options);
|
58
|
+
|
59
|
+
this.map = new google.maps.Map(this.div, map_options);
|
60
|
+
|
61
|
+
// Context menus
|
62
|
+
var buildContextMenuHTML = function(control, e) {
|
63
|
+
var html = '';
|
64
|
+
var options = window.context_menu[control];
|
65
|
+
for (var i in options){
|
66
|
+
if (options.hasOwnProperty(i)){
|
67
|
+
var option = options[i];
|
68
|
+
html += '<li><a id="' + control + '_' + i + '" href="#">' +
|
69
|
+
option.title + '</a></li>';
|
70
|
+
}
|
71
|
+
}
|
72
|
+
var $context_menu = $('#gmaps_context_menu');
|
73
|
+
$context_menu.html(html);
|
74
|
+
$context_menu.undelegate();
|
75
|
+
$context_menu.delegate('li a', 'click', function(ev) {
|
76
|
+
ev.preventDefault();
|
77
|
+
options[$(this).attr('id').replace(control + '_', '')].action.call(self, e);
|
78
|
+
self.hideContextMenu();
|
79
|
+
});
|
80
|
+
|
81
|
+
var left = $(self.div).offset().left + e.pixel.x - 15;
|
82
|
+
var top = $(self.div).offset().top + e.pixel.y - 15;
|
83
|
+
$context_menu.css({
|
84
|
+
left: left,
|
85
|
+
top: top
|
86
|
+
}).fadeIn(200);
|
87
|
+
};
|
88
|
+
|
89
|
+
var buildContextMenu = function(control, e) {
|
90
|
+
if (control === 'marker') {
|
91
|
+
e.pixel = {};
|
92
|
+
var overlay = new google.maps.OverlayView();
|
93
|
+
overlay.setMap(self.map);
|
94
|
+
overlay.draw = function() {
|
95
|
+
var projection = overlay.getProjection();
|
96
|
+
var position = e.marker.getPosition();
|
97
|
+
e.pixel = projection.fromLatLngToContainerPixel(position);
|
98
|
+
|
99
|
+
buildContextMenuHTML(control, e);
|
100
|
+
};
|
101
|
+
}
|
102
|
+
else {
|
103
|
+
buildContextMenuHTML(control, e);
|
104
|
+
}
|
105
|
+
};
|
106
|
+
|
107
|
+
this.setContextMenu = function(options) {
|
108
|
+
window.context_menu[options.control] = {};
|
109
|
+
var html = '<ul id="gmaps_context_menu" style="' + context_menu_style + '"></ul>';
|
110
|
+
for (var i in options.options){
|
111
|
+
if (options.options.hasOwnProperty(i)){
|
112
|
+
var option = options.options[i];
|
113
|
+
window.context_menu[options.control][option.name] = {
|
114
|
+
title: option.title,
|
115
|
+
action: option.action
|
116
|
+
};
|
117
|
+
}
|
118
|
+
}
|
119
|
+
$('body').append(html);
|
120
|
+
$('#gmaps_context_menu').mouseleave(function() {
|
121
|
+
$(this).delay(100).fadeOut(200);
|
122
|
+
});
|
123
|
+
};
|
124
|
+
|
125
|
+
this.hideContextMenu = function() {
|
126
|
+
$('#gmaps_context_menu').fadeOut(200);
|
127
|
+
};
|
128
|
+
|
129
|
+
//Events
|
130
|
+
|
131
|
+
var events_that_hide_context_menu = ['bounds_changed', 'center_changed', 'click', 'dblclick', 'drag', 'dragend', 'dragstart', 'idle', 'maptypeid_changed', 'projection_changed', 'resize', 'tilesloaded', 'zoom_changed'];
|
132
|
+
var events_that_doesnt_hide_context_menu = ['mousemove', 'mouseout', 'mouseover'];
|
133
|
+
|
134
|
+
for (var ev = 0; ev < events_that_hide_context_menu.length; ev++) {
|
135
|
+
(function(object, name) {
|
136
|
+
google.maps.event.addListener(object, name, function(e){
|
137
|
+
if (options[name])
|
138
|
+
options[name].apply(this, [e]);
|
139
|
+
|
140
|
+
self.hideContextMenu();
|
141
|
+
});
|
142
|
+
})(this.map, events_that_hide_context_menu[ev]);
|
143
|
+
}
|
144
|
+
|
145
|
+
for (var ev = 0; ev < events_that_doesnt_hide_context_menu.length; ev++) {
|
146
|
+
(function(object, name) {
|
147
|
+
google.maps.event.addListener(object, name, function(e){
|
148
|
+
if (options[name])
|
149
|
+
options[name].apply(this, [e]);
|
150
|
+
});
|
151
|
+
})(this.map, events_that_doesnt_hide_context_menu[ev]);
|
152
|
+
}
|
153
|
+
|
154
|
+
google.maps.event.addListener(this.map, 'rightclick', function(e) {
|
155
|
+
if (options.rightclick) {
|
156
|
+
options.rightclick.apply(this, [e]);
|
157
|
+
}
|
158
|
+
|
159
|
+
buildContextMenu('map', e);
|
160
|
+
});
|
161
|
+
|
162
|
+
this.refresh = function() {
|
163
|
+
google.maps.event.trigger(this.map, 'resize');
|
164
|
+
};
|
165
|
+
|
166
|
+
// Map methods
|
167
|
+
this.setCenter = function(lat, lng, callback) {
|
168
|
+
this.map.panTo(new google.maps.LatLng(lat, lng));
|
169
|
+
if (callback) {
|
170
|
+
callback();
|
171
|
+
}
|
172
|
+
};
|
173
|
+
|
174
|
+
this.getCenter = function() {
|
175
|
+
return this.map.getCenter();
|
176
|
+
};
|
177
|
+
|
178
|
+
this.getDiv = function() {
|
179
|
+
return this.div;
|
180
|
+
};
|
181
|
+
|
182
|
+
this.setZoom = function(value) {
|
183
|
+
this.map.setZoom(value);
|
184
|
+
};
|
185
|
+
|
186
|
+
this.zoomIn = function(value) {
|
187
|
+
this.map.setZoom(this.map.getZoom() + value);
|
188
|
+
};
|
189
|
+
|
190
|
+
this.zoomOut = function(value) {
|
191
|
+
this.map.setZoom(this.map.getZoom() - value);
|
192
|
+
};
|
193
|
+
|
194
|
+
this.createControl = function(options) {
|
195
|
+
options.style.cursor = 'pointer';
|
196
|
+
options.style.fontFamily = 'Arial, sans-serif';
|
197
|
+
options.style.fontSize = '13px';
|
198
|
+
options.style.boxShadow = 'rgba(0, 0, 0, 0.398438) 0px 2px 4px';
|
199
|
+
|
200
|
+
var controlDiv = $('<div></div>');
|
201
|
+
controlDiv.css(options.style);
|
202
|
+
controlDiv.text(options.text);
|
203
|
+
|
204
|
+
var control = controlDiv[0];
|
205
|
+
|
206
|
+
for (var ev in options.events) {
|
207
|
+
(function(object, name) {
|
208
|
+
google.maps.event.addDomListener(object, name, function(){
|
209
|
+
options.events[name].apply(this, [this]);
|
210
|
+
});
|
211
|
+
})(control, ev);
|
212
|
+
}
|
213
|
+
|
214
|
+
control.index = 1;
|
215
|
+
|
216
|
+
return control;
|
217
|
+
};
|
218
|
+
|
219
|
+
this.addControl = function(options) {
|
220
|
+
var position = google.maps.ControlPosition[options.position.toUpperCase()];
|
221
|
+
|
222
|
+
delete options.position;
|
223
|
+
|
224
|
+
var control = this.createControl(options);
|
225
|
+
this.controls.push(control);
|
226
|
+
this.map.controls[position].push(control);
|
227
|
+
|
228
|
+
return control;
|
229
|
+
};
|
230
|
+
|
231
|
+
// Markers
|
232
|
+
this.createMarker = function(options) {
|
233
|
+
if (options.lat && options.lng) {
|
234
|
+
var self = this;
|
235
|
+
var details = options.details;
|
236
|
+
var fences = options.fences;
|
237
|
+
var outside = options.outside;
|
238
|
+
var base_options = {
|
239
|
+
position: new google.maps.LatLng(options.lat, options.lng),
|
240
|
+
map: null
|
241
|
+
};
|
242
|
+
delete options.lat;
|
243
|
+
delete options.lng;
|
244
|
+
delete options.fences;
|
245
|
+
delete options.outside;
|
246
|
+
|
247
|
+
var marker_options = $.extend(base_options, options);
|
248
|
+
|
249
|
+
var marker = new google.maps.Marker(marker_options);
|
250
|
+
|
251
|
+
marker.fences = fences;
|
252
|
+
|
253
|
+
if (options.infoWindow) {
|
254
|
+
marker.infoWindow = new google.maps.InfoWindow(options.infoWindow);
|
255
|
+
|
256
|
+
var info_window_events = ['closeclick', 'content_changed', 'domready', 'position_changed', 'zindex_changed'];
|
257
|
+
|
258
|
+
for (var ev = 0; ev < info_window_events.length; ev++) {
|
259
|
+
(function(object, name) {
|
260
|
+
google.maps.event.addListener(object, name, function(e){
|
261
|
+
if (options.infoWindow[name])
|
262
|
+
options.infoWindow[name].apply(this, [e]);
|
263
|
+
});
|
264
|
+
})(marker.infoWindow, info_window_events[ev]);
|
265
|
+
}
|
266
|
+
}
|
267
|
+
|
268
|
+
var marker_events = ['drag', 'dragstart', 'mouseout', 'mouseover', 'mouseup', 'position_changed'];
|
269
|
+
|
270
|
+
for (var ev = 0; ev < marker_events.length; ev++) {
|
271
|
+
(function(object, name) {
|
272
|
+
google.maps.event.addListener(object, name, function(){
|
273
|
+
if (options[name])
|
274
|
+
options[name].apply(this, [this]);
|
275
|
+
});
|
276
|
+
})(marker, marker_events[ev]);
|
277
|
+
}
|
278
|
+
|
279
|
+
google.maps.event.addListener(marker, 'click', function() {
|
280
|
+
this.details = details;
|
281
|
+
|
282
|
+
if (options.click) {
|
283
|
+
options.click.apply(this, [this]);
|
284
|
+
}
|
285
|
+
|
286
|
+
if (marker.infoWindow) {
|
287
|
+
self.hideInfoWindows();
|
288
|
+
marker.infoWindow.open(self.map, marker);
|
289
|
+
}
|
290
|
+
});
|
291
|
+
|
292
|
+
if (options.dragend || marker.fences) {
|
293
|
+
google.maps.event.addListener(marker, 'dragend', function() {
|
294
|
+
if (options.dragend) {
|
295
|
+
options.dragend.apply(this, [this]);
|
296
|
+
}
|
297
|
+
if (marker.fences) {
|
298
|
+
self.checkMarkerGeofence(marker, function(m, f) {
|
299
|
+
outside(m, f);
|
300
|
+
});
|
301
|
+
}
|
302
|
+
});
|
303
|
+
}
|
304
|
+
|
305
|
+
return marker;
|
306
|
+
}
|
307
|
+
else {
|
308
|
+
throw 'No latitude or longitude defined';
|
309
|
+
}
|
310
|
+
};
|
311
|
+
|
312
|
+
this.addMarker = function(options) {
|
313
|
+
if (options.lat && options.lng) {
|
314
|
+
var marker = this.createMarker(options);
|
315
|
+
marker.setMap(this.map);
|
316
|
+
this.markers.push(marker);
|
317
|
+
|
318
|
+
return marker;
|
319
|
+
}
|
320
|
+
else {
|
321
|
+
throw 'No latitude or longitude defined';
|
322
|
+
}
|
323
|
+
};
|
324
|
+
|
325
|
+
this.addMarkers = function(array) {
|
326
|
+
for (var i=0, marker; marker=array[i]; i++) {
|
327
|
+
this.addMarker(marker);
|
328
|
+
}
|
329
|
+
return this.markers;
|
330
|
+
};
|
331
|
+
|
332
|
+
this.hideInfoWindows = function() {
|
333
|
+
for (var i=0, marker; marker=this.markers[i]; i++){
|
334
|
+
if (marker.infoWindow){
|
335
|
+
marker.infoWindow.close();
|
336
|
+
}
|
337
|
+
}
|
338
|
+
};
|
339
|
+
|
340
|
+
this.removeMarkers = function() {
|
341
|
+
for (var i=0, marker; marker=this.markers[i]; i++){
|
342
|
+
marker.setMap(null);
|
343
|
+
}
|
344
|
+
this.markers = [];
|
345
|
+
};
|
346
|
+
|
347
|
+
// Overlays
|
348
|
+
this.drawOverlay = function(options) {
|
349
|
+
var overlay = new google.maps.OverlayView();
|
350
|
+
overlay.setMap(self.map);
|
351
|
+
|
352
|
+
overlay.onAdd = function() {
|
353
|
+
var div = document.createElement('div');
|
354
|
+
div.style.borderStyle = "none";
|
355
|
+
div.style.borderWidth = "0px";
|
356
|
+
div.style.position = "absolute";
|
357
|
+
div.innerHTML = options.content;
|
358
|
+
|
359
|
+
self.overlay_div = div;
|
360
|
+
|
361
|
+
var panes = this.getPanes();
|
362
|
+
if (!options.layer) {
|
363
|
+
options.layer = 'overlayLayer';
|
364
|
+
}
|
365
|
+
var overlayLayer = panes[options.layer];
|
366
|
+
overlayLayer.appendChild(div);
|
367
|
+
};
|
368
|
+
|
369
|
+
overlay.draw = function() {
|
370
|
+
var projection = this.getProjection();
|
371
|
+
var pixel = projection.fromLatLngToDivPixel(new google.maps.LatLng(options.lat, options.lng));
|
372
|
+
|
373
|
+
options.horizontalOffset = options.horizontalOffset || 0;
|
374
|
+
options.verticalOffset = options.verticalOffset || 0;
|
375
|
+
|
376
|
+
var div = self.overlay_div;
|
377
|
+
var content = div.children;
|
378
|
+
|
379
|
+
switch (options.verticalAlign) {
|
380
|
+
case 'top':
|
381
|
+
div.style.top = (pixel.y - $(content).height() + options.verticalOffset) + 'px';
|
382
|
+
break;
|
383
|
+
default:
|
384
|
+
case 'middle':
|
385
|
+
div.style.top = (pixel.y - ($(content).height() / 2) + options.verticalOffset) + 'px';
|
386
|
+
break;
|
387
|
+
case 'bottom':
|
388
|
+
div.style.top = (pixel.y + options.verticalOffset) + 'px';
|
389
|
+
break;
|
390
|
+
}
|
391
|
+
|
392
|
+
switch (options.horizontalAlign) {
|
393
|
+
case 'left':
|
394
|
+
div.style.left = (pixel.x - $(content).width() + options.horizontalOffset) + 'px';
|
395
|
+
break;
|
396
|
+
default:
|
397
|
+
case 'center':
|
398
|
+
div.style.left = (pixel.x - ($(content).width() / 2) + options.horizontalOffset) + 'px';
|
399
|
+
break;
|
400
|
+
case 'right':
|
401
|
+
div.style.left = (pixel.x + options.horizontalOffset) + 'px';
|
402
|
+
break;
|
403
|
+
}
|
404
|
+
};
|
405
|
+
|
406
|
+
overlay.onRemove = function() {
|
407
|
+
self.overlay_div.parentNode.removeChild(self.overlay_div);
|
408
|
+
self.overlay_div = null;
|
409
|
+
};
|
410
|
+
self.overlays.push(overlay);
|
411
|
+
return overlay;
|
412
|
+
};
|
413
|
+
|
414
|
+
this.removeOverlay = function(overlay) {
|
415
|
+
overlay.setMap(null);
|
416
|
+
};
|
417
|
+
|
418
|
+
this.removeOverlays = function() {
|
419
|
+
for (var i=0, item; item=self.overlays[i]; i++){
|
420
|
+
item.setMap(null);
|
421
|
+
}
|
422
|
+
self.overlays = [];
|
423
|
+
};
|
424
|
+
|
425
|
+
this.drawPolyline = function(options) {
|
426
|
+
var path = [];
|
427
|
+
var points = options.path;
|
428
|
+
|
429
|
+
if (points.length){
|
430
|
+
if (points[0][0] === undefined){
|
431
|
+
path = points;
|
432
|
+
}
|
433
|
+
else {
|
434
|
+
for (var i=0, latlng; latlng=points[i]; i++){
|
435
|
+
path.push(new google.maps.LatLng(latlng[0], latlng[1]));
|
436
|
+
}
|
437
|
+
}
|
438
|
+
}
|
439
|
+
|
440
|
+
var polyline = new google.maps.Polyline({
|
441
|
+
map: this.map,
|
442
|
+
path: path,
|
443
|
+
strokeColor: options.strokeColor,
|
444
|
+
strokeOpacity: options.strokeOpacity,
|
445
|
+
strokeWeight: options.strokeWeight
|
446
|
+
});
|
447
|
+
|
448
|
+
var polyline_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
|
449
|
+
|
450
|
+
for (var ev = 0; ev < polyline_events.length; ev++) {
|
451
|
+
(function(object, name) {
|
452
|
+
google.maps.event.addListener(object, name, function(e){
|
453
|
+
if (options[name])
|
454
|
+
options[name].apply(this, [e]);
|
455
|
+
});
|
456
|
+
})(polyline, polyline_events[ev]);
|
457
|
+
}
|
458
|
+
|
459
|
+
this.polylines.push(polyline);
|
460
|
+
|
461
|
+
return polyline;
|
462
|
+
};
|
463
|
+
|
464
|
+
this.drawCircle = function(options) {
|
465
|
+
options = $.extend({
|
466
|
+
map: this.map,
|
467
|
+
center: new google.maps.LatLng(options.lat, options.lng)
|
468
|
+
}, options);
|
469
|
+
|
470
|
+
delete options.lat;
|
471
|
+
delete options.lng;
|
472
|
+
var polygon = new google.maps.Circle(options);
|
473
|
+
|
474
|
+
var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
|
475
|
+
|
476
|
+
for (var ev = 0; ev < polygon_events.length; ev++) {
|
477
|
+
(function(object, name) {
|
478
|
+
google.maps.event.addListener(object, name, function(e){
|
479
|
+
if (options[name])
|
480
|
+
options[name].apply(this, [e]);
|
481
|
+
});
|
482
|
+
})(polygon, polygon_events[ev]);
|
483
|
+
}
|
484
|
+
|
485
|
+
return polygon;
|
486
|
+
};
|
487
|
+
|
488
|
+
this.drawPolygon = function(options) {
|
489
|
+
options = $.extend({
|
490
|
+
map: this.map
|
491
|
+
}, options);
|
492
|
+
|
493
|
+
if($.isArray(options.paths)) {
|
494
|
+
if($.isArray(options.paths[0])) {
|
495
|
+
options.paths = $.map(options.paths, arrayToLatLng);
|
496
|
+
}
|
497
|
+
}
|
498
|
+
|
499
|
+
var polygon = new google.maps.Polygon(options);
|
500
|
+
|
501
|
+
var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
|
502
|
+
|
503
|
+
for (var ev = 0; ev < polygon_events.length; ev++) {
|
504
|
+
(function(object, name) {
|
505
|
+
google.maps.event.addListener(object, name, function(e){
|
506
|
+
if (options[name])
|
507
|
+
options[name].apply(this, [e]);
|
508
|
+
});
|
509
|
+
})(polygon, polygon_events[ev]);
|
510
|
+
}
|
511
|
+
|
512
|
+
this.polygons.push(polygon);
|
513
|
+
|
514
|
+
return polygon;
|
515
|
+
|
516
|
+
function arrayToLatLng(coords) {
|
517
|
+
return new google.maps.LatLng(coords[0], coords[1]);
|
518
|
+
}
|
519
|
+
};
|
520
|
+
|
521
|
+
this.getFromFusionTables = function(options) {
|
522
|
+
var events = options.events;
|
523
|
+
|
524
|
+
delete options.events;
|
525
|
+
|
526
|
+
var fusion_tables_options = options;
|
527
|
+
|
528
|
+
var layer = new google.maps.FusionTablesLayer(fusion_tables_options);
|
529
|
+
|
530
|
+
for (var ev in events) {
|
531
|
+
(function(object, name) {
|
532
|
+
google.maps.event.addListener(object, name, function(e){
|
533
|
+
events[name].apply(this, [e]);
|
534
|
+
});
|
535
|
+
})(layer, ev);
|
536
|
+
}
|
537
|
+
|
538
|
+
this.layers.push(layer);
|
539
|
+
|
540
|
+
return layer;
|
541
|
+
};
|
542
|
+
|
543
|
+
this.loadFromFusionTables = function(options) {
|
544
|
+
var layer = this.getFromFusionTables(options);
|
545
|
+
layer.setMap(this.map);
|
546
|
+
|
547
|
+
return layer;
|
548
|
+
};
|
549
|
+
|
550
|
+
this.getFromKML = function(options) {
|
551
|
+
var url = options.url;
|
552
|
+
var events = options.events;
|
553
|
+
|
554
|
+
delete options.url;
|
555
|
+
delete options.events;
|
556
|
+
|
557
|
+
var kml_options = options;
|
558
|
+
|
559
|
+
var layer = new google.maps.KmlLayer(url, kml_options);
|
560
|
+
|
561
|
+
for (var ev in events) {
|
562
|
+
(function(object, name) {
|
563
|
+
google.maps.event.addListener(object, name, function(e){
|
564
|
+
events[name].apply(this, [e]);
|
565
|
+
});
|
566
|
+
})(layer, ev);
|
567
|
+
}
|
568
|
+
|
569
|
+
this.layers.push(layer);
|
570
|
+
|
571
|
+
return layer;
|
572
|
+
};
|
573
|
+
|
574
|
+
this.loadFromKML = function(options) {
|
575
|
+
var layer = this.getFromKML(options);
|
576
|
+
layer.setMap(this.map);
|
577
|
+
|
578
|
+
return layer;
|
579
|
+
};
|
580
|
+
|
581
|
+
// Services
|
582
|
+
var travelMode, unitSystem;
|
583
|
+
this.getRoutes = function(options) {
|
584
|
+
switch (options.travelMode) {
|
585
|
+
case 'bicycling':
|
586
|
+
travelMode = google.maps.TravelMode.BICYCLING;
|
587
|
+
break;
|
588
|
+
case 'driving':
|
589
|
+
travelMode = google.maps.TravelMode.DRIVING;
|
590
|
+
break;
|
591
|
+
// case 'walking':
|
592
|
+
default:
|
593
|
+
travelMode = google.maps.TravelMode.WALKING;
|
594
|
+
break;
|
595
|
+
}
|
596
|
+
|
597
|
+
if (options.unitSystem === 'imperial') {
|
598
|
+
unitSystem = google.maps.UnitSystem.IMPERIAL;
|
599
|
+
}
|
600
|
+
else {
|
601
|
+
unitSystem = google.maps.UnitSystem.METRIC;
|
602
|
+
}
|
603
|
+
|
604
|
+
var base_options = {
|
605
|
+
avoidHighways: false,
|
606
|
+
avoidTolls: false,
|
607
|
+
optimizeWaypoints: false,
|
608
|
+
waypoints: []
|
609
|
+
};
|
610
|
+
var request_options = $.extend(base_options, options);
|
611
|
+
request_options.origin = new google.maps.LatLng(options.origin[0], options.origin[1]);
|
612
|
+
request_options.destination = new google.maps.LatLng(options.destination[0], options.destination[1]);
|
613
|
+
request_options.travelMode = travelMode;
|
614
|
+
request_options.unitSystem = unitSystem;
|
615
|
+
|
616
|
+
delete request_options.callback;
|
617
|
+
|
618
|
+
var self = this;
|
619
|
+
var service = new google.maps.DirectionsService();
|
620
|
+
|
621
|
+
service.route(request_options, function(result, status) {
|
622
|
+
if (status === google.maps.DirectionsStatus.OK) {
|
623
|
+
for (var r in result.routes) {
|
624
|
+
if (result.routes.hasOwnProperty(r)) {
|
625
|
+
self.routes.push(result.routes[r]);
|
626
|
+
}
|
627
|
+
}
|
628
|
+
}
|
629
|
+
if (options.callback) {
|
630
|
+
options.callback(self.routes);
|
631
|
+
}
|
632
|
+
});
|
633
|
+
};
|
634
|
+
|
635
|
+
this.drawRoute = function(options) {
|
636
|
+
var self = this;
|
637
|
+
this.getRoutes({
|
638
|
+
origin: options.origin,
|
639
|
+
destination: options.destination,
|
640
|
+
travelMode: options.travelMode,
|
641
|
+
callback: function(e) {
|
642
|
+
if (e.length > 0) {
|
643
|
+
self.drawPolyline({
|
644
|
+
path: e[e.length - 1].overview_path,
|
645
|
+
strokeColor: options.strokeColor,
|
646
|
+
strokeOpacity: options.strokeOpacity,
|
647
|
+
strokeWeight: options.strokeWeight
|
648
|
+
});
|
649
|
+
if (options.callback) {
|
650
|
+
options.callback(e[e.length - 1]);
|
651
|
+
}
|
652
|
+
}
|
653
|
+
}
|
654
|
+
});
|
655
|
+
};
|
656
|
+
|
657
|
+
this.travelRoute = function(options) {
|
658
|
+
if (options.origin && options.destination) {
|
659
|
+
this.getRoutes({
|
660
|
+
origin: options.origin,
|
661
|
+
destination: options.destination,
|
662
|
+
travelMode: options.travelMode,
|
663
|
+
callback: function(e) {
|
664
|
+
if (e.length > 0 && options.step) {
|
665
|
+
var route = e[e.length - 1];
|
666
|
+
if (route.legs.length > 0) {
|
667
|
+
var steps = route.legs[0].steps;
|
668
|
+
for (var i=0, step; step=steps[i]; i++) {
|
669
|
+
step.step_number = i;
|
670
|
+
options.step(step);
|
671
|
+
}
|
672
|
+
}
|
673
|
+
}
|
674
|
+
}
|
675
|
+
});
|
676
|
+
}
|
677
|
+
else if (options.route) {
|
678
|
+
if (options.route.legs.length > 0) {
|
679
|
+
var steps = options.route.legs[0].steps;
|
680
|
+
for (var i=0, step; step=steps[i]; i++) {
|
681
|
+
step.step_number = i;
|
682
|
+
options.step(step);
|
683
|
+
}
|
684
|
+
}
|
685
|
+
}
|
686
|
+
};
|
687
|
+
|
688
|
+
this.drawSteppedRoute = function(options) {
|
689
|
+
if (options.origin && options.destination) {
|
690
|
+
this.getRoutes({
|
691
|
+
origin: options.origin,
|
692
|
+
destination: options.destination,
|
693
|
+
travelMode: options.travelMode,
|
694
|
+
callback: function(e) {
|
695
|
+
if (e.length > 0 && options.step) {
|
696
|
+
var route = e[e.length - 1];
|
697
|
+
if (route.legs.length > 0) {
|
698
|
+
var steps = route.legs[0].steps;
|
699
|
+
for (var i=0, step; step=steps[i]; i++) {
|
700
|
+
step.step_number = i;
|
701
|
+
self.drawPolyline({
|
702
|
+
path: step.path,
|
703
|
+
strokeColor: options.strokeColor,
|
704
|
+
strokeOpacity: options.strokeOpacity,
|
705
|
+
strokeWeight: options.strokeWeight
|
706
|
+
});
|
707
|
+
options.step(step);
|
708
|
+
}
|
709
|
+
}
|
710
|
+
}
|
711
|
+
}
|
712
|
+
});
|
713
|
+
}
|
714
|
+
else if (options.route) {
|
715
|
+
if (options.route.legs.length > 0) {
|
716
|
+
var steps = options.route.legs[0].steps;
|
717
|
+
for (var i=0, step; step=steps[i]; i++) {
|
718
|
+
step.step_number = i;
|
719
|
+
self.drawPolyline({
|
720
|
+
path: step.path,
|
721
|
+
strokeColor: options.strokeColor,
|
722
|
+
strokeOpacity: options.strokeOpacity,
|
723
|
+
strokeWeight: options.strokeWeight
|
724
|
+
});
|
725
|
+
options.step(step);
|
726
|
+
}
|
727
|
+
}
|
728
|
+
}
|
729
|
+
};
|
730
|
+
|
731
|
+
// Geofence
|
732
|
+
this.checkGeofence = function(lat, lng, fence) {
|
733
|
+
return fence.containsLatLng(new google.maps.LatLng(lat, lng));
|
734
|
+
};
|
735
|
+
|
736
|
+
this.checkMarkerGeofence = function(marker, outside_callback) {
|
737
|
+
if (marker.fences) {
|
738
|
+
for (var i=0, fence; fence=marker.fences[i]; i++) {
|
739
|
+
var pos = marker.getPosition();
|
740
|
+
if (!self.checkGeofence(pos.lat(), pos.lng(), fence)) {
|
741
|
+
outside_callback(marker, fence);
|
742
|
+
}
|
743
|
+
}
|
744
|
+
}
|
745
|
+
};
|
746
|
+
};
|
747
|
+
|
748
|
+
GMaps.Route = function(options) {
|
749
|
+
this.map = options.map;
|
750
|
+
this.route = options.route;
|
751
|
+
this.step_count = 0;
|
752
|
+
this.steps = this.route.legs[0].steps;
|
753
|
+
this.steps_length = this.steps.length;
|
754
|
+
|
755
|
+
this.polyline = this.map.drawPolyline({
|
756
|
+
path: new google.maps.MVCArray(),
|
757
|
+
strokeColor: options.strokeColor,
|
758
|
+
strokeOpacity: options.strokeOpacity,
|
759
|
+
strokeWeight: options.strokeWeight
|
760
|
+
}).getPath();
|
761
|
+
|
762
|
+
this.back = function() {
|
763
|
+
if (this.step_count > 0) {
|
764
|
+
this.step_count--;
|
765
|
+
var path = this.route.legs[0].steps[this.step_count].path;
|
766
|
+
for (var p in path){
|
767
|
+
if (path.hasOwnProperty(p)){
|
768
|
+
this.polyline.pop();
|
769
|
+
}
|
770
|
+
}
|
771
|
+
}
|
772
|
+
};
|
773
|
+
|
774
|
+
this.forward = function() {
|
775
|
+
if (this.step_count < this.steps_length) {
|
776
|
+
var path = this.route.legs[0].steps[this.step_count].path;
|
777
|
+
for (var p in path){
|
778
|
+
if (path.hasOwnProperty(p)){
|
779
|
+
this.polyline.push(path[p]);
|
780
|
+
}
|
781
|
+
}
|
782
|
+
this.step_count++;
|
783
|
+
}
|
784
|
+
};
|
785
|
+
};
|
786
|
+
|
787
|
+
// Geolocation (Modern browsers only)
|
788
|
+
GMaps.geolocate = function(options) {
|
789
|
+
if (navigator.geolocation) {
|
790
|
+
navigator.geolocation.getCurrentPosition(function(position) {
|
791
|
+
options.success(position);
|
792
|
+
if (options.always) {
|
793
|
+
options.always();
|
794
|
+
}
|
795
|
+
}, function(error) {
|
796
|
+
options.error(error);
|
797
|
+
if (options.always) {
|
798
|
+
options.always();
|
799
|
+
}
|
800
|
+
}, options.options);
|
801
|
+
}
|
802
|
+
else {
|
803
|
+
options.not_supported();
|
804
|
+
if (options.always) {
|
805
|
+
options.always();
|
806
|
+
}
|
807
|
+
}
|
808
|
+
};
|
809
|
+
|
810
|
+
// Geocoding
|
811
|
+
GMaps.geocode = function(options) {
|
812
|
+
this.geocoder = new google.maps.Geocoder();
|
813
|
+
var callback = options.callback;
|
814
|
+
if (options.lat && options.lng) {
|
815
|
+
options.latLng = new google.maps.LatLng(options.lat, options.lng);
|
816
|
+
}
|
817
|
+
|
818
|
+
delete options.lat;
|
819
|
+
delete options.lng;
|
820
|
+
delete options.callback;
|
821
|
+
this.geocoder.geocode(options, function(results, status) {
|
822
|
+
callback(results, status);
|
823
|
+
});
|
824
|
+
};
|
825
|
+
|
826
|
+
// Static maps
|
827
|
+
GMaps.staticMapURL = function(options){
|
828
|
+
var parameters = [];
|
829
|
+
var data;
|
830
|
+
|
831
|
+
var static_root = 'http://maps.googleapis.com/maps/api/staticmap';
|
832
|
+
if (options.url){
|
833
|
+
static_root = options.url;
|
834
|
+
delete options.url;
|
835
|
+
}
|
836
|
+
static_root += '?';
|
837
|
+
|
838
|
+
var markers = options.markers;
|
839
|
+
delete options.markers;
|
840
|
+
if (!markers && options.marker){
|
841
|
+
markers = [options.marker];
|
842
|
+
delete options.marker;
|
843
|
+
}
|
844
|
+
|
845
|
+
var polyline = options.polyline;
|
846
|
+
delete options.polyline;
|
847
|
+
|
848
|
+
/** Map options **/
|
849
|
+
if (options.center){
|
850
|
+
parameters.push('center=' + options.center);
|
851
|
+
delete options.center;
|
852
|
+
}
|
853
|
+
else if (options.address){
|
854
|
+
parameters.push('center=' + options.address);
|
855
|
+
delete options.address;
|
856
|
+
}
|
857
|
+
else if (options.lat){
|
858
|
+
parameters.push(['center=', options.lat, ',', options.lng].join(''));
|
859
|
+
delete options.lat;
|
860
|
+
delete options.lng;
|
861
|
+
}
|
862
|
+
else if (options.visible){
|
863
|
+
var visible = encodeURI(options.visible.join('|'));
|
864
|
+
parameters.push('visible=' + visible);
|
865
|
+
}
|
866
|
+
|
867
|
+
var size = options.size;
|
868
|
+
if (size){
|
869
|
+
if (size.join){
|
870
|
+
size = size.join('x');
|
871
|
+
}
|
872
|
+
delete options.size;
|
873
|
+
}
|
874
|
+
else {
|
875
|
+
size = '630x300';
|
876
|
+
}
|
877
|
+
parameters.push('size=' + size);
|
878
|
+
|
879
|
+
if (!options.zoom){
|
880
|
+
options.zoom = 15;
|
881
|
+
}
|
882
|
+
|
883
|
+
var sensor = options.hasOwnProperty('sensor') ? !!options.sensor : true;
|
884
|
+
delete options.sensor;
|
885
|
+
parameters.push('sensor=' + sensor);
|
886
|
+
|
887
|
+
for (var param in options){
|
888
|
+
if (options.hasOwnProperty(param)){
|
889
|
+
parameters.push(param + '=' + options[param]);
|
890
|
+
}
|
891
|
+
}
|
892
|
+
|
893
|
+
/** Markers **/
|
894
|
+
if (markers){
|
895
|
+
var marker, loc;
|
896
|
+
|
897
|
+
for (var i=0; data=markers[i]; i++){
|
898
|
+
marker = [];
|
899
|
+
|
900
|
+
if (data.size && data.size !== 'normal'){
|
901
|
+
marker.push('size:' + data.size);
|
902
|
+
}
|
903
|
+
else if (data.icon){
|
904
|
+
marker.push('icon:' + encodeURI(data.icon));
|
905
|
+
}
|
906
|
+
|
907
|
+
if (data.color){
|
908
|
+
marker.push('color:' + data.color.replace('#', '0x'));
|
909
|
+
}
|
910
|
+
|
911
|
+
if (data.label){
|
912
|
+
marker.push('label:' + data.label[0].toUpperCase());
|
913
|
+
}
|
914
|
+
|
915
|
+
loc = (data.address ? data.address : data.lat + ',' + data.lng);
|
916
|
+
|
917
|
+
if (marker.length || i === 0){
|
918
|
+
marker.push(loc);
|
919
|
+
marker = marker.join('|');
|
920
|
+
parameters.push('markers=' + encodeURI(marker));
|
921
|
+
}
|
922
|
+
// New marker without styles
|
923
|
+
else {
|
924
|
+
marker = parameters.pop() + encodeURI('|' + loc);
|
925
|
+
parameters.push(marker);
|
926
|
+
}
|
927
|
+
}
|
928
|
+
}
|
929
|
+
|
930
|
+
/** Polylines **/
|
931
|
+
function parseColor(color, opacity){
|
932
|
+
if (color[0] === '#'){
|
933
|
+
color = color.replace('#', '0x');
|
934
|
+
|
935
|
+
if (opacity){
|
936
|
+
opacity = parseFloat(opacity);
|
937
|
+
opacity = Math.min(1, Math.max(opacity, 0));
|
938
|
+
if (opacity === 0){
|
939
|
+
return '0x00000000';
|
940
|
+
}
|
941
|
+
opacity = (opacity * 255).toString(16);
|
942
|
+
if (opacity.length === 1){
|
943
|
+
opacity += opacity;
|
944
|
+
}
|
945
|
+
|
946
|
+
color = color.slice(0,8) + opacity;
|
947
|
+
}
|
948
|
+
}
|
949
|
+
return color;
|
950
|
+
}
|
951
|
+
|
952
|
+
if (polyline){
|
953
|
+
data = polyline;
|
954
|
+
polyline = [];
|
955
|
+
|
956
|
+
if (data.strokeWeight){
|
957
|
+
polyline.push('weight:' + parseInt(data.strokeWeight, 10));
|
958
|
+
}
|
959
|
+
|
960
|
+
if (data.strokeColor){
|
961
|
+
var color = parseColor(data.strokeColor, data.strokeOpacity);
|
962
|
+
polyline.push('color:' + color);
|
963
|
+
}
|
964
|
+
|
965
|
+
if (data.fillColor){
|
966
|
+
var fillcolor = parseColor(data.fillColor, data.fillOpacity);
|
967
|
+
polyline.push('fillcolor:' + fillcolor);
|
968
|
+
}
|
969
|
+
|
970
|
+
var path = data.path;
|
971
|
+
if (path.join){
|
972
|
+
for (var j=0, pos; pos=path[j]; j++){
|
973
|
+
polyline.push(pos.join(','));
|
974
|
+
}
|
975
|
+
}
|
976
|
+
else {
|
977
|
+
polyline.push('enc:' + path);
|
978
|
+
}
|
979
|
+
|
980
|
+
polyline = polyline.join('|');
|
981
|
+
parameters.push('path=' + encodeURI(polyline));
|
982
|
+
}
|
983
|
+
|
984
|
+
parameters = parameters.join('&');
|
985
|
+
return static_root + parameters;
|
986
|
+
};
|
987
|
+
|
988
|
+
//==========================
|
989
|
+
// Polygon containsLatLng
|
990
|
+
// https://github.com/tparkin/Google-Maps-Point-in-Polygon
|
991
|
+
// Poygon getBounds extension - google-maps-extensions
|
992
|
+
// http://code.google.com/p/google-maps-extensions/source/browse/google.maps.Polygon.getBounds.js
|
993
|
+
if (!google.maps.Polygon.prototype.getBounds) {
|
994
|
+
google.maps.Polygon.prototype.getBounds = function(latLng) {
|
995
|
+
var bounds = new google.maps.LatLngBounds();
|
996
|
+
var paths = this.getPaths();
|
997
|
+
var path;
|
998
|
+
|
999
|
+
for (var p = 0; p < paths.getLength(); p++) {
|
1000
|
+
path = paths.getAt(p);
|
1001
|
+
for (var i = 0; i < path.getLength(); i++) {
|
1002
|
+
bounds.extend(path.getAt(i));
|
1003
|
+
}
|
1004
|
+
}
|
1005
|
+
|
1006
|
+
return bounds;
|
1007
|
+
};
|
1008
|
+
}
|
1009
|
+
|
1010
|
+
// Polygon containsLatLng - method to determine if a latLng is within a polygon
|
1011
|
+
google.maps.Polygon.prototype.containsLatLng = function(latLng) {
|
1012
|
+
// Exclude points outside of bounds as there is no way they are in the poly
|
1013
|
+
var bounds = this.getBounds();
|
1014
|
+
|
1015
|
+
if (bounds !== null && !bounds.contains(latLng)) {
|
1016
|
+
return false;
|
1017
|
+
}
|
1018
|
+
|
1019
|
+
// Raycast point in polygon method
|
1020
|
+
var inPoly = false;
|
1021
|
+
|
1022
|
+
var numPaths = this.getPaths().getLength();
|
1023
|
+
for (var p = 0; p < numPaths; p++) {
|
1024
|
+
var path = this.getPaths().getAt(p);
|
1025
|
+
var numPoints = path.getLength();
|
1026
|
+
var j = numPoints - 1;
|
1027
|
+
|
1028
|
+
for (var i = 0; i < numPoints; i++) {
|
1029
|
+
var vertex1 = path.getAt(i);
|
1030
|
+
var vertex2 = path.getAt(j);
|
1031
|
+
|
1032
|
+
if (vertex1.lng() < latLng.lng() && vertex2.lng() >= latLng.lng() || vertex2.lng() < latLng.lng() && vertex1.lng() >= latLng.lng()) {
|
1033
|
+
if (vertex1.lat() + (latLng.lng() - vertex1.lng()) / (vertex2.lng() - vertex1.lng()) * (vertex2.lat() - vertex1.lat()) < latLng.lat()) {
|
1034
|
+
inPoly = !inPoly;
|
1035
|
+
}
|
1036
|
+
}
|
1037
|
+
|
1038
|
+
j = i;
|
1039
|
+
}
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
return inPoly;
|
1043
|
+
};
|
1044
|
+
|
1045
|
+
google.maps.LatLngBounds.prototype.containsLatLng = function(latLng) {
|
1046
|
+
return this.contains(latLng);
|
1047
|
+
};
|
1048
|
+
|
1049
|
+
google.maps.Marker.prototype.setFences = function(fences) {
|
1050
|
+
this.fences = fences;
|
1051
|
+
};
|
1052
|
+
|
1053
|
+
google.maps.Marker.prototype.addFence = function(fence) {
|
1054
|
+
this.fences.push(fence);
|
1055
|
+
};
|
1056
|
+
|
1057
|
+
return GMaps;
|
1058
|
+
}(jQuery || $));
|