Simple Map - Version 2.0.0

Version Description

  • Add argument infowindow
  • little fix
Download this release

Release Info

Developer miyauchi
Plugin Icon wp plugin Simple Map
Version 2.0.0
Comparing to
See all releases

Version 2.0.0

Files changed (7) hide show
  1. Gruntfile.js +42 -0
  2. js/gmaps.js +2044 -0
  3. js/simple-map.js +104 -0
  4. js/simple-map.min.js +13 -0
  5. package.json +24 -0
  6. readme.txt +184 -0
  7. simple-map.php +168 -0
Gruntfile.js ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* vim: set ft=javascript expandtab shiftwidth=2 tabstop=2: */
2
+
3
+ module.exports = function( grunt ) {
4
+
5
+ // Project configuration
6
+ grunt.initConfig( {
7
+ pkg: grunt.file.readJSON( 'package.json' ),
8
+ uglify: {
9
+ all: {
10
+ files: {
11
+ 'js/simple-map.min.js': [
12
+ 'node_modules/gmaps/gmaps.js',
13
+ 'js/simple-map.js'
14
+ ]
15
+ },
16
+ options: {
17
+ banner: '/**\n' +
18
+ ' * <%= pkg.title %> - v<%= pkg.version %>\n' +
19
+ ' *\n' +
20
+ ' * <%= pkg.homepage %>\n' +
21
+ ' * <%= pkg.repository.url %>\n' +
22
+ ' *\n' +
23
+ ' * Special thanks!\n' +
24
+ ' * http://hpneo.github.io/gmaps/\n' +
25
+ ' *\n' +
26
+ ' * Copyright <%= grunt.template.today("yyyy") %>, <%= pkg.author.name %> (<%= pkg.author.url %>)\n' +
27
+ ' * Released under the <%= pkg.license %>\n' +
28
+ ' */\n',
29
+ mangle: {
30
+ except: ['jQuery']
31
+ }
32
+ }
33
+ }
34
+ }
35
+ } );
36
+
37
+ // Load other tasks
38
+ grunt.loadNpmTasks('grunt-contrib-uglify');
39
+ grunt.registerTask( 'default', ['uglify'] );
40
+
41
+ grunt.util.linefeed = '\n';
42
+ };
js/gmaps.js ADDED
@@ -0,0 +1,2044 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * GMaps.js v0.4.8
3
+ * http://hpneo.github.com/gmaps/
4
+ *
5
+ * Copyright 2013, Gustavo Leon
6
+ * Released under the MIT License.
7
+ */
8
+
9
+ if (!(typeof window.google === 'object' && window.google.maps)) {
10
+ throw 'Google Maps API is required. Please register the following JavaScript library http://maps.google.com/maps/api/js?sensor=true.'
11
+ }
12
+
13
+ var extend_object = function(obj, new_obj) {
14
+ var name;
15
+
16
+ if (obj === new_obj) {
17
+ return obj;
18
+ }
19
+
20
+ for (name in new_obj) {
21
+ obj[name] = new_obj[name];
22
+ }
23
+
24
+ return obj;
25
+ };
26
+
27
+ var replace_object = function(obj, replace) {
28
+ var name;
29
+
30
+ if (obj === replace) {
31
+ return obj;
32
+ }
33
+
34
+ for (name in replace) {
35
+ if (obj[name] != undefined) {
36
+ obj[name] = replace[name];
37
+ }
38
+ }
39
+
40
+ return obj;
41
+ };
42
+
43
+ var array_map = function(array, callback) {
44
+ var original_callback_params = Array.prototype.slice.call(arguments, 2),
45
+ array_return = [],
46
+ array_length = array.length,
47
+ i;
48
+
49
+ if (Array.prototype.map && array.map === Array.prototype.map) {
50
+ array_return = Array.prototype.map.call(array, function(item) {
51
+ callback_params = original_callback_params;
52
+ callback_params.splice(0, 0, item);
53
+
54
+ return callback.apply(this, callback_params);
55
+ });
56
+ }
57
+ else {
58
+ for (i = 0; i < array_length; i++) {
59
+ callback_params = original_callback_params;
60
+ callback_params.splice(0, 0, array[i]);
61
+ array_return.push(callback.apply(this, callback_params));
62
+ }
63
+ }
64
+
65
+ return array_return;
66
+ };
67
+
68
+ var array_flat = function(array) {
69
+ var new_array = [],
70
+ i;
71
+
72
+ for (i = 0; i < array.length; i++) {
73
+ new_array = new_array.concat(array[i]);
74
+ }
75
+
76
+ return new_array;
77
+ };
78
+
79
+ var coordsToLatLngs = function(coords, useGeoJSON) {
80
+ var first_coord = coords[0],
81
+ second_coord = coords[1];
82
+
83
+ if (useGeoJSON) {
84
+ first_coord = coords[1];
85
+ second_coord = coords[0];
86
+ }
87
+
88
+ return new google.maps.LatLng(first_coord, second_coord);
89
+ };
90
+
91
+ var arrayToLatLng = function(coords, useGeoJSON) {
92
+ var i;
93
+
94
+ for (i = 0; i < coords.length; i++) {
95
+ if (coords[i].length > 0 && typeof(coords[i][0]) == "object") {
96
+ coords[i] = arrayToLatLng(coords[i], useGeoJSON);
97
+ }
98
+ else {
99
+ coords[i] = coordsToLatLngs(coords[i], useGeoJSON);
100
+ }
101
+ }
102
+
103
+ return coords;
104
+ };
105
+
106
+ var getElementById = function(id, context) {
107
+ var element,
108
+ id = id.replace('#', '');
109
+
110
+ if ('jQuery' in this && context) {
111
+ element = $("#" + id, context)[0];
112
+ } else {
113
+ element = document.getElementById(id);
114
+ };
115
+
116
+ return element;
117
+ };
118
+
119
+ var findAbsolutePosition = function(obj) {
120
+ var curleft = 0,
121
+ curtop = 0;
122
+
123
+ if (obj.offsetParent) {
124
+ do {
125
+ curleft += obj.offsetLeft;
126
+ curtop += obj.offsetTop;
127
+ } while (obj = obj.offsetParent);
128
+ }
129
+
130
+ return [curleft, curtop];
131
+ };
132
+
133
+ var GMaps = (function(global) {
134
+ "use strict";
135
+
136
+ var doc = document;
137
+
138
+ var GMaps = function(options) {
139
+ if (!this) return new GMaps(options);
140
+
141
+ options.zoom = options.zoom || 15;
142
+ options.mapType = options.mapType || 'roadmap';
143
+
144
+ var self = this,
145
+ i,
146
+ events_that_hide_context_menu = ['bounds_changed', 'center_changed', 'click', 'dblclick', 'drag', 'dragend', 'dragstart', 'idle', 'maptypeid_changed', 'projection_changed', 'resize', 'tilesloaded', 'zoom_changed'],
147
+ events_that_doesnt_hide_context_menu = ['mousemove', 'mouseout', 'mouseover'],
148
+ options_to_be_deleted = ['el', 'lat', 'lng', 'mapType', 'width', 'height', 'markerClusterer', 'enableNewStyle'],
149
+ container_id = options.el || options.div,
150
+ markerClustererFunction = options.markerClusterer,
151
+ mapType = google.maps.MapTypeId[options.mapType.toUpperCase()],
152
+ map_center = new google.maps.LatLng(options.lat, options.lng),
153
+ zoomControl = options.zoomControl || true,
154
+ zoomControlOpt = options.zoomControlOpt || {
155
+ style: 'DEFAULT',
156
+ position: 'TOP_LEFT'
157
+ },
158
+ zoomControlStyle = zoomControlOpt.style || 'DEFAULT',
159
+ zoomControlPosition = zoomControlOpt.position || 'TOP_LEFT',
160
+ panControl = options.panControl || true,
161
+ mapTypeControl = options.mapTypeControl || true,
162
+ scaleControl = options.scaleControl || true,
163
+ streetViewControl = options.streetViewControl || true,
164
+ overviewMapControl = overviewMapControl || true,
165
+ map_options = {},
166
+ map_base_options = {
167
+ zoom: this.zoom,
168
+ center: map_center,
169
+ mapTypeId: mapType
170
+ },
171
+ map_controls_options = {
172
+ panControl: panControl,
173
+ zoomControl: zoomControl,
174
+ zoomControlOptions: {
175
+ style: google.maps.ZoomControlStyle[zoomControlStyle],
176
+ position: google.maps.ControlPosition[zoomControlPosition]
177
+ },
178
+ mapTypeControl: mapTypeControl,
179
+ scaleControl: scaleControl,
180
+ streetViewControl: streetViewControl,
181
+ overviewMapControl: overviewMapControl
182
+ };
183
+
184
+ if (typeof(options.el) === 'string' || typeof(options.div) === 'string') {
185
+ this.el = getElementById(container_id, options.context);
186
+ } else {
187
+ this.el = container_id;
188
+ }
189
+
190
+ if (typeof(this.el) === 'undefined' || this.el === null) {
191
+ throw 'No element defined.';
192
+ }
193
+
194
+ window.context_menu = window.context_menu || {};
195
+ window.context_menu[self.el.id] = {};
196
+
197
+ this.controls = [];
198
+ this.overlays = [];
199
+ this.layers = []; // array with kml/georss and fusiontables layers, can be as many
200
+ this.singleLayers = {}; // object with the other layers, only one per layer
201
+ this.markers = [];
202
+ this.polylines = [];
203
+ this.routes = [];
204
+ this.polygons = [];
205
+ this.infoWindow = null;
206
+ this.overlay_el = null;
207
+ this.zoom = options.zoom;
208
+ this.registered_events = {};
209
+
210
+ this.el.style.width = options.width || this.el.scrollWidth || this.el.offsetWidth;
211
+ this.el.style.height = options.height || this.el.scrollHeight || this.el.offsetHeight;
212
+
213
+ google.maps.visualRefresh = options.enableNewStyle;
214
+
215
+ for (i = 0; i < options_to_be_deleted.length; i++) {
216
+ delete options[options_to_be_deleted[i]];
217
+ }
218
+
219
+ if(options.disableDefaultUI != true) {
220
+ map_base_options = extend_object(map_base_options, map_controls_options);
221
+ }
222
+
223
+ map_options = extend_object(map_base_options, options);
224
+
225
+ for (i = 0; i < events_that_hide_context_menu.length; i++) {
226
+ delete map_options[events_that_hide_context_menu[i]];
227
+ }
228
+
229
+ for (i = 0; i < events_that_doesnt_hide_context_menu.length; i++) {
230
+ delete map_options[events_that_doesnt_hide_context_menu[i]];
231
+ }
232
+
233
+ this.map = new google.maps.Map(this.el, map_options);
234
+
235
+ if (markerClustererFunction) {
236
+ this.markerClusterer = markerClustererFunction.apply(this, [this.map]);
237
+ }
238
+
239
+ var buildContextMenuHTML = function(control, e) {
240
+ var html = '',
241
+ options = window.context_menu[self.el.id][control];
242
+
243
+ for (var i in options){
244
+ if (options.hasOwnProperty(i)) {
245
+ var option = options[i];
246
+
247
+ html += '<li><a id="' + control + '_' + i + '" href="#">' + option.title + '</a></li>';
248
+ }
249
+ }
250
+
251
+ if (!getElementById('gmaps_context_menu')) return;
252
+
253
+ var context_menu_element = getElementById('gmaps_context_menu');
254
+
255
+ context_menu_element.innerHTML = html;
256
+
257
+ var context_menu_items = context_menu_element.getElementsByTagName('a'),
258
+ context_menu_items_count = context_menu_items.length
259
+ i;
260
+
261
+ for (i = 0; i < context_menu_items_count; i++) {
262
+ var context_menu_item = context_menu_items[i];
263
+
264
+ var assign_menu_item_action = function(ev){
265
+ ev.preventDefault();
266
+
267
+ options[this.id.replace(control + '_', '')].action.apply(self, [e]);
268
+ self.hideContextMenu();
269
+ };
270
+
271
+ google.maps.event.clearListeners(context_menu_item, 'click');
272
+ google.maps.event.addDomListenerOnce(context_menu_item, 'click', assign_menu_item_action, false);
273
+ }
274
+
275
+ var position = findAbsolutePosition.apply(this, [self.el]),
276
+ left = position[0] + e.pixel.x - 15,
277
+ top = position[1] + e.pixel.y- 15;
278
+
279
+ context_menu_element.style.left = left + "px";
280
+ context_menu_element.style.top = top + "px";
281
+
282
+ context_menu_element.style.display = 'block';
283
+ };
284
+
285
+ this.buildContextMenu = function(control, e) {
286
+ if (control === 'marker') {
287
+ e.pixel = {};
288
+
289
+ var overlay = new google.maps.OverlayView();
290
+ overlay.setMap(self.map);
291
+
292
+ overlay.draw = function() {
293
+ var projection = overlay.getProjection(),
294
+ position = e.marker.getPosition();
295
+
296
+ e.pixel = projection.fromLatLngToContainerPixel(position);
297
+
298
+ buildContextMenuHTML(control, e);
299
+ };
300
+ }
301
+ else {
302
+ buildContextMenuHTML(control, e);
303
+ }
304
+ };
305
+
306
+ this.setContextMenu = function(options) {
307
+ window.context_menu[self.el.id][options.control] = {};
308
+
309
+ var i,
310
+ ul = doc.createElement('ul');
311
+
312
+ for (i in options.options) {
313
+ if (options.options.hasOwnProperty(i)) {
314
+ var option = options.options[i];
315
+
316
+ window.context_menu[self.el.id][options.control][option.name] = {
317
+ title: option.title,
318
+ action: option.action
319
+ };
320
+ }
321
+ }
322
+
323
+ ul.id = 'gmaps_context_menu';
324
+ ul.style.display = 'none';
325
+ ul.style.position = 'absolute';
326
+ ul.style.minWidth = '100px';
327
+ ul.style.background = 'white';
328
+ ul.style.listStyle = 'none';
329
+ ul.style.padding = '8px';
330
+ ul.style.boxShadow = '2px 2px 6px #ccc';
331
+
332
+ doc.body.appendChild(ul);
333
+
334
+ var context_menu_element = getElementById('gmaps_context_menu')
335
+
336
+ google.maps.event.addDomListener(context_menu_element, 'mouseout', function(ev) {
337
+ if (!ev.relatedTarget || !this.contains(ev.relatedTarget)) {
338
+ window.setTimeout(function(){
339
+ context_menu_element.style.display = 'none';
340
+ }, 400);
341
+ }
342
+ }, false);
343
+ };
344
+
345
+ this.hideContextMenu = function() {
346
+ var context_menu_element = getElementById('gmaps_context_menu');
347
+
348
+ if (context_menu_element) {
349
+ context_menu_element.style.display = 'none';
350
+ }
351
+ };
352
+
353
+ var setupListener = function(object, name) {
354
+ google.maps.event.addListener(object, name, function(e){
355
+ if (e == undefined) {
356
+ e = this;
357
+ }
358
+
359
+ options[name].apply(this, [e]);
360
+
361
+ self.hideContextMenu();
362
+ });
363
+ };
364
+
365
+ for (var ev = 0; ev < events_that_hide_context_menu.length; ev++) {
366
+ var name = events_that_hide_context_menu[ev];
367
+
368
+ if (name in options) {
369
+ setupListener(this.map, name);
370
+ }
371
+ }
372
+
373
+ for (var ev = 0; ev < events_that_doesnt_hide_context_menu.length; ev++) {
374
+ var name = events_that_doesnt_hide_context_menu[ev];
375
+
376
+ if (name in options) {
377
+ setupListener(this.map, name);
378
+ }
379
+ }
380
+
381
+ google.maps.event.addListener(this.map, 'rightclick', function(e) {
382
+ if (options.rightclick) {
383
+ options.rightclick.apply(this, [e]);
384
+ }
385
+
386
+ if(window.context_menu[self.el.id]['map'] != undefined) {
387
+ self.buildContextMenu('map', e);
388
+ }
389
+ });
390
+
391
+ this.refresh = function() {
392
+ google.maps.event.trigger(this.map, 'resize');
393
+ };
394
+
395
+ this.fitZoom = function() {
396
+ var latLngs = [],
397
+ markers_length = this.markers.length,
398
+ i;
399
+
400
+ for (i = 0; i < markers_length; i++) {
401
+ latLngs.push(this.markers[i].getPosition());
402
+ }
403
+
404
+ this.fitLatLngBounds(latLngs);
405
+ };
406
+
407
+ this.fitLatLngBounds = function(latLngs) {
408
+ var total = latLngs.length;
409
+ var bounds = new google.maps.LatLngBounds();
410
+
411
+ for(var i=0; i < total; i++) {
412
+ bounds.extend(latLngs[i]);
413
+ }
414
+
415
+ this.map.fitBounds(bounds);
416
+ };
417
+
418
+ this.setCenter = function(lat, lng, callback) {
419
+ this.map.panTo(new google.maps.LatLng(lat, lng));
420
+
421
+ if (callback) {
422
+ callback();
423
+ }
424
+ };
425
+
426
+ this.getElement = function() {
427
+ return this.el;
428
+ };
429
+
430
+ this.zoomIn = function(value) {
431
+ value = value || 1;
432
+
433
+ this.zoom = this.map.getZoom() + value;
434
+ this.map.setZoom(this.zoom);
435
+ };
436
+
437
+ this.zoomOut = function(value) {
438
+ value = value || 1;
439
+
440
+ this.zoom = this.map.getZoom() - value;
441
+ this.map.setZoom(this.zoom);
442
+ };
443
+
444
+ var native_methods = [],
445
+ method;
446
+
447
+ for (method in this.map) {
448
+ if (typeof(this.map[method]) == 'function' && !this[method]) {
449
+ native_methods.push(method);
450
+ }
451
+ }
452
+
453
+ for (i=0; i < native_methods.length; i++) {
454
+ (function(gmaps, scope, method_name) {
455
+ gmaps[method_name] = function(){
456
+ return scope[method_name].apply(scope, arguments);
457
+ };
458
+ })(this, this.map, native_methods[i]);
459
+ }
460
+ };
461
+
462
+ return GMaps;
463
+ })(this);
464
+
465
+ GMaps.prototype.createControl = function(options) {
466
+ var control = document.createElement('div');
467
+
468
+ control.style.cursor = 'pointer';
469
+ control.style.fontFamily = 'Arial, sans-serif';
470
+ control.style.fontSize = '13px';
471
+ control.style.boxShadow = 'rgba(0, 0, 0, 0.398438) 0px 2px 4px';
472
+
473
+ for (var option in options.style) {
474
+ control.style[option] = options.style[option];
475
+ }
476
+
477
+ if (options.id) {
478
+ control.id = options.id;
479
+ }
480
+
481
+ if (options.classes) {
482
+ control.className = options.classes;
483
+ }
484
+
485
+ if (options.content) {
486
+ control.innerHTML = options.content;
487
+ }
488
+
489
+ for (var ev in options.events) {
490
+ (function(object, name) {
491
+ google.maps.event.addDomListener(object, name, function(){
492
+ options.events[name].apply(this, [this]);
493
+ });
494
+ })(control, ev);
495
+ }
496
+
497
+ control.index = 1;
498
+
499
+ return control;
500
+ };
501
+
502
+ GMaps.prototype.addControl = function(options) {
503
+ var position = google.maps.ControlPosition[options.position.toUpperCase()];
504
+
505
+ delete options.position;
506
+
507
+ var control = this.createControl(options);
508
+ this.controls.push(control);
509
+
510
+ this.map.controls[position].push(control);
511
+
512
+ return control;
513
+ };
514
+
515
+ GMaps.prototype.createMarker = function(options) {
516
+ if (options.lat == undefined && options.lng == undefined && options.position == undefined) {
517
+ throw 'No latitude or longitude defined.';
518
+ }
519
+
520
+ var self = this,
521
+ details = options.details,
522
+ fences = options.fences,
523
+ outside = options.outside,
524
+ base_options = {
525
+ position: new google.maps.LatLng(options.lat, options.lng),
526
+ map: null
527
+ };
528
+
529
+ delete options.lat;
530
+ delete options.lng;
531
+ delete options.fences;
532
+ delete options.outside;
533
+
534
+ var marker_options = extend_object(base_options, options),
535
+ marker = new google.maps.Marker(marker_options);
536
+
537
+ marker.fences = fences;
538
+
539
+ if (options.infoWindow) {
540
+ marker.infoWindow = new google.maps.InfoWindow(options.infoWindow);
541
+
542
+ var info_window_events = ['closeclick', 'content_changed', 'domready', 'position_changed', 'zindex_changed'];
543
+
544
+ for (var ev = 0; ev < info_window_events.length; ev++) {
545
+ (function(object, name) {
546
+ if (options.infoWindow[name]) {
547
+ google.maps.event.addListener(object, name, function(e){
548
+ options.infoWindow[name].apply(this, [e]);
549
+ });
550
+ }
551
+ })(marker.infoWindow, info_window_events[ev]);
552
+ }
553
+ }
554
+
555
+ var marker_events = ['animation_changed', 'clickable_changed', 'cursor_changed', 'draggable_changed', 'flat_changed', 'icon_changed', 'position_changed', 'shadow_changed', 'shape_changed', 'title_changed', 'visible_changed', 'zindex_changed'];
556
+
557
+ var marker_events_with_mouse = ['dblclick', 'drag', 'dragend', 'dragstart', 'mousedown', 'mouseout', 'mouseover', 'mouseup'];
558
+
559
+ for (var ev = 0; ev < marker_events.length; ev++) {
560
+ (function(object, name) {
561
+ if (options[name]) {
562
+ google.maps.event.addListener(object, name, function(){
563
+ options[name].apply(this, [this]);
564
+ });
565
+ }
566
+ })(marker, marker_events[ev]);
567
+ }
568
+
569
+ for (var ev = 0; ev < marker_events_with_mouse.length; ev++) {
570
+ (function(map, object, name) {
571
+ if (options[name]) {
572
+ google.maps.event.addListener(object, name, function(me){
573
+ if(!me.pixel){
574
+ me.pixel = map.getProjection().fromLatLngToPoint(me.latLng)
575
+ }
576
+
577
+ options[name].apply(this, [me]);
578
+ });
579
+ }
580
+ })(this.map, marker, marker_events_with_mouse[ev]);
581
+ }
582
+
583
+ google.maps.event.addListener(marker, 'click', function() {
584
+ this.details = details;
585
+
586
+ if (options.click) {
587
+ options.click.apply(this, [this]);
588
+ }
589
+
590
+ if (marker.infoWindow) {
591
+ self.hideInfoWindows();
592
+ marker.infoWindow.open(self.map, marker);
593
+ }
594
+ });
595
+
596
+ google.maps.event.addListener(marker, 'rightclick', function(e) {
597
+ e.marker = this;
598
+
599
+ if (options.rightclick) {
600
+ options.rightclick.apply(this, [e]);
601
+ }
602
+
603
+ if (window.context_menu[self.el.id]['marker'] != undefined) {
604
+ self.buildContextMenu('marker', e);
605
+ }
606
+ });
607
+
608
+ if (marker.fences) {
609
+ google.maps.event.addListener(marker, 'dragend', function() {
610
+ self.checkMarkerGeofence(marker, function(m, f) {
611
+ outside(m, f);
612
+ });
613
+ });
614
+ }
615
+
616
+ return marker;
617
+ };
618
+
619
+ GMaps.prototype.addMarker = function(options) {
620
+ var marker;
621
+ if(options.hasOwnProperty('gm_accessors_')) {
622
+ // Native google.maps.Marker object
623
+ marker = options;
624
+ }
625
+ else {
626
+ if ((options.hasOwnProperty('lat') && options.hasOwnProperty('lng')) || options.position) {
627
+ marker = this.createMarker(options);
628
+ }
629
+ else {
630
+ throw 'No latitude or longitude defined.';
631
+ }
632
+ }
633
+
634
+ marker.setMap(this.map);
635
+
636
+ if(this.markerClusterer) {
637
+ this.markerClusterer.addMarker(marker);
638
+ }
639
+
640
+ this.markers.push(marker);
641
+
642
+ GMaps.fire('marker_added', marker, this);
643
+
644
+ return marker;
645
+ };
646
+
647
+ GMaps.prototype.addMarkers = function(array) {
648
+ for (var i = 0, marker; marker=array[i]; i++) {
649
+ this.addMarker(marker);
650
+ }
651
+
652
+ return this.markers;
653
+ };
654
+
655
+ GMaps.prototype.hideInfoWindows = function() {
656
+ for (var i = 0, marker; marker = this.markers[i]; i++){
657
+ if (marker.infoWindow){
658
+ marker.infoWindow.close();
659
+ }
660
+ }
661
+ };
662
+
663
+ GMaps.prototype.removeMarker = function(marker) {
664
+ for (var i = 0; i < this.markers.length; i++) {
665
+ if (this.markers[i] === marker) {
666
+ this.markers[i].setMap(null);
667
+ this.markers.splice(i, 1);
668
+
669
+ if(this.markerClusterer) {
670
+ this.markerClusterer.removeMarker(marker);
671
+ }
672
+
673
+ GMaps.fire('marker_removed', marker, this);
674
+
675
+ break;
676
+ }
677
+ }
678
+
679
+ return marker;
680
+ };
681
+
682
+ GMaps.prototype.removeMarkers = function(collection) {
683
+ var collection = (collection || this.markers);
684
+
685
+ for (var i = 0;i < this.markers.length; i++) {
686
+ if(this.markers[i] === collection[i]) {
687
+ this.markers[i].setMap(null);
688
+ }
689
+ }
690
+
691
+ var new_markers = [];
692
+
693
+ for (var i = 0;i < this.markers.length; i++) {
694
+ if(this.markers[i].getMap() != null) {
695
+ new_markers.push(this.markers[i]);
696
+ }
697
+ }
698
+
699
+ this.markers = new_markers;
700
+ };
701
+
702
+ GMaps.prototype.drawOverlay = function(options) {
703
+ var overlay = new google.maps.OverlayView(),
704
+ auto_show = true;
705
+
706
+ overlay.setMap(this.map);
707
+
708
+ if (options.auto_show != null) {
709
+ auto_show = options.auto_show;
710
+ }
711
+
712
+ overlay.onAdd = function() {
713
+ var el = document.createElement('div');
714
+
715
+ el.style.borderStyle = "none";
716
+ el.style.borderWidth = "0px";
717
+ el.style.position = "absolute";
718
+ el.style.zIndex = 100;
719
+ el.innerHTML = options.content;
720
+
721
+ overlay.el = el;
722
+
723
+ if (!options.layer) {
724
+ options.layer = 'overlayLayer';
725
+ }
726
+
727
+ var panes = this.getPanes(),
728
+ overlayLayer = panes[options.layer],
729
+ stop_overlay_events = ['contextmenu', 'DOMMouseScroll', 'dblclick', 'mousedown'];
730
+
731
+ overlayLayer.appendChild(el);
732
+
733
+ for (var ev = 0; ev < stop_overlay_events.length; ev++) {
734
+ (function(object, name) {
735
+ google.maps.event.addDomListener(object, name, function(e){
736
+ if (navigator.userAgent.toLowerCase().indexOf('msie') != -1 && document.all) {
737
+ e.cancelBubble = true;
738
+ e.returnValue = false;
739
+ }
740
+ else {
741
+ e.stopPropagation();
742
+ }
743
+ });
744
+ })(el, stop_overlay_events[ev]);
745
+ }
746
+
747
+ google.maps.event.trigger(this, 'ready');
748
+ };
749
+
750
+ overlay.draw = function() {
751
+ var projection = this.getProjection(),
752
+ pixel = projection.fromLatLngToDivPixel(new google.maps.LatLng(options.lat, options.lng));
753
+
754
+ options.horizontalOffset = options.horizontalOffset || 0;
755
+ options.verticalOffset = options.verticalOffset || 0;
756
+
757
+ var el = overlay.el,
758
+ content = el.children[0],
759
+ content_height = content.clientHeight,
760
+ content_width = content.clientWidth;
761
+
762
+ switch (options.verticalAlign) {
763
+ case 'top':
764
+ el.style.top = (pixel.y - content_height + options.verticalOffset) + 'px';
765
+ break;
766
+ default:
767
+ case 'middle':
768
+ el.style.top = (pixel.y - (content_height / 2) + options.verticalOffset) + 'px';
769
+ break;
770
+ case 'bottom':
771
+ el.style.top = (pixel.y + options.verticalOffset) + 'px';
772
+ break;
773
+ }
774
+
775
+ switch (options.horizontalAlign) {
776
+ case 'left':
777
+ el.style.left = (pixel.x - content_width + options.horizontalOffset) + 'px';
778
+ break;
779
+ default:
780
+ case 'center':
781
+ el.style.left = (pixel.x - (content_width / 2) + options.horizontalOffset) + 'px';
782
+ break;
783
+ case 'right':
784
+ el.style.left = (pixel.x + options.horizontalOffset) + 'px';
785
+ break;
786
+ }
787
+
788
+ el.style.display = auto_show ? 'block' : 'none';
789
+
790
+ if (!auto_show) {
791
+ options.show.apply(this, [el]);
792
+ }
793
+ };
794
+
795
+ overlay.onRemove = function() {
796
+ var el = overlay.el;
797
+
798
+ if (options.remove) {
799
+ options.remove.apply(this, [el]);
800
+ }
801
+ else {
802
+ overlay.el.parentNode.removeChild(overlay.el);
803
+ overlay.el = null;
804
+ }
805
+ };
806
+
807
+ this.overlays.push(overlay);
808
+ return overlay;
809
+ };
810
+
811
+ GMaps.prototype.removeOverlay = function(overlay) {
812
+ for (var i = 0; i < this.overlays.length; i++) {
813
+ if (this.overlays[i] === overlay) {
814
+ this.overlays[i].setMap(null);
815
+ this.overlays.splice(i, 1);
816
+
817
+ break;
818
+ }
819
+ }
820
+ };
821
+
822
+ GMaps.prototype.removeOverlays = function() {
823
+ for (var i = 0, item; item = this.overlays[i]; i++) {
824
+ item.setMap(null);
825
+ }
826
+
827
+ this.overlays = [];
828
+ };
829
+
830
+ GMaps.prototype.drawPolyline = function(options) {
831
+ var path = [],
832
+ points = options.path;
833
+
834
+ if (points.length) {
835
+ if (points[0][0] === undefined) {
836
+ path = points;
837
+ }
838
+ else {
839
+ for (var i=0, latlng; latlng=points[i]; i++) {
840
+ path.push(new google.maps.LatLng(latlng[0], latlng[1]));
841
+ }
842
+ }
843
+ }
844
+
845
+ var polyline_options = {
846
+ map: this.map,
847
+ path: path,
848
+ strokeColor: options.strokeColor,
849
+ strokeOpacity: options.strokeOpacity,
850
+ strokeWeight: options.strokeWeight,
851
+ geodesic: options.geodesic,
852
+ clickable: true,
853
+ editable: false,
854
+ visible: true
855
+ };
856
+
857
+ if (options.hasOwnProperty("clickable")) {
858
+ polyline_options.clickable = options.clickable;
859
+ }
860
+
861
+ if (options.hasOwnProperty("editable")) {
862
+ polyline_options.editable = options.editable;
863
+ }
864
+
865
+ if (options.hasOwnProperty("icons")) {
866
+ polyline_options.icons = options.icons;
867
+ }
868
+
869
+ if (options.hasOwnProperty("zIndex")) {
870
+ polyline_options.zIndex = options.zIndex;
871
+ }
872
+
873
+ var polyline = new google.maps.Polyline(polyline_options);
874
+
875
+ var polyline_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
876
+
877
+ for (var ev = 0; ev < polyline_events.length; ev++) {
878
+ (function(object, name) {
879
+ if (options[name]) {
880
+ google.maps.event.addListener(object, name, function(e){
881
+ options[name].apply(this, [e]);
882
+ });
883
+ }
884
+ })(polyline, polyline_events[ev]);
885
+ }
886
+
887
+ this.polylines.push(polyline);
888
+
889
+ GMaps.fire('polyline_added', polyline, this);
890
+
891
+ return polyline;
892
+ };
893
+
894
+ GMaps.prototype.removePolyline = function(polyline) {
895
+ for (var i = 0; i < this.polylines.length; i++) {
896
+ if (this.polylines[i] === polyline) {
897
+ this.polylines[i].setMap(null);
898
+ this.polylines.splice(i, 1);
899
+
900
+ GMaps.fire('polyline_removed', polyline, this);
901
+
902
+ break;
903
+ }
904
+ }
905
+ };
906
+
907
+ GMaps.prototype.removePolylines = function() {
908
+ for (var i = 0, item; item = this.polylines[i]; i++) {
909
+ item.setMap(null);
910
+ }
911
+
912
+ this.polylines = [];
913
+ };
914
+
915
+ GMaps.prototype.drawCircle = function(options) {
916
+ options = extend_object({
917
+ map: this.map,
918
+ center: new google.maps.LatLng(options.lat, options.lng)
919
+ }, options);
920
+
921
+ delete options.lat;
922
+ delete options.lng;
923
+
924
+ var polygon = new google.maps.Circle(options),
925
+ polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
926
+
927
+ for (var ev = 0; ev < polygon_events.length; ev++) {
928
+ (function(object, name) {
929
+ if (options[name]) {
930
+ google.maps.event.addListener(object, name, function(e){
931
+ options[name].apply(this, [e]);
932
+ });
933
+ }
934
+ })(polygon, polygon_events[ev]);
935
+ }
936
+
937
+ this.polygons.push(polygon);
938
+
939
+ return polygon;
940
+ };
941
+
942
+ GMaps.prototype.drawRectangle = function(options) {
943
+ options = extend_object({
944
+ map: this.map
945
+ }, options);
946
+
947
+ var latLngBounds = new google.maps.LatLngBounds(
948
+ new google.maps.LatLng(options.bounds[0][0], options.bounds[0][1]),
949
+ new google.maps.LatLng(options.bounds[1][0], options.bounds[1][1])
950
+ );
951
+
952
+ options.bounds = latLngBounds;
953
+
954
+ var polygon = new google.maps.Rectangle(options),
955
+ polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
956
+
957
+ for (var ev = 0; ev < polygon_events.length; ev++) {
958
+ (function(object, name) {
959
+ if (options[name]) {
960
+ google.maps.event.addListener(object, name, function(e){
961
+ options[name].apply(this, [e]);
962
+ });
963
+ }
964
+ })(polygon, polygon_events[ev]);
965
+ }
966
+
967
+ this.polygons.push(polygon);
968
+
969
+ return polygon;
970
+ };
971
+
972
+ GMaps.prototype.drawPolygon = function(options) {
973
+ var useGeoJSON = false;
974
+
975
+ if(options.hasOwnProperty("useGeoJSON")) {
976
+ useGeoJSON = options.useGeoJSON;
977
+ }
978
+
979
+ delete options.useGeoJSON;
980
+
981
+ options = extend_object({
982
+ map: this.map
983
+ }, options);
984
+
985
+ if (useGeoJSON == false) {
986
+ options.paths = [options.paths.slice(0)];
987
+ }
988
+
989
+ if (options.paths.length > 0) {
990
+ if (options.paths[0].length > 0) {
991
+ options.paths = array_flat(array_map(options.paths, arrayToLatLng, useGeoJSON));
992
+ }
993
+ }
994
+
995
+ var polygon = new google.maps.Polygon(options),
996
+ polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
997
+
998
+ for (var ev = 0; ev < polygon_events.length; ev++) {
999
+ (function(object, name) {
1000
+ if (options[name]) {
1001
+ google.maps.event.addListener(object, name, function(e){
1002
+ options[name].apply(this, [e]);
1003
+ });
1004
+ }
1005
+ })(polygon, polygon_events[ev]);
1006
+ }
1007
+
1008
+ this.polygons.push(polygon);
1009
+
1010
+ GMaps.fire('polygon_added', polygon, this);
1011
+
1012
+ return polygon;
1013
+ };
1014
+
1015
+ GMaps.prototype.removePolygon = function(polygon) {
1016
+ for (var i = 0; i < this.polygons.length; i++) {
1017
+ if (this.polygons[i] === polygon) {
1018
+ this.polygons[i].setMap(null);
1019
+ this.polygons.splice(i, 1);
1020
+
1021
+ GMaps.fire('polygon_removed', polygon, this);
1022
+
1023
+ break;
1024
+ }
1025
+ }
1026
+ };
1027
+
1028
+ GMaps.prototype.removePolygons = function() {
1029
+ for (var i = 0, item; item = this.polygons[i]; i++) {
1030
+ item.setMap(null);
1031
+ }
1032
+
1033
+ this.polygons = [];
1034
+ };
1035
+
1036
+ GMaps.prototype.getFromFusionTables = function(options) {
1037
+ var events = options.events;
1038
+
1039
+ delete options.events;
1040
+
1041
+ var fusion_tables_options = options,
1042
+ layer = new google.maps.FusionTablesLayer(fusion_tables_options);
1043
+
1044
+ for (var ev in events) {
1045
+ (function(object, name) {
1046
+ google.maps.event.addListener(object, name, function(e) {
1047
+ events[name].apply(this, [e]);
1048
+ });
1049
+ })(layer, ev);
1050
+ }
1051
+
1052
+ this.layers.push(layer);
1053
+
1054
+ return layer;
1055
+ };
1056
+
1057
+ GMaps.prototype.loadFromFusionTables = function(options) {
1058
+ var layer = this.getFromFusionTables(options);
1059
+ layer.setMap(this.map);
1060
+
1061
+ return layer;
1062
+ };
1063
+
1064
+ GMaps.prototype.getFromKML = function(options) {
1065
+ var url = options.url,
1066
+ events = options.events;
1067
+
1068
+ delete options.url;
1069
+ delete options.events;
1070
+
1071
+ var kml_options = options,
1072
+ layer = new google.maps.KmlLayer(url, kml_options);
1073
+
1074
+ for (var ev in events) {
1075
+ (function(object, name) {
1076
+ google.maps.event.addListener(object, name, function(e) {
1077
+ events[name].apply(this, [e]);
1078
+ });
1079
+ })(layer, ev);
1080
+ }
1081
+
1082
+ this.layers.push(layer);
1083
+
1084
+ return layer;
1085
+ };
1086
+
1087
+ GMaps.prototype.loadFromKML = function(options) {
1088
+ var layer = this.getFromKML(options);
1089
+ layer.setMap(this.map);
1090
+
1091
+ return layer;
1092
+ };
1093
+
1094
+ GMaps.prototype.addLayer = function(layerName, options) {
1095
+ //var default_layers = ['weather', 'clouds', 'traffic', 'transit', 'bicycling', 'panoramio', 'places'];
1096
+ options = options || {};
1097
+ var layer;
1098
+
1099
+ switch(layerName) {
1100
+ case 'weather': this.singleLayers.weather = layer = new google.maps.weather.WeatherLayer();
1101
+ break;
1102
+ case 'clouds': this.singleLayers.clouds = layer = new google.maps.weather.CloudLayer();
1103
+ break;
1104
+ case 'traffic': this.singleLayers.traffic = layer = new google.maps.TrafficLayer();
1105
+ break;
1106
+ case 'transit': this.singleLayers.transit = layer = new google.maps.TransitLayer();
1107
+ break;
1108
+ case 'bicycling': this.singleLayers.bicycling = layer = new google.maps.BicyclingLayer();
1109
+ break;
1110
+ case 'panoramio':
1111
+ this.singleLayers.panoramio = layer = new google.maps.panoramio.PanoramioLayer();
1112
+ layer.setTag(options.filter);
1113
+ delete options.filter;
1114
+
1115
+ //click event
1116
+ if (options.click) {
1117
+ google.maps.event.addListener(layer, 'click', function(event) {
1118
+ options.click(event);
1119
+ delete options.click;
1120
+ });
1121
+ }
1122
+ break;
1123
+ case 'places':
1124
+ this.singleLayers.places = layer = new google.maps.places.PlacesService(this.map);
1125
+
1126
+ //search and nearbySearch callback, Both are the same
1127
+ if (options.search || options.nearbySearch) {
1128
+ var placeSearchRequest = {
1129
+ bounds : options.bounds || null,
1130
+ keyword : options.keyword || null,
1131
+ location : options.location || null,
1132
+ name : options.name || null,
1133
+ radius : options.radius || null,
1134
+ rankBy : options.rankBy || null,
1135
+ types : options.types || null
1136
+ };
1137
+
1138
+ if (options.search) {
1139
+ layer.search(placeSearchRequest, options.search);
1140
+ }
1141
+
1142
+ if (options.nearbySearch) {
1143
+ layer.nearbySearch(placeSearchRequest, options.nearbySearch);
1144
+ }
1145
+ }
1146
+
1147
+ //textSearch callback
1148
+ if (options.textSearch) {
1149
+ var textSearchRequest = {
1150
+ bounds : options.bounds || null,
1151
+ location : options.location || null,
1152
+ query : options.query || null,
1153
+ radius : options.radius || null
1154
+ };
1155
+
1156
+ layer.textSearch(textSearchRequest, options.textSearch);
1157
+ }
1158
+ break;
1159
+ }
1160
+
1161
+ if (layer !== undefined) {
1162
+ if (typeof layer.setOptions == 'function') {
1163
+ layer.setOptions(options);
1164
+ }
1165
+ if (typeof layer.setMap == 'function') {
1166
+ layer.setMap(this.map);
1167
+ }
1168
+
1169
+ return layer;
1170
+ }
1171
+ };
1172
+
1173
+ GMaps.prototype.removeLayer = function(layer) {
1174
+ if (typeof(layer) == "string" && this.singleLayers[layer] !== undefined) {
1175
+ this.singleLayers[layer].setMap(null);
1176
+
1177
+ delete this.singleLayers[layer];
1178
+ }
1179
+ else {
1180
+ for (var i = 0; i < this.layers.length; i++) {
1181
+ if (this.layers[i] === layer) {
1182
+ this.layers[i].setMap(null);
1183
+ this.layers.splice(i, 1);
1184
+
1185
+ break;
1186
+ }
1187
+ }
1188
+ }
1189
+ };
1190
+
1191
+ var travelMode, unitSystem;
1192
+
1193
+ GMaps.prototype.getRoutes = function(options) {
1194
+ switch (options.travelMode) {
1195
+ case 'bicycling':
1196
+ travelMode = google.maps.TravelMode.BICYCLING;
1197
+ break;
1198
+ case 'transit':
1199
+ travelMode = google.maps.TravelMode.TRANSIT;
1200
+ break;
1201
+ case 'driving':
1202
+ travelMode = google.maps.TravelMode.DRIVING;
1203
+ break;
1204
+ default:
1205
+ travelMode = google.maps.TravelMode.WALKING;
1206
+ break;
1207
+ }
1208
+
1209
+ if (options.unitSystem === 'imperial') {
1210
+ unitSystem = google.maps.UnitSystem.IMPERIAL;
1211
+ }
1212
+ else {
1213
+ unitSystem = google.maps.UnitSystem.METRIC;
1214
+ }
1215
+
1216
+ var base_options = {
1217
+ avoidHighways: false,
1218
+ avoidTolls: false,
1219
+ optimizeWaypoints: false,
1220
+ waypoints: []
1221
+ },
1222
+ request_options = extend_object(base_options, options);
1223
+
1224
+ request_options.origin = /string/.test(typeof options.origin) ? options.origin : new google.maps.LatLng(options.origin[0], options.origin[1]);
1225
+ request_options.destination = /string/.test(typeof options.destination) ? options.destination : new google.maps.LatLng(options.destination[0], options.destination[1]);
1226
+ request_options.travelMode = travelMode;
1227
+ request_options.unitSystem = unitSystem;
1228
+
1229
+ delete request_options.callback;
1230
+ delete request_options.error;
1231
+
1232
+ var self = this,
1233
+ service = new google.maps.DirectionsService();
1234
+
1235
+ service.route(request_options, function(result, status) {
1236
+ if (status === google.maps.DirectionsStatus.OK) {
1237
+ for (var r in result.routes) {
1238
+ if (result.routes.hasOwnProperty(r)) {
1239
+ self.routes.push(result.routes[r]);
1240
+ }
1241
+ }
1242
+
1243
+ if (options.callback) {
1244
+ options.callback(self.routes);
1245
+ }
1246
+ }
1247
+ else {
1248
+ if (options.error) {
1249
+ options.error(result, status);
1250
+ }
1251
+ }
1252
+ });
1253
+ };
1254
+
1255
+ GMaps.prototype.removeRoutes = function() {
1256
+ this.routes = [];
1257
+ };
1258
+
1259
+ GMaps.prototype.getElevations = function(options) {
1260
+ options = extend_object({
1261
+ locations: [],
1262
+ path : false,
1263
+ samples : 256
1264
+ }, options);
1265
+
1266
+ if (options.locations.length > 0) {
1267
+ if (options.locations[0].length > 0) {
1268
+ options.locations = array_flat(array_map([options.locations], arrayToLatLng, false));
1269
+ }
1270
+ }
1271
+
1272
+ var callback = options.callback;
1273
+ delete options.callback;
1274
+
1275
+ var service = new google.maps.ElevationService();
1276
+
1277
+ //location request
1278
+ if (!options.path) {
1279
+ delete options.path;
1280
+ delete options.samples;
1281
+
1282
+ service.getElevationForLocations(options, function(result, status) {
1283
+ if (callback && typeof(callback) === "function") {
1284
+ callback(result, status);
1285
+ }
1286
+ });
1287
+ //path request
1288
+ } else {
1289
+ var pathRequest = {
1290
+ path : options.locations,
1291
+ samples : options.samples
1292
+ };
1293
+
1294
+ service.getElevationAlongPath(pathRequest, function(result, status) {
1295
+ if (callback && typeof(callback) === "function") {
1296
+ callback(result, status);
1297
+ }
1298
+ });
1299
+ }
1300
+ };
1301
+
1302
+ GMaps.prototype.cleanRoute = GMaps.prototype.removePolylines;
1303
+
1304
+ GMaps.prototype.drawRoute = function(options) {
1305
+ var self = this;
1306
+
1307
+ this.getRoutes({
1308
+ origin: options.origin,
1309
+ destination: options.destination,
1310
+ travelMode: options.travelMode,
1311
+ waypoints: options.waypoints,
1312
+ unitSystem: options.unitSystem,
1313
+ error: options.error,
1314
+ callback: function(e) {
1315
+ if (e.length > 0) {
1316
+ self.drawPolyline({
1317
+ path: e[e.length - 1].overview_path,
1318
+ strokeColor: options.strokeColor,
1319
+ strokeOpacity: options.strokeOpacity,
1320
+ strokeWeight: options.strokeWeight
1321
+ });
1322
+
1323
+ if (options.callback) {
1324
+ options.callback(e[e.length - 1]);
1325
+ }
1326
+ }
1327
+ }
1328
+ });
1329
+ };
1330
+
1331
+ GMaps.prototype.travelRoute = function(options) {
1332
+ if (options.origin && options.destination) {
1333
+ this.getRoutes({
1334
+ origin: options.origin,
1335
+ destination: options.destination,
1336
+ travelMode: options.travelMode,
1337
+ waypoints : options.waypoints,
1338
+ error: options.error,
1339
+ callback: function(e) {
1340
+ //start callback
1341
+ if (e.length > 0 && options.start) {
1342
+ options.start(e[e.length - 1]);
1343
+ }
1344
+
1345
+ //step callback
1346
+ if (e.length > 0 && options.step) {
1347
+ var route = e[e.length - 1];
1348
+ if (route.legs.length > 0) {
1349
+ var steps = route.legs[0].steps;
1350
+ for (var i=0, step; step=steps[i]; i++) {
1351
+ step.step_number = i;
1352
+ options.step(step, (route.legs[0].steps.length - 1));
1353
+ }
1354
+ }
1355
+ }
1356
+
1357
+ //end callback
1358
+ if (e.length > 0 && options.end) {
1359
+ options.end(e[e.length - 1]);
1360
+ }
1361
+ }
1362
+ });
1363
+ }
1364
+ else if (options.route) {
1365
+ if (options.route.legs.length > 0) {
1366
+ var steps = options.route.legs[0].steps;
1367
+ for (var i=0, step; step=steps[i]; i++) {
1368
+ step.step_number = i;
1369
+ options.step(step);
1370
+ }
1371
+ }
1372
+ }
1373
+ };
1374
+
1375
+ GMaps.prototype.drawSteppedRoute = function(options) {
1376
+ var self = this;
1377
+
1378
+ if (options.origin && options.destination) {
1379
+ this.getRoutes({
1380
+ origin: options.origin,
1381
+ destination: options.destination,
1382
+ travelMode: options.travelMode,
1383
+ waypoints : options.waypoints,
1384
+ error: options.error,
1385
+ callback: function(e) {
1386
+ //start callback
1387
+ if (e.length > 0 && options.start) {
1388
+ options.start(e[e.length - 1]);
1389
+ }
1390
+
1391
+ //step callback
1392
+ if (e.length > 0 && options.step) {
1393
+ var route = e[e.length - 1];
1394
+ if (route.legs.length > 0) {
1395
+ var steps = route.legs[0].steps;
1396
+ for (var i=0, step; step=steps[i]; i++) {
1397
+ step.step_number = i;
1398
+ self.drawPolyline({
1399
+ path: step.path,
1400
+ strokeColor: options.strokeColor,
1401
+ strokeOpacity: options.strokeOpacity,
1402
+ strokeWeight: options.strokeWeight
1403
+ });
1404
+ options.step(step, (route.legs[0].steps.length - 1));
1405
+ }
1406
+ }
1407
+ }
1408
+
1409
+ //end callback
1410
+ if (e.length > 0 && options.end) {
1411
+ options.end(e[e.length - 1]);
1412
+ }
1413
+ }
1414
+ });
1415
+ }
1416
+ else if (options.route) {
1417
+ if (options.route.legs.length > 0) {
1418
+ var steps = options.route.legs[0].steps;
1419
+ for (var i=0, step; step=steps[i]; i++) {
1420
+ step.step_number = i;
1421
+ self.drawPolyline({
1422
+ path: step.path,
1423
+ strokeColor: options.strokeColor,
1424
+ strokeOpacity: options.strokeOpacity,
1425
+ strokeWeight: options.strokeWeight
1426
+ });
1427
+ options.step(step);
1428
+ }
1429
+ }
1430
+ }
1431
+ };
1432
+
1433
+ GMaps.Route = function(options) {
1434
+ this.origin = options.origin;
1435
+ this.destination = options.destination;
1436
+ this.waypoints = options.waypoints;
1437
+
1438
+ this.map = options.map;
1439
+ this.route = options.route;
1440
+ this.step_count = 0;
1441
+ this.steps = this.route.legs[0].steps;
1442
+ this.steps_length = this.steps.length;
1443
+
1444
+ this.polyline = this.map.drawPolyline({
1445
+ path: new google.maps.MVCArray(),
1446
+ strokeColor: options.strokeColor,
1447
+ strokeOpacity: options.strokeOpacity,
1448
+ strokeWeight: options.strokeWeight
1449
+ }).getPath();
1450
+ };
1451
+
1452
+ GMaps.Route.prototype.getRoute = function(options) {
1453
+ var self = this;
1454
+
1455
+ this.map.getRoutes({
1456
+ origin : this.origin,
1457
+ destination : this.destination,
1458
+ travelMode : options.travelMode,
1459
+ waypoints : this.waypoints || [],
1460
+ error: options.error,
1461
+ callback : function() {
1462
+ self.route = e[0];
1463
+
1464
+ if (options.callback) {
1465
+ options.callback.call(self);
1466
+ }
1467
+ }
1468
+ });
1469
+ };
1470
+
1471
+ GMaps.Route.prototype.back = function() {
1472
+ if (this.step_count > 0) {
1473
+ this.step_count--;
1474
+ var path = this.route.legs[0].steps[this.step_count].path;
1475
+
1476
+ for (var p in path){
1477
+ if (path.hasOwnProperty(p)){
1478
+ this.polyline.pop();
1479
+ }
1480
+ }
1481
+ }
1482
+ };
1483
+
1484
+ GMaps.Route.prototype.forward = function() {
1485
+ if (this.step_count < this.steps_length) {
1486
+ var path = this.route.legs[0].steps[this.step_count].path;
1487
+
1488
+ for (var p in path){
1489
+ if (path.hasOwnProperty(p)){
1490
+ this.polyline.push(path[p]);
1491
+ }
1492
+ }
1493
+ this.step_count++;
1494
+ }
1495
+ };
1496
+
1497
+ GMaps.prototype.checkGeofence = function(lat, lng, fence) {
1498
+ return fence.containsLatLng(new google.maps.LatLng(lat, lng));
1499
+ };
1500
+
1501
+ GMaps.prototype.checkMarkerGeofence = function(marker, outside_callback) {
1502
+ if (marker.fences) {
1503
+ for (var i = 0, fence; fence = marker.fences[i]; i++) {
1504
+ var pos = marker.getPosition();
1505
+ if (!this.checkGeofence(pos.lat(), pos.lng(), fence)) {
1506
+ outside_callback(marker, fence);
1507
+ }
1508
+ }
1509
+ }
1510
+ };
1511
+
1512
+ GMaps.prototype.toImage = function(options) {
1513
+ var options = options || {},
1514
+ static_map_options = {};
1515
+
1516
+ static_map_options['size'] = options['size'] || [this.el.clientWidth, this.el.clientHeight];
1517
+ static_map_options['lat'] = this.getCenter().lat();
1518
+ static_map_options['lng'] = this.getCenter().lng();
1519
+
1520
+ if (this.markers.length > 0) {
1521
+ static_map_options['markers'] = [];
1522
+
1523
+ for (var i = 0; i < this.markers.length; i++) {
1524
+ static_map_options['markers'].push({
1525
+ lat: this.markers[i].getPosition().lat(),
1526
+ lng: this.markers[i].getPosition().lng()
1527
+ });
1528
+ }
1529
+ }
1530
+
1531
+ if (this.polylines.length > 0) {
1532
+ var polyline = this.polylines[0];
1533
+
1534
+ static_map_options['polyline'] = {};
1535
+ static_map_options['polyline']['path'] = google.maps.geometry.encoding.encodePath(polyline.getPath());
1536
+ static_map_options['polyline']['strokeColor'] = polyline.strokeColor
1537
+ static_map_options['polyline']['strokeOpacity'] = polyline.strokeOpacity
1538
+ static_map_options['polyline']['strokeWeight'] = polyline.strokeWeight
1539
+ }
1540
+
1541
+ return GMaps.staticMapURL(static_map_options);
1542
+ };
1543
+
1544
+ GMaps.staticMapURL = function(options){
1545
+ var parameters = [],
1546
+ data,
1547
+ static_root = 'http://maps.googleapis.com/maps/api/staticmap';
1548
+
1549
+ if (options.url) {
1550
+ static_root = options.url;
1551
+ delete options.url;
1552
+ }
1553
+
1554
+ static_root += '?';
1555
+
1556
+ var markers = options.markers;
1557
+
1558
+ delete options.markers;
1559
+
1560
+ if (!markers && options.marker) {
1561
+ markers = [options.marker];
1562
+ delete options.marker;
1563
+ }
1564
+
1565
+ var styles = options.styles;
1566
+
1567
+ delete options.styles;
1568
+
1569
+ var polyline = options.polyline;
1570
+ delete options.polyline;
1571
+
1572
+ /** Map options **/
1573
+ if (options.center) {
1574
+ parameters.push('center=' + options.center);
1575
+ delete options.center;
1576
+ }
1577
+ else if (options.address) {
1578
+ parameters.push('center=' + options.address);
1579
+ delete options.address;
1580
+ }
1581
+ else if (options.lat) {
1582
+ parameters.push(['center=', options.lat, ',', options.lng].join(''));
1583
+ delete options.lat;
1584
+ delete options.lng;
1585
+ }
1586
+ else if (options.visible) {
1587
+ var visible = encodeURI(options.visible.join('|'));
1588
+ parameters.push('visible=' + visible);
1589
+ }
1590
+
1591
+ var size = options.size;
1592
+ if (size) {
1593
+ if (size.join) {
1594
+ size = size.join('x');
1595
+ }
1596
+ delete options.size;
1597
+ }
1598
+ else {
1599
+ size = '630x300';
1600
+ }
1601
+ parameters.push('size=' + size);
1602
+
1603
+ if (!options.zoom && options.zoom !== false) {
1604
+ options.zoom = 15;
1605
+ }
1606
+
1607
+ var sensor = options.hasOwnProperty('sensor') ? !!options.sensor : true;
1608
+ delete options.sensor;
1609
+ parameters.push('sensor=' + sensor);
1610
+
1611
+ for (var param in options) {
1612
+ if (options.hasOwnProperty(param)) {
1613
+ parameters.push(param + '=' + options[param]);
1614
+ }
1615
+ }
1616
+
1617
+ /** Markers **/
1618
+ if (markers) {
1619
+ var marker, loc;
1620
+
1621
+ for (var i=0; data=markers[i]; i++) {
1622
+ marker = [];
1623
+
1624
+ if (data.size && data.size !== 'normal') {
1625
+ marker.push('size:' + data.size);
1626
+ delete data.size;
1627
+ }
1628
+ else if (data.icon) {
1629
+ marker.push('icon:' + encodeURI(data.icon));
1630
+ delete data.icon;
1631
+ }
1632
+
1633
+ if (data.color) {
1634
+ marker.push('color:' + data.color.replace('#', '0x'));
1635
+ delete data.color;
1636
+ }
1637
+
1638
+ if (data.label) {
1639
+ marker.push('label:' + data.label[0].toUpperCase());
1640
+ delete data.label;
1641
+ }
1642
+
1643
+ loc = (data.address ? data.address : data.lat + ',' + data.lng);
1644
+ delete data.address;
1645
+ delete data.lat;
1646
+ delete data.lng;
1647
+
1648
+ for(var param in data){
1649
+ if (data.hasOwnProperty(param)) {
1650
+ marker.push(param + ':' + data[param]);
1651
+ }
1652
+ }
1653
+
1654
+ if (marker.length || i === 0) {
1655
+ marker.push(loc);
1656
+ marker = marker.join('|');
1657
+ parameters.push('markers=' + encodeURI(marker));
1658
+ }
1659
+ // New marker without styles
1660
+ else {
1661
+ marker = parameters.pop() + encodeURI('|' + loc);
1662
+ parameters.push(marker);
1663
+ }
1664
+ }
1665
+ }
1666
+
1667
+ /** Map Styles **/
1668
+ if (styles) {
1669
+ for (var i = 0; i < styles.length; i++) {
1670
+ var styleRule = [];
1671
+ if (styles[i].featureType && styles[i].featureType != 'all' ) {
1672
+ styleRule.push('feature:' + styles[i].featureType);
1673
+ }
1674
+
1675
+ if (styles[i].elementType && styles[i].elementType != 'all') {
1676
+ styleRule.push('element:' + styles[i].elementType);
1677
+ }
1678
+
1679
+ for (var j = 0; j < styles[i].stylers.length; j++) {
1680
+ for (var p in styles[i].stylers[j]) {
1681
+ var ruleArg = styles[i].stylers[j][p];
1682
+ if (p == 'hue' || p == 'color') {
1683
+ ruleArg = '0x' + ruleArg.substring(1);
1684
+ }
1685
+ styleRule.push(p + ':' + ruleArg);
1686
+ }
1687
+ }
1688
+
1689
+ var rule = styleRule.join('|');
1690
+ if (rule != '') {
1691
+ parameters.push('style=' + rule);
1692
+ }
1693
+ }
1694
+ }
1695
+
1696
+ /** Polylines **/
1697
+ function parseColor(color, opacity) {
1698
+ if (color[0] === '#'){
1699
+ color = color.replace('#', '0x');
1700
+
1701
+ if (opacity) {
1702
+ opacity = parseFloat(opacity);
1703
+ opacity = Math.min(1, Math.max(opacity, 0));
1704
+ if (opacity === 0) {
1705
+ return '0x00000000';
1706
+ }
1707
+ opacity = (opacity * 255).toString(16);
1708
+ if (opacity.length === 1) {
1709
+ opacity += opacity;
1710
+ }
1711
+
1712
+ color = color.slice(0,8) + opacity;
1713
+ }
1714
+ }
1715
+ return color;
1716
+ }
1717
+
1718
+ if (polyline) {
1719
+ data = polyline;
1720
+ polyline = [];
1721
+
1722
+ if (data.strokeWeight) {
1723
+ polyline.push('weight:' + parseInt(data.strokeWeight, 10));
1724
+ }
1725
+
1726
+ if (data.strokeColor) {
1727
+ var color = parseColor(data.strokeColor, data.strokeOpacity);
1728
+ polyline.push('color:' + color);
1729
+ }
1730
+
1731
+ if (data.fillColor) {
1732
+ var fillcolor = parseColor(data.fillColor, data.fillOpacity);
1733
+ polyline.push('fillcolor:' + fillcolor);
1734
+ }
1735
+
1736
+ var path = data.path;
1737
+ if (path.join) {
1738
+ for (var j=0, pos; pos=path[j]; j++) {
1739
+ polyline.push(pos.join(','));
1740
+ }
1741
+ }
1742
+ else {
1743
+ polyline.push('enc:' + path);
1744
+ }
1745
+
1746
+ polyline = polyline.join('|');
1747
+ parameters.push('path=' + encodeURI(polyline));
1748
+ }
1749
+
1750
+ parameters = parameters.join('&');
1751
+ return static_root + parameters;
1752
+ };
1753
+
1754
+ GMaps.prototype.addMapType = function(mapTypeId, options) {
1755
+ if (options.hasOwnProperty("getTileUrl") && typeof(options["getTileUrl"]) == "function") {
1756
+ options.tileSize = options.tileSize || new google.maps.Size(256, 256);
1757
+
1758
+ var mapType = new google.maps.ImageMapType(options);
1759
+
1760
+ this.map.mapTypes.set(mapTypeId, mapType);
1761
+ }
1762
+ else {
1763
+ throw "'getTileUrl' function required.";
1764
+ }
1765
+ };
1766
+
1767
+ GMaps.prototype.addOverlayMapType = function(options) {
1768
+ if (options.hasOwnProperty("getTile") && typeof(options["getTile"]) == "function") {
1769
+ var overlayMapTypeIndex = options.index;
1770
+
1771
+ delete options.index;
1772
+
1773
+ this.map.overlayMapTypes.insertAt(overlayMapTypeIndex, options);
1774
+ }
1775
+ else {
1776
+ throw "'getTile' function required.";
1777
+ }
1778
+ };
1779
+
1780
+ GMaps.prototype.removeOverlayMapType = function(overlayMapTypeIndex) {
1781
+ this.map.overlayMapTypes.removeAt(overlayMapTypeIndex);
1782
+ };
1783
+
1784
+ GMaps.prototype.addStyle = function(options) {
1785
+ var styledMapType = new google.maps.StyledMapType(options.styles, { name: options.styledMapName });
1786
+
1787
+ this.map.mapTypes.set(options.mapTypeId, styledMapType);
1788
+ };
1789
+
1790
+ GMaps.prototype.setStyle = function(mapTypeId) {
1791
+ this.map.setMapTypeId(mapTypeId);
1792
+ };
1793
+
1794
+ GMaps.prototype.createPanorama = function(streetview_options) {
1795
+ if (!streetview_options.hasOwnProperty('lat') || !streetview_options.hasOwnProperty('lng')) {
1796
+ streetview_options.lat = this.getCenter().lat();
1797
+ streetview_options.lng = this.getCenter().lng();
1798
+ }
1799
+
1800
+ this.panorama = GMaps.createPanorama(streetview_options);
1801
+
1802
+ this.map.setStreetView(this.panorama);
1803
+
1804
+ return this.panorama;
1805
+ };
1806
+
1807
+ GMaps.createPanorama = function(options) {
1808
+ var el = getElementById(options.el, options.context);
1809
+
1810
+ options.position = new google.maps.LatLng(options.lat, options.lng);
1811
+
1812
+ delete options.el;
1813
+ delete options.context;
1814
+ delete options.lat;
1815
+ delete options.lng;
1816
+
1817
+ var streetview_events = ['closeclick', 'links_changed', 'pano_changed', 'position_changed', 'pov_changed', 'resize', 'visible_changed'],
1818
+ streetview_options = extend_object({visible : true}, options);
1819
+
1820
+ for (var i = 0; i < streetview_events.length; i++) {
1821
+ delete streetview_options[streetview_events[i]];
1822
+ }
1823
+
1824
+ var panorama = new google.maps.StreetViewPanorama(el, streetview_options);
1825
+
1826
+ for (var i = 0; i < streetview_events.length; i++) {
1827
+ (function(object, name) {
1828
+ if (options[name]) {
1829
+ google.maps.event.addListener(object, name, function(){
1830
+ options[name].apply(this);
1831
+ });
1832
+ }
1833
+ })(panorama, streetview_events[i]);
1834
+ }
1835
+
1836
+ return panorama;
1837
+ };
1838
+
1839
+ GMaps.prototype.on = function(event_name, handler) {
1840
+ return GMaps.on(event_name, this, handler);
1841
+ };
1842
+
1843
+ GMaps.prototype.off = function(event_name) {
1844
+ GMaps.off(event_name, this);
1845
+ };
1846
+
1847
+ GMaps.custom_events = ['marker_added', 'marker_removed', 'polyline_added', 'polyline_removed', 'polygon_added', 'polygon_removed', 'geolocated', 'geolocation_failed'];
1848
+
1849
+ GMaps.on = function(event_name, object, handler) {
1850
+ if (GMaps.custom_events.indexOf(event_name) == -1) {
1851
+ return google.maps.event.addListener(object, event_name, handler);
1852
+ }
1853
+ else {
1854
+ var registered_event = {
1855
+ handler : handler,
1856
+ eventName : event_name
1857
+ };
1858
+
1859
+ object.registered_events[event_name] = object.registered_events[event_name] || [];
1860
+ object.registered_events[event_name].push(registered_event);
1861
+
1862
+ return registered_event;
1863
+ }
1864
+ };
1865
+
1866
+ GMaps.off = function(event_name, object) {
1867
+ if (GMaps.custom_events.indexOf(event_name) == -1) {
1868
+ google.maps.event.clearListeners(object, event_name);
1869
+ }
1870
+ else {
1871
+ object.registered_events[event_name] = [];
1872
+ }
1873
+ };
1874
+
1875
+ GMaps.fire = function(event_name, object, scope) {
1876
+ if (GMaps.custom_events.indexOf(event_name) == -1) {
1877
+ google.maps.event.trigger(object, event_name, Array.prototype.slice.apply(arguments).slice(2));
1878
+ }
1879
+ else {
1880
+ if(event_name in scope.registered_events) {
1881
+ var firing_events = scope.registered_events[event_name];
1882
+
1883
+ for(var i = 0; i < firing_events.length; i++) {
1884
+ (function(handler, scope, object) {
1885
+ handler.apply(scope, [object]);
1886
+ })(firing_events[i]['handler'], scope, object);
1887
+ }
1888
+ }
1889
+ }
1890
+ };
1891
+
1892
+ GMaps.geolocate = function(options) {
1893
+ var complete_callback = options.always || options.complete;
1894
+
1895
+ if (navigator.geolocation) {
1896
+ navigator.geolocation.getCurrentPosition(function(position) {
1897
+ options.success(position);
1898
+
1899
+ if (complete_callback) {
1900
+ complete_callback();
1901
+ }
1902
+ }, function(error) {
1903
+ options.error(error);
1904
+
1905
+ if (complete_callback) {
1906
+ complete_callback();
1907
+ }
1908
+ }, options.options);
1909
+ }
1910
+ else {
1911
+ options.not_supported();
1912
+
1913
+ if (complete_callback) {
1914
+ complete_callback();
1915
+ }
1916
+ }
1917
+ };
1918
+
1919
+ GMaps.geocode = function(options) {
1920
+ this.geocoder = new google.maps.Geocoder();
1921
+ var callback = options.callback;
1922
+ if (options.hasOwnProperty('lat') && options.hasOwnProperty('lng')) {
1923
+ options.latLng = new google.maps.LatLng(options.lat, options.lng);
1924
+ }
1925
+
1926
+ delete options.lat;
1927
+ delete options.lng;
1928
+ delete options.callback;
1929
+
1930
+ this.geocoder.geocode(options, function(results, status) {
1931
+ callback(results, status);
1932
+ });
1933
+ };
1934
+
1935
+ //==========================
1936
+ // Polygon containsLatLng
1937
+ // https://github.com/tparkin/Google-Maps-Point-in-Polygon
1938
+ // Poygon getBounds extension - google-maps-extensions
1939
+ // http://code.google.com/p/google-maps-extensions/source/browse/google.maps.Polygon.getBounds.js
1940
+ if (!google.maps.Polygon.prototype.getBounds) {
1941
+ google.maps.Polygon.prototype.getBounds = function(latLng) {
1942
+ var bounds = new google.maps.LatLngBounds();
1943
+ var paths = this.getPaths();
1944
+ var path;
1945
+
1946
+ for (var p = 0; p < paths.getLength(); p++) {
1947
+ path = paths.getAt(p);
1948
+ for (var i = 0; i < path.getLength(); i++) {
1949
+ bounds.extend(path.getAt(i));
1950
+ }
1951
+ }
1952
+
1953
+ return bounds;
1954
+ };
1955
+ }
1956
+
1957
+ if (!google.maps.Polygon.prototype.containsLatLng) {
1958
+ // Polygon containsLatLng - method to determine if a latLng is within a polygon
1959
+ google.maps.Polygon.prototype.containsLatLng = function(latLng) {
1960
+ // Exclude points outside of bounds as there is no way they are in the poly
1961
+ var bounds = this.getBounds();
1962
+
1963
+ if (bounds !== null && !bounds.contains(latLng)) {
1964
+ return false;
1965
+ }
1966
+
1967
+ // Raycast point in polygon method
1968
+ var inPoly = false;
1969
+
1970
+ var numPaths = this.getPaths().getLength();
1971
+ for (var p = 0; p < numPaths; p++) {
1972
+ var path = this.getPaths().getAt(p);
1973
+ var numPoints = path.getLength();
1974
+ var j = numPoints - 1;
1975
+
1976
+ for (var i = 0; i < numPoints; i++) {
1977
+ var vertex1 = path.getAt(i);
1978
+ var vertex2 = path.getAt(j);
1979
+
1980
+ if (vertex1.lng() < latLng.lng() && vertex2.lng() >= latLng.lng() || vertex2.lng() < latLng.lng() && vertex1.lng() >= latLng.lng()) {
1981
+ if (vertex1.lat() + (latLng.lng() - vertex1.lng()) / (vertex2.lng() - vertex1.lng()) * (vertex2.lat() - vertex1.lat()) < latLng.lat()) {
1982
+ inPoly = !inPoly;
1983
+ }
1984
+ }
1985
+
1986
+ j = i;
1987
+ }
1988
+ }
1989
+
1990
+ return inPoly;
1991
+ };
1992
+ }
1993
+
1994
+ google.maps.LatLngBounds.prototype.containsLatLng = function(latLng) {
1995
+ return this.contains(latLng);
1996
+ };
1997
+
1998
+ google.maps.Marker.prototype.setFences = function(fences) {
1999
+ this.fences = fences;
2000
+ };
2001
+
2002
+ google.maps.Marker.prototype.addFence = function(fence) {
2003
+ this.fences.push(fence);
2004
+ };
2005
+
2006
+ google.maps.Marker.prototype.getId = function() {
2007
+ return this['__gm_id'];
2008
+ };
2009
+
2010
+ //==========================
2011
+ // Array indexOf
2012
+ // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf
2013
+ if (!Array.prototype.indexOf) {
2014
+ Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
2015
+ "use strict";
2016
+ if (this == null) {
2017
+ throw new TypeError();
2018
+ }
2019
+ var t = Object(this);
2020
+ var len = t.length >>> 0;
2021
+ if (len === 0) {
2022
+ return -1;
2023
+ }
2024
+ var n = 0;
2025
+ if (arguments.length > 1) {
2026
+ n = Number(arguments[1]);
2027
+ if (n != n) { // shortcut for verifying if it's NaN
2028
+ n = 0;
2029
+ } else if (n != 0 && n != Infinity && n != -Infinity) {
2030
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
2031
+ }
2032
+ }
2033
+ if (n >= len) {
2034
+ return -1;
2035
+ }
2036
+ var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
2037
+ for (; k < len; k++) {
2038
+ if (k in t && t[k] === searchElement) {
2039
+ return k;
2040
+ }
2041
+ }
2042
+ return -1;
2043
+ }
2044
+ }
js/simple-map.js ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($){
2
+
3
+ var SimpleMap = function(element, pos, zoom, infoCont) {
4
+ this.base_url = 'https://maps.google.com/maps?';
5
+ this.display(element, pos, zoom, infoCont);
6
+ }
7
+
8
+ SimpleMap.prototype.display = function(element, pos, zoom, infoCont) {
9
+ $(element).show();
10
+ var breakpoint = $(element).data('breakpoint');
11
+ if (breakpoint > 640) {
12
+ breakpoint = 640;
13
+ }
14
+ if ($('html').width() > breakpoint) {
15
+ var map = new GMaps({
16
+ div: element,
17
+ lat: pos.lat(),
18
+ lng: pos.lng(),
19
+ mapTypeControl: false,
20
+ zoom: parseFloat(zoom),
21
+ streetViewControl: false,
22
+ scrollwheel: false,
23
+ mapTypeId: google.maps.MapTypeId.ROADMAP
24
+ });
25
+ if (infoCont.length) {
26
+ var marker = map.addMarker({
27
+ lat: pos.lat(),
28
+ lng: pos.lng(),
29
+ infoWindow: {
30
+ content: infoCont
31
+ }
32
+ });
33
+ if ($(element).data('infowindow') == 'open') {
34
+ marker.infoWindow.open(map, marker);
35
+ }
36
+ } else {
37
+ map.addMarker({
38
+ lat: pos.lat(),
39
+ lng: pos.lng()
40
+ });
41
+ }
42
+ } else {
43
+ var url = GMaps.staticMapURL({
44
+ center: pos.lat()+','+pos.lng(),
45
+ zoom: zoom,
46
+ size: breakpoint+'x'+$(element).height(),
47
+ markers: [
48
+ {lat: pos.lat(), lng: pos.lng()}
49
+ ],
50
+ sensor: 'false'
51
+ });
52
+ var img = $('<img />');
53
+ $(img).attr('src', url);
54
+ $(img).attr('alt', $(element).text());
55
+ var a = $('<a />');
56
+ $(a).attr(
57
+ 'href',
58
+ this.base_url+'q='+pos.lat()+','+pos.lng()+'&z='+zoom
59
+ );
60
+ $(a).html(img);
61
+ $(element).html(a);
62
+ $(element).addClass('staticmap');
63
+ }
64
+ }
65
+
66
+ $('.simplemap').each(function(){
67
+ var element = $('div', this).get(0);
68
+ var zoom = 16;
69
+ if (parseFloat($(element).data('zoom'))) {
70
+ zoom = $(element).data('zoom');
71
+ }
72
+ if ($(element).data('lat') && $(element).data('lng')) {
73
+ var lat = $(element).data('lat');
74
+ var lng = $(element).data('lng');
75
+ var infoCont = $(element).html();
76
+ var pos = new google.maps.LatLng(
77
+ lat,
78
+ lng
79
+ );
80
+ new SimpleMap(element, pos, zoom, infoCont);
81
+ } else if ($(element).data('addr')) {
82
+ GMaps.geocode({
83
+ address: $(element).data('addr'),
84
+ callback: function(results, status) {
85
+ if (status == 'OK') {
86
+ var pos = results[0].geometry.location;
87
+ new SimpleMap(element, pos, zoom, $(element).html());
88
+ }
89
+ }
90
+ });
91
+ } else if ($(element).text().length) {
92
+ GMaps.geocode({
93
+ address: $(element).text(),
94
+ callback: function(results, status) {
95
+ if (status == 'OK') {
96
+ var pos = results[0].geometry.location;
97
+ new SimpleMap(element, pos, zoom, $(element).text());
98
+ }
99
+ }
100
+ });
101
+ }
102
+ });
103
+
104
+ })(jQuery);
js/simple-map.min.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Simple Map - v1.3.0
3
+ *
4
+ * http://wordpress.org/plugins/simple-map/
5
+ * https://github.com/miya0001/simple-map
6
+ *
7
+ * Special thanks!
8
+ * http://hpneo.github.io/gmaps/
9
+ *
10
+ * Copyright 2014, Takayuki Miyauchi (http://wpist.me/)
11
+ * Released under the GPLv2
12
+ */
13
+ (function(e,t){"object"==typeof exports?module.exports=t():"function"==typeof define&&define.amd&&define("GMaps",[],t),e.GMaps=t()})(this,function(){if("object"!=typeof window.google||!window.google.maps)throw"Google Maps API is required. Please register the following JavaScript library http://maps.google.com/maps/api/js?sensor=true.";var t=function(e,t){var o;if(e===t)return e;for(o in t)e[o]=t[o];return e},o=function(e,t){var o,n=Array.prototype.slice.call(arguments,2),r=[],a=e.length;if(Array.prototype.map&&e.map===Array.prototype.map)r=Array.prototype.map.call(e,function(e){return callback_params=n,callback_params.splice(0,0,e),t.apply(this,callback_params)});else for(o=0;a>o;o++)callback_params=n,callback_params.splice(0,0,e[o]),r.push(t.apply(this,callback_params));return r},n=function(e){var t,o=[];for(t=0;e.length>t;t++)o=o.concat(e[t]);return o},r=function(e,t){var o=e[0],n=e[1];return t&&(o=e[1],n=e[0]),new google.maps.LatLng(o,n)},a=function(e,t){var o;for(o=0;e.length>o;o++)e[o]instanceof google.maps.LatLng||(e[o]=e[o].length>0&&"object"==typeof e[o][0]?a(e[o],t):r(e[o],t));return e},s=function(e,t){var o,e=e.replace("#","");return o="jQuery"in this&&t?$("#"+e,t)[0]:document.getElementById(e)},i=function(e){var t=0,o=0;if(e.offsetParent)do t+=e.offsetLeft,o+=e.offsetTop;while(e=e.offsetParent);return[t,o]},l=function(){"use strict";var e=document,o=function(n){if(!this)return new o(n);n.zoom=n.zoom||15,n.mapType=n.mapType||"roadmap";var r,a=this,l=["bounds_changed","center_changed","click","dblclick","drag","dragend","dragstart","idle","maptypeid_changed","projection_changed","resize","tilesloaded","zoom_changed"],p=["mousemove","mouseout","mouseover"],g=["el","lat","lng","mapType","width","height","markerClusterer","enableNewStyle"],c=n.el||n.div,h=n.markerClusterer,d=google.maps.MapTypeId[n.mapType.toUpperCase()],u=new google.maps.LatLng(n.lat,n.lng),m=n.zoomControl||!0,f=n.zoomControlOpt||{style:"DEFAULT",position:"TOP_LEFT"},y=f.style||"DEFAULT",v=f.position||"TOP_LEFT",k=n.panControl||!0,w=n.mapTypeControl||!0,b=n.scaleControl||!0,L=n.streetViewControl||!0,_=_||!0,M={},x={zoom:this.zoom,center:u,mapTypeId:d},C={panControl:k,zoomControl:m,zoomControlOptions:{style:google.maps.ZoomControlStyle[y],position:google.maps.ControlPosition[v]},mapTypeControl:w,scaleControl:b,streetViewControl:L,overviewMapControl:_};if(this.el="string"==typeof n.el||"string"==typeof n.div?s(c,n.context):c,this.el===void 0||null===this.el)throw"No element defined.";for(window.context_menu=window.context_menu||{},window.context_menu[a.el.id]={},this.controls=[],this.overlays=[],this.layers=[],this.singleLayers={},this.markers=[],this.polylines=[],this.routes=[],this.polygons=[],this.infoWindow=null,this.overlay_el=null,this.zoom=n.zoom,this.registered_events={},this.el.style.width=n.width||this.el.scrollWidth||this.el.offsetWidth,this.el.style.height=n.height||this.el.scrollHeight||this.el.offsetHeight,google.maps.visualRefresh=n.enableNewStyle,r=0;g.length>r;r++)delete n[g[r]];for(1!=n.disableDefaultUI&&(x=t(x,C)),M=t(x,n),r=0;l.length>r;r++)delete M[l[r]];for(r=0;p.length>r;r++)delete M[p[r]];this.map=new google.maps.Map(this.el,M),h&&(this.markerClusterer=h.apply(this,[this.map]));var O=function(e,t){var o="",n=window.context_menu[a.el.id][e];for(var r in n)if(n.hasOwnProperty(r)){var l=n[r];o+='<li><a id="'+e+"_"+r+'" href="#">'+l.title+"</a></li>"}if(s("gmaps_context_menu")){var p=s("gmaps_context_menu");p.innerHTML=o;var r,g=p.getElementsByTagName("a"),c=g.length;for(r=0;c>r;r++){var h=g[r],d=function(o){o.preventDefault(),n[this.id.replace(e+"_","")].action.apply(a,[t]),a.hideContextMenu()};google.maps.event.clearListeners(h,"click"),google.maps.event.addDomListenerOnce(h,"click",d,!1)}var u=i.apply(this,[a.el]),m=u[0]+t.pixel.x-15,f=u[1]+t.pixel.y-15;p.style.left=m+"px",p.style.top=f+"px",p.style.display="block"}};this.buildContextMenu=function(e,t){if("marker"===e){t.pixel={};var o=new google.maps.OverlayView;o.setMap(a.map),o.draw=function(){var n=o.getProjection(),r=t.marker.getPosition();t.pixel=n.fromLatLngToContainerPixel(r),O(e,t)}}else O(e,t)},this.setContextMenu=function(t){window.context_menu[a.el.id][t.control]={};var o,n=e.createElement("ul");for(o in t.options)if(t.options.hasOwnProperty(o)){var r=t.options[o];window.context_menu[a.el.id][t.control][r.name]={title:r.title,action:r.action}}n.id="gmaps_context_menu",n.style.display="none",n.style.position="absolute",n.style.minWidth="100px",n.style.background="white",n.style.listStyle="none",n.style.padding="8px",n.style.boxShadow="2px 2px 6px #ccc",e.body.appendChild(n);var i=s("gmaps_context_menu");google.maps.event.addDomListener(i,"mouseout",function(e){e.relatedTarget&&this.contains(e.relatedTarget)||window.setTimeout(function(){i.style.display="none"},400)},!1)},this.hideContextMenu=function(){var e=s("gmaps_context_menu");e&&(e.style.display="none")};var P=function(e,t){google.maps.event.addListener(e,t,function(e){void 0==e&&(e=this),n[t].apply(this,[e]),a.hideContextMenu()})};google.maps.event.addListener(this.map,"zoom_changed",this.hideContextMenu);for(var T=0;l.length>T;T++){var z=l[T];z in n&&P(this.map,z)}for(var T=0;p.length>T;T++){var z=p[T];z in n&&P(this.map,z)}google.maps.event.addListener(this.map,"rightclick",function(e){n.rightclick&&n.rightclick.apply(this,[e]),void 0!=window.context_menu[a.el.id].map&&a.buildContextMenu("map",e)}),this.refresh=function(){google.maps.event.trigger(this.map,"resize")},this.fitZoom=function(){var e,t=[],o=this.markers.length;for(e=0;o>e;e++)"boolean"==typeof this.markers[e].visible&&this.markers[e].visible&&t.push(this.markers[e].getPosition());this.fitLatLngBounds(t)},this.fitLatLngBounds=function(e){for(var t=e.length,o=new google.maps.LatLngBounds,n=0;t>n;n++)o.extend(e[n]);this.map.fitBounds(o)},this.setCenter=function(e,t,o){this.map.panTo(new google.maps.LatLng(e,t)),o&&o()},this.getElement=function(){return this.el},this.zoomIn=function(e){e=e||1,this.zoom=this.map.getZoom()+e,this.map.setZoom(this.zoom)},this.zoomOut=function(e){e=e||1,this.zoom=this.map.getZoom()-e,this.map.setZoom(this.zoom)};var S,W=[];for(S in this.map)"function"!=typeof this.map[S]||this[S]||W.push(S);for(r=0;W.length>r;r++)(function(e,t,o){e[o]=function(){return t[o].apply(t,arguments)}})(this,this.map,W[r])};return o}(this);l.prototype.createControl=function(e){var t=document.createElement("div");t.style.cursor="pointer",e.disableDefaultStyles!==!0&&(t.style.fontFamily="Roboto, Arial, sans-serif",t.style.fontSize="11px",t.style.boxShadow="rgba(0, 0, 0, 0.298039) 0px 1px 4px -1px");for(var o in e.style)t.style[o]=e.style[o];e.id&&(t.id=e.id),e.classes&&(t.className=e.classes),e.content&&(t.innerHTML=e.content),e.position&&(t.position=google.maps.ControlPosition[e.position.toUpperCase()]);for(var n in e.events)(function(t,o){google.maps.event.addDomListener(t,o,function(){e.events[o].apply(this,[this])})})(t,n);return t.index=1,t},l.prototype.addControl=function(e){var t=this.createControl(e);return this.controls.push(t),this.map.controls[t.position].push(t),t},l.prototype.removeControl=function(e){for(var t=null,o=0;this.controls.length>o;o++)this.controls[o]==e&&(t=this.controls[o].position,this.controls.splice(o,1));if(t)for(o=0;this.map.controls.length>o;o++){var n=this.map.controls[e.position];if(n.getAt(o)==e){n.removeAt(o);break}}return e},l.prototype.createMarker=function(e){if(void 0==e.lat&&void 0==e.lng&&void 0==e.position)throw"No latitude or longitude defined.";var o=this,n=e.details,r=e.fences,a=e.outside,s={position:new google.maps.LatLng(e.lat,e.lng),map:null},i=t(s,e);delete i.lat,delete i.lng,delete i.fences,delete i.outside;var l=new google.maps.Marker(i);if(l.fences=r,e.infoWindow){l.infoWindow=new google.maps.InfoWindow(e.infoWindow);for(var p=["closeclick","content_changed","domready","position_changed","zindex_changed"],g=0;p.length>g;g++)(function(t,o){e.infoWindow[o]&&google.maps.event.addListener(t,o,function(t){e.infoWindow[o].apply(this,[t])})})(l.infoWindow,p[g])}for(var c=["animation_changed","clickable_changed","cursor_changed","draggable_changed","flat_changed","icon_changed","position_changed","shadow_changed","shape_changed","title_changed","visible_changed","zindex_changed"],h=["dblclick","drag","dragend","dragstart","mousedown","mouseout","mouseover","mouseup"],g=0;c.length>g;g++)(function(t,o){e[o]&&google.maps.event.addListener(t,o,function(){e[o].apply(this,[this])})})(l,c[g]);for(var g=0;h.length>g;g++)(function(t,o,n){e[n]&&google.maps.event.addListener(o,n,function(o){o.pixel||(o.pixel=t.getProjection().fromLatLngToPoint(o.latLng)),e[n].apply(this,[o])})})(this.map,l,h[g]);return google.maps.event.addListener(l,"click",function(){this.details=n,e.click&&e.click.apply(this,[this]),l.infoWindow&&(o.hideInfoWindows(),l.infoWindow.open(o.map,l))}),google.maps.event.addListener(l,"rightclick",function(t){t.marker=this,e.rightclick&&e.rightclick.apply(this,[t]),void 0!=window.context_menu[o.el.id].marker&&o.buildContextMenu("marker",t)}),l.fences&&google.maps.event.addListener(l,"dragend",function(){o.checkMarkerGeofence(l,function(e,t){a(e,t)})}),l},l.prototype.addMarker=function(e){var t;if(e.hasOwnProperty("gm_accessors_"))t=e;else{if(!(e.hasOwnProperty("lat")&&e.hasOwnProperty("lng")||e.position))throw"No latitude or longitude defined.";t=this.createMarker(e)}return t.setMap(this.map),this.markerClusterer&&this.markerClusterer.addMarker(t),this.markers.push(t),l.fire("marker_added",t,this),t},l.prototype.addMarkers=function(e){for(var t,o=0;t=e[o];o++)this.addMarker(t);return this.markers},l.prototype.hideInfoWindows=function(){for(var e,t=0;e=this.markers[t];t++)e.infoWindow&&e.infoWindow.close()},l.prototype.removeMarker=function(e){for(var t=0;this.markers.length>t;t++)if(this.markers[t]===e){this.markers[t].setMap(null),this.markers.splice(t,1),this.markerClusterer&&this.markerClusterer.removeMarker(e),l.fire("marker_removed",e,this);break}return e},l.prototype.removeMarkers=function(e){var t=[];if(e===void 0){for(var o=0;this.markers.length>o;o++)this.markers[o].setMap(null);this.markers=t}else{for(var o=0;e.length>o;o++)this.markers.indexOf(e[o])>-1&&this.markers[o].setMap(null);for(var o=0;this.markers.length>o;o++)null!=this.markers[o].getMap()&&t.push(this.markers[o]);this.markers=t}},l.prototype.drawOverlay=function(e){var t=new google.maps.OverlayView,o=!0;return t.setMap(this.map),null!=e.auto_show&&(o=e.auto_show),t.onAdd=function(){var o=document.createElement("div");o.style.borderStyle="none",o.style.borderWidth="0px",o.style.position="absolute",o.style.zIndex=100,o.innerHTML=e.content,t.el=o,e.layer||(e.layer="overlayLayer");var n=this.getPanes(),r=n[e.layer],a=["contextmenu","DOMMouseScroll","dblclick","mousedown"];r.appendChild(o);for(var s=0;a.length>s;s++)(function(e,t){google.maps.event.addDomListener(e,t,function(e){-1!=navigator.userAgent.toLowerCase().indexOf("msie")&&document.all?(e.cancelBubble=!0,e.returnValue=!1):e.stopPropagation()})})(o,a[s]);e.click&&google.maps.event.addDomListener(t.el,"click",function(){e.click.apply(t,[t])}),google.maps.event.trigger(this,"ready")},t.draw=function(){var n=this.getProjection(),r=n.fromLatLngToDivPixel(new google.maps.LatLng(e.lat,e.lng));e.horizontalOffset=e.horizontalOffset||0,e.verticalOffset=e.verticalOffset||0;var a=t.el,s=a.children[0],i=s.clientHeight,l=s.clientWidth;switch(e.verticalAlign){case"top":a.style.top=r.y-i+e.verticalOffset+"px";break;default:case"middle":a.style.top=r.y-i/2+e.verticalOffset+"px";break;case"bottom":a.style.top=r.y+e.verticalOffset+"px"}switch(e.horizontalAlign){case"left":a.style.left=r.x-l+e.horizontalOffset+"px";break;default:case"center":a.style.left=r.x-l/2+e.horizontalOffset+"px";break;case"right":a.style.left=r.x+e.horizontalOffset+"px"}a.style.display=o?"block":"none",o||e.show.apply(this,[a])},t.onRemove=function(){var o=t.el;e.remove?e.remove.apply(this,[o]):(t.el.parentNode.removeChild(t.el),t.el=null)},this.overlays.push(t),t},l.prototype.removeOverlay=function(e){for(var t=0;this.overlays.length>t;t++)if(this.overlays[t]===e){this.overlays[t].setMap(null),this.overlays.splice(t,1);break}},l.prototype.removeOverlays=function(){for(var e,t=0;e=this.overlays[t];t++)e.setMap(null);this.overlays=[]},l.prototype.drawPolyline=function(e){var t=[],o=e.path;if(o.length)if(void 0===o[0][0])t=o;else for(var n,r=0;n=o[r];r++)t.push(new google.maps.LatLng(n[0],n[1]));var a={map:this.map,path:t,strokeColor:e.strokeColor,strokeOpacity:e.strokeOpacity,strokeWeight:e.strokeWeight,geodesic:e.geodesic,clickable:!0,editable:!1,visible:!0};e.hasOwnProperty("clickable")&&(a.clickable=e.clickable),e.hasOwnProperty("editable")&&(a.editable=e.editable),e.hasOwnProperty("icons")&&(a.icons=e.icons),e.hasOwnProperty("zIndex")&&(a.zIndex=e.zIndex);for(var s=new google.maps.Polyline(a),i=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"],p=0;i.length>p;p++)(function(t,o){e[o]&&google.maps.event.addListener(t,o,function(t){e[o].apply(this,[t])})})(s,i[p]);return this.polylines.push(s),l.fire("polyline_added",s,this),s},l.prototype.removePolyline=function(e){for(var t=0;this.polylines.length>t;t++)if(this.polylines[t]===e){this.polylines[t].setMap(null),this.polylines.splice(t,1),l.fire("polyline_removed",e,this);break}},l.prototype.removePolylines=function(){for(var e,t=0;e=this.polylines[t];t++)e.setMap(null);this.polylines=[]},l.prototype.drawCircle=function(e){e=t({map:this.map,center:new google.maps.LatLng(e.lat,e.lng)},e),delete e.lat,delete e.lng;for(var o=new google.maps.Circle(e),n=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"],r=0;n.length>r;r++)(function(t,o){e[o]&&google.maps.event.addListener(t,o,function(t){e[o].apply(this,[t])})})(o,n[r]);return this.polygons.push(o),o},l.prototype.drawRectangle=function(e){e=t({map:this.map},e);var o=new google.maps.LatLngBounds(new google.maps.LatLng(e.bounds[0][0],e.bounds[0][1]),new google.maps.LatLng(e.bounds[1][0],e.bounds[1][1]));e.bounds=o;for(var n=new google.maps.Rectangle(e),r=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"],a=0;r.length>a;a++)(function(t,o){e[o]&&google.maps.event.addListener(t,o,function(t){e[o].apply(this,[t])})})(n,r[a]);return this.polygons.push(n),n},l.prototype.drawPolygon=function(e){var r=!1;e.hasOwnProperty("useGeoJSON")&&(r=e.useGeoJSON),delete e.useGeoJSON,e=t({map:this.map},e),0==r&&(e.paths=[e.paths.slice(0)]),e.paths.length>0&&e.paths[0].length>0&&(e.paths=n(o(e.paths,a,r)));for(var s=new google.maps.Polygon(e),i=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"],p=0;i.length>p;p++)(function(t,o){e[o]&&google.maps.event.addListener(t,o,function(t){e[o].apply(this,[t])})})(s,i[p]);return this.polygons.push(s),l.fire("polygon_added",s,this),s},l.prototype.removePolygon=function(e){for(var t=0;this.polygons.length>t;t++)if(this.polygons[t]===e){this.polygons[t].setMap(null),this.polygons.splice(t,1),l.fire("polygon_removed",e,this);break}},l.prototype.removePolygons=function(){for(var e,t=0;e=this.polygons[t];t++)e.setMap(null);this.polygons=[]},l.prototype.getFromFusionTables=function(e){var t=e.events;delete e.events;var o=e,n=new google.maps.FusionTablesLayer(o);for(var r in t)(function(e,o){google.maps.event.addListener(e,o,function(e){t[o].apply(this,[e])})})(n,r);return this.layers.push(n),n},l.prototype.loadFromFusionTables=function(e){var t=this.getFromFusionTables(e);return t.setMap(this.map),t},l.prototype.getFromKML=function(e){var t=e.url,o=e.events;delete e.url,delete e.events;var n=e,r=new google.maps.KmlLayer(t,n);for(var a in o)(function(e,t){google.maps.event.addListener(e,t,function(e){o[t].apply(this,[e])})})(r,a);return this.layers.push(r),r},l.prototype.loadFromKML=function(e){var t=this.getFromKML(e);return t.setMap(this.map),t},l.prototype.addLayer=function(e,t){t=t||{};var o;switch(e){case"weather":this.singleLayers.weather=o=new google.maps.weather.WeatherLayer;break;case"clouds":this.singleLayers.clouds=o=new google.maps.weather.CloudLayer;break;case"traffic":this.singleLayers.traffic=o=new google.maps.TrafficLayer;break;case"transit":this.singleLayers.transit=o=new google.maps.TransitLayer;break;case"bicycling":this.singleLayers.bicycling=o=new google.maps.BicyclingLayer;break;case"panoramio":this.singleLayers.panoramio=o=new google.maps.panoramio.PanoramioLayer,o.setTag(t.filter),delete t.filter,t.click&&google.maps.event.addListener(o,"click",function(e){t.click(e),delete t.click});break;case"places":if(this.singleLayers.places=o=new google.maps.places.PlacesService(this.map),t.search||t.nearbySearch||t.radarSearch){var n={bounds:t.bounds||null,keyword:t.keyword||null,location:t.location||null,name:t.name||null,radius:t.radius||null,rankBy:t.rankBy||null,types:t.types||null};t.radarSearch&&o.radarSearch(n,t.radarSearch),t.search&&o.search(n,t.search),t.nearbySearch&&o.nearbySearch(n,t.nearbySearch)}if(t.textSearch){var r={bounds:t.bounds||null,location:t.location||null,query:t.query||null,radius:t.radius||null};o.textSearch(r,t.textSearch)}}return void 0!==o?("function"==typeof o.setOptions&&o.setOptions(t),"function"==typeof o.setMap&&o.setMap(this.map),o):void 0},l.prototype.removeLayer=function(e){if("string"==typeof e&&void 0!==this.singleLayers[e])this.singleLayers[e].setMap(null),delete this.singleLayers[e];else for(var t=0;this.layers.length>t;t++)if(this.layers[t]===e){this.layers[t].setMap(null),this.layers.splice(t,1);break}};var p,g;return l.prototype.getRoutes=function(e){switch(e.travelMode){case"bicycling":p=google.maps.TravelMode.BICYCLING;break;case"transit":p=google.maps.TravelMode.TRANSIT;break;case"driving":p=google.maps.TravelMode.DRIVING;break;default:p=google.maps.TravelMode.WALKING}g="imperial"===e.unitSystem?google.maps.UnitSystem.IMPERIAL:google.maps.UnitSystem.METRIC;var o={avoidHighways:!1,avoidTolls:!1,optimizeWaypoints:!1,waypoints:[]},n=t(o,e);n.origin=/string/.test(typeof e.origin)?e.origin:new google.maps.LatLng(e.origin[0],e.origin[1]),n.destination=/string/.test(typeof e.destination)?e.destination:new google.maps.LatLng(e.destination[0],e.destination[1]),n.travelMode=p,n.unitSystem=g,delete n.callback,delete n.error;var r=this,a=new google.maps.DirectionsService;a.route(n,function(t,o){if(o===google.maps.DirectionsStatus.OK){for(var n in t.routes)t.routes.hasOwnProperty(n)&&r.routes.push(t.routes[n]);e.callback&&e.callback(r.routes)}else e.error&&e.error(t,o)})},l.prototype.removeRoutes=function(){this.routes=[]},l.prototype.getElevations=function(e){e=t({locations:[],path:!1,samples:256},e),e.locations.length>0&&e.locations[0].length>0&&(e.locations=n(o([e.locations],a,!1)));var r=e.callback;delete e.callback;var s=new google.maps.ElevationService;if(e.path){var i={path:e.locations,samples:e.samples};s.getElevationAlongPath(i,function(e,t){r&&"function"==typeof r&&r(e,t)})}else delete e.path,delete e.samples,s.getElevationForLocations(e,function(e,t){r&&"function"==typeof r&&r(e,t)})},l.prototype.cleanRoute=l.prototype.removePolylines,l.prototype.drawRoute=function(e){var t=this;this.getRoutes({origin:e.origin,destination:e.destination,travelMode:e.travelMode,waypoints:e.waypoints,unitSystem:e.unitSystem,error:e.error,callback:function(o){o.length>0&&(t.drawPolyline({path:o[o.length-1].overview_path,strokeColor:e.strokeColor,strokeOpacity:e.strokeOpacity,strokeWeight:e.strokeWeight}),e.callback&&e.callback(o[o.length-1]))}})},l.prototype.travelRoute=function(e){if(e.origin&&e.destination)this.getRoutes({origin:e.origin,destination:e.destination,travelMode:e.travelMode,waypoints:e.waypoints,unitSystem:e.unitSystem,error:e.error,callback:function(t){if(t.length>0&&e.start&&e.start(t[t.length-1]),t.length>0&&e.step){var o=t[t.length-1];if(o.legs.length>0)for(var n,r=o.legs[0].steps,a=0;n=r[a];a++)n.step_number=a,e.step(n,o.legs[0].steps.length-1)}t.length>0&&e.end&&e.end(t[t.length-1])}});else if(e.route&&e.route.legs.length>0)for(var t,o=e.route.legs[0].steps,n=0;t=o[n];n++)t.step_number=n,e.step(t)},l.prototype.drawSteppedRoute=function(e){var t=this;if(e.origin&&e.destination)this.getRoutes({origin:e.origin,destination:e.destination,travelMode:e.travelMode,waypoints:e.waypoints,error:e.error,callback:function(o){if(o.length>0&&e.start&&e.start(o[o.length-1]),o.length>0&&e.step){var n=o[o.length-1];if(n.legs.length>0)for(var r,a=n.legs[0].steps,s=0;r=a[s];s++)r.step_number=s,t.drawPolyline({path:r.path,strokeColor:e.strokeColor,strokeOpacity:e.strokeOpacity,strokeWeight:e.strokeWeight}),e.step(r,n.legs[0].steps.length-1)}o.length>0&&e.end&&e.end(o[o.length-1])}});else if(e.route&&e.route.legs.length>0)for(var o,n=e.route.legs[0].steps,r=0;o=n[r];r++)o.step_number=r,t.drawPolyline({path:o.path,strokeColor:e.strokeColor,strokeOpacity:e.strokeOpacity,strokeWeight:e.strokeWeight}),e.step(o)},l.Route=function(e){this.origin=e.origin,this.destination=e.destination,this.waypoints=e.waypoints,this.map=e.map,this.route=e.route,this.step_count=0,this.steps=this.route.legs[0].steps,this.steps_length=this.steps.length,this.polyline=this.map.drawPolyline({path:new google.maps.MVCArray,strokeColor:e.strokeColor,strokeOpacity:e.strokeOpacity,strokeWeight:e.strokeWeight}).getPath()},l.Route.prototype.getRoute=function(t){var o=this;this.map.getRoutes({origin:this.origin,destination:this.destination,travelMode:t.travelMode,waypoints:this.waypoints||[],error:t.error,callback:function(){o.route=e[0],t.callback&&t.callback.call(o)}})},l.Route.prototype.back=function(){if(this.step_count>0){this.step_count--;var e=this.route.legs[0].steps[this.step_count].path;for(var t in e)e.hasOwnProperty(t)&&this.polyline.pop()}},l.Route.prototype.forward=function(){if(this.step_count<this.steps_length){var e=this.route.legs[0].steps[this.step_count].path;for(var t in e)e.hasOwnProperty(t)&&this.polyline.push(e[t]);this.step_count++}},l.prototype.checkGeofence=function(e,t,o){return o.containsLatLng(new google.maps.LatLng(e,t))},l.prototype.checkMarkerGeofence=function(e,t){if(e.fences)for(var o,n=0;o=e.fences[n];n++){var r=e.getPosition();this.checkGeofence(r.lat(),r.lng(),o)||t(e,o)}},l.prototype.toImage=function(e){var e=e||{},t={};if(t.size=e.size||[this.el.clientWidth,this.el.clientHeight],t.lat=this.getCenter().lat(),t.lng=this.getCenter().lng(),this.markers.length>0){t.markers=[];for(var o=0;this.markers.length>o;o++)t.markers.push({lat:this.markers[o].getPosition().lat(),lng:this.markers[o].getPosition().lng()})}if(this.polylines.length>0){var n=this.polylines[0];t.polyline={},t.polyline.path=google.maps.geometry.encoding.encodePath(n.getPath()),t.polyline.strokeColor=n.strokeColor,t.polyline.strokeOpacity=n.strokeOpacity,t.polyline.strokeWeight=n.strokeWeight}return l.staticMapURL(t)},l.staticMapURL=function(e){function t(e,t){if("#"===e[0]&&(e=e.replace("#","0x"),t)){if(t=parseFloat(t),t=Math.min(1,Math.max(t,0)),0===t)return"0x00000000";t=(255*t).toString(16),1===t.length&&(t+=t),e=e.slice(0,8)+t}return e}var o,n=[],r="http://maps.googleapis.com/maps/api/staticmap";e.url&&(r=e.url,delete e.url),r+="?";var a=e.markers;delete e.markers,!a&&e.marker&&(a=[e.marker],delete e.marker);var s=e.styles;delete e.styles;var i=e.polyline;if(delete e.polyline,e.center)n.push("center="+e.center),delete e.center;else if(e.address)n.push("center="+e.address),delete e.address;else if(e.lat)n.push(["center=",e.lat,",",e.lng].join("")),delete e.lat,delete e.lng;else if(e.visible){var l=encodeURI(e.visible.join("|"));n.push("visible="+l)}var p=e.size;p?(p.join&&(p=p.join("x")),delete e.size):p="630x300",n.push("size="+p),e.zoom||e.zoom===!1||(e.zoom=15);var g=e.hasOwnProperty("sensor")?!!e.sensor:!0;delete e.sensor,n.push("sensor="+g);for(var c in e)e.hasOwnProperty(c)&&n.push(c+"="+e[c]);if(a)for(var h,d,u=0;o=a[u];u++){h=[],o.size&&"normal"!==o.size?(h.push("size:"+o.size),delete o.size):o.icon&&(h.push("icon:"+encodeURI(o.icon)),delete o.icon),o.color&&(h.push("color:"+o.color.replace("#","0x")),delete o.color),o.label&&(h.push("label:"+o.label[0].toUpperCase()),delete o.label),d=o.address?o.address:o.lat+","+o.lng,delete o.address,delete o.lat,delete o.lng;for(var c in o)o.hasOwnProperty(c)&&h.push(c+":"+o[c]);h.length||0===u?(h.push(d),h=h.join("|"),n.push("markers="+encodeURI(h))):(h=n.pop()+encodeURI("|"+d),n.push(h))}if(s)for(var u=0;s.length>u;u++){var m=[];s[u].featureType&&m.push("feature:"+s[u].featureType.toLowerCase()),s[u].elementType&&m.push("element:"+s[u].elementType.toLowerCase());for(var f=0;s[u].stylers.length>f;f++)for(var y in s[u].stylers[f]){var v=s[u].stylers[f][y];("hue"==y||"color"==y)&&(v="0x"+v.substring(1)),m.push(y+":"+v)}var k=m.join("|");""!=k&&n.push("style="+k)}if(i){if(o=i,i=[],o.strokeWeight&&i.push("weight:"+parseInt(o.strokeWeight,10)),o.strokeColor){var w=t(o.strokeColor,o.strokeOpacity);i.push("color:"+w)}if(o.fillColor){var b=t(o.fillColor,o.fillOpacity);i.push("fillcolor:"+b)}var L=o.path;if(L.join)for(var _,f=0;_=L[f];f++)i.push(_.join(","));else i.push("enc:"+L);i=i.join("|"),n.push("path="+encodeURI(i))}var M=window.devicePixelRatio||1;return n.push("scale="+M),n=n.join("&"),r+n},l.prototype.addMapType=function(e,t){if(!t.hasOwnProperty("getTileUrl")||"function"!=typeof t.getTileUrl)throw"'getTileUrl' function required.";t.tileSize=t.tileSize||new google.maps.Size(256,256);var o=new google.maps.ImageMapType(t);this.map.mapTypes.set(e,o)},l.prototype.addOverlayMapType=function(e){if(!e.hasOwnProperty("getTile")||"function"!=typeof e.getTile)throw"'getTile' function required.";var t=e.index;delete e.index,this.map.overlayMapTypes.insertAt(t,e)},l.prototype.removeOverlayMapType=function(e){this.map.overlayMapTypes.removeAt(e)},l.prototype.addStyle=function(e){var t=new google.maps.StyledMapType(e.styles,{name:e.styledMapName});this.map.mapTypes.set(e.mapTypeId,t)},l.prototype.setStyle=function(e){this.map.setMapTypeId(e)},l.prototype.createPanorama=function(e){return e.hasOwnProperty("lat")&&e.hasOwnProperty("lng")||(e.lat=this.getCenter().lat(),e.lng=this.getCenter().lng()),this.panorama=l.createPanorama(e),this.map.setStreetView(this.panorama),this.panorama},l.createPanorama=function(e){var o=s(e.el,e.context);e.position=new google.maps.LatLng(e.lat,e.lng),delete e.el,delete e.context,delete e.lat,delete e.lng;for(var n=["closeclick","links_changed","pano_changed","position_changed","pov_changed","resize","visible_changed"],r=t({visible:!0},e),a=0;n.length>a;a++)delete r[n[a]];for(var i=new google.maps.StreetViewPanorama(o,r),a=0;n.length>a;a++)(function(t,o){e[o]&&google.maps.event.addListener(t,o,function(){e[o].apply(this)})})(i,n[a]);return i},l.prototype.on=function(e,t){return l.on(e,this,t)},l.prototype.off=function(e){l.off(e,this)},l.custom_events=["marker_added","marker_removed","polyline_added","polyline_removed","polygon_added","polygon_removed","geolocated","geolocation_failed"],l.on=function(e,t,o){if(-1==l.custom_events.indexOf(e))return t instanceof l&&(t=t.map),google.maps.event.addListener(t,e,o);var n={handler:o,eventName:e};return t.registered_events[e]=t.registered_events[e]||[],t.registered_events[e].push(n),n},l.off=function(e,t){-1==l.custom_events.indexOf(e)?(t instanceof l&&(t=t.map),google.maps.event.clearListeners(t,e)):t.registered_events[e]=[]},l.fire=function(e,t,o){if(-1==l.custom_events.indexOf(e))google.maps.event.trigger(t,e,Array.prototype.slice.apply(arguments).slice(2));else if(e in o.registered_events)for(var n=o.registered_events[e],r=0;n.length>r;r++)(function(e,t,o){e.apply(t,[o])})(n[r].handler,o,t)},l.geolocate=function(e){var t=e.always||e.complete;navigator.geolocation?navigator.geolocation.getCurrentPosition(function(o){e.success(o),t&&t()},function(o){e.error(o),t&&t()},e.options):(e.not_supported(),t&&t())},l.geocode=function(e){this.geocoder=new google.maps.Geocoder;var t=e.callback;e.hasOwnProperty("lat")&&e.hasOwnProperty("lng")&&(e.latLng=new google.maps.LatLng(e.lat,e.lng)),delete e.lat,delete e.lng,delete e.callback,this.geocoder.geocode(e,function(e,o){t(e,o)})},google.maps.Polygon.prototype.getBounds||(google.maps.Polygon.prototype.getBounds=function(){for(var e,t=new google.maps.LatLngBounds,o=this.getPaths(),n=0;o.getLength()>n;n++){e=o.getAt(n);for(var r=0;e.getLength()>r;r++)t.extend(e.getAt(r))}return t}),google.maps.Polygon.prototype.containsLatLng||(google.maps.Polygon.prototype.containsLatLng=function(e){var t=this.getBounds();if(null!==t&&!t.contains(e))return!1;for(var o=!1,n=this.getPaths().getLength(),r=0;n>r;r++)for(var a=this.getPaths().getAt(r),s=a.getLength(),i=s-1,l=0;s>l;l++){var p=a.getAt(l),g=a.getAt(i);(p.lng()<e.lng()&&g.lng()>=e.lng()||g.lng()<e.lng()&&p.lng()>=e.lng())&&p.lat()+(e.lng()-p.lng())/(g.lng()-p.lng())*(g.lat()-p.lat())<e.lat()&&(o=!o),i=l}return o}),google.maps.LatLngBounds.prototype.containsLatLng=function(e){return this.contains(e)},google.maps.Marker.prototype.setFences=function(e){this.fences=e},google.maps.Marker.prototype.addFence=function(e){this.fences.push(e)},google.maps.Marker.prototype.getId=function(){return this.__gm_id},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){"use strict";if(null==this)throw new TypeError;var t=Object(this),o=t.length>>>0;if(0===o)return-1;var n=0;if(arguments.length>1&&(n=Number(arguments[1]),n!=n?n=0:0!=n&&1/0!=n&&n!=-1/0&&(n=(n>0||-1)*Math.floor(Math.abs(n)))),n>=o)return-1;for(var r=n>=0?n:Math.max(o-Math.abs(n),0);o>r;r++)if(r in t&&t[r]===e)return r;return-1}),l}),function(e){var t=function(e,t,o,n){this.base_url="https://maps.google.com/maps?",this.display(e,t,o,n)};t.prototype.display=function(t,o,n,r){e(t).show();var a=e(t).data("breakpoint");if(a>640&&(a=640),e("html").width()>a){var s=new GMaps({div:t,lat:o.lat(),lng:o.lng(),mapTypeControl:!1,zoom:parseFloat(n),streetViewControl:!1,scrollwheel:!1,mapTypeId:google.maps.MapTypeId.ROADMAP});if(r.length){var i=s.addMarker({lat:o.lat(),lng:o.lng(),infoWindow:{content:r}});"open"==e(t).data("infowindow")&&i.infoWindow.open(s,i)}else s.addMarker({lat:o.lat(),lng:o.lng()})}else{var l=GMaps.staticMapURL({center:o.lat()+","+o.lng(),zoom:n,size:a+"x"+e(t).height(),markers:[{lat:o.lat(),lng:o.lng()}],sensor:"false"}),p=e("<img />");e(p).attr("src",l),e(p).attr("alt",e(t).text());var g=e("<a />");e(g).attr("href",this.base_url+"q="+o.lat()+","+o.lng()+"&z="+n),e(g).html(p),e(t).html(g),e(t).addClass("staticmap")}},e(".simplemap").each(function(){var o=e("div",this).get(0),n=16;if(parseFloat(e(o).data("zoom"))&&(n=e(o).data("zoom")),e(o).data("lat")&&e(o).data("lng")){var r=e(o).data("lat"),a=e(o).data("lng"),s=e(o).html(),i=new google.maps.LatLng(r,a);new t(o,i,n,s)}else e(o).data("addr")?GMaps.geocode({address:e(o).data("addr"),callback:function(r,a){if("OK"==a){var s=r[0].geometry.location;new t(o,s,n,e(o).html())}}}):e(o).text().length&&GMaps.geocode({address:e(o).text(),callback:function(r,a){if("OK"==a){var s=r[0].geometry.location;new t(o,s,n,e(o).text())}}})})}(jQuery);
package.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "simple-map",
3
+ "title": "Simple Map",
4
+ "license" : "GPLv2",
5
+ "description": "Easy way to embed google map(s) using gmaps.js.",
6
+ "version": "1.3.0",
7
+ "homepage": "http://wordpress.org/plugins/simple-map/",
8
+ "repository" : {
9
+ "type" : "git",
10
+ "url" : "https://github.com/miya0001/simple-map"
11
+ },
12
+ "author": {
13
+ "name": "Takayuki Miyauchi",
14
+ "url": "http://wpist.me/"
15
+ },
16
+ "dependencies": {
17
+ "gmaps": "git+ssh://git@github.com:HPNeo/gmaps.git#0.4.14"
18
+ },
19
+ "devDependencies": {
20
+ "grunt": "~0.4.1",
21
+ "grunt-contrib-uglify": "~0.1.1"
22
+ },
23
+ "keywords": []
24
+ }
readme.txt ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Simple Map ===
2
+ Contributors: miyauchi
3
+ Donate link: http://wpist.me/
4
+ Tags: widget
5
+ Requires at least: 3.3
6
+ Tested up to: 4.0
7
+ Stable tag: 2.0
8
+
9
+ Easy way to embed google map(s).
10
+
11
+ == Description ==
12
+
13
+ Easy way to embed google map(s) using [gmaps.js](http://hpneo.github.com/gmaps/).
14
+
15
+ This plugin allows you to convert address into google maps like below:
16
+
17
+ `[map]San Francisco, California[/map]`
18
+
19
+ Another way, you can embed Google Map with url only like oEmbed.
20
+
21
+
22
+ You can also use coordinates, set width, height and zoom:
23
+
24
+ `[map lat="37.77493" lng="-122.41942"]
25
+ Text you would
26
+ like to appear
27
+ as a tooltip
28
+ goes here
29
+ [/map]`
30
+
31
+ In this case there will be a marker on the map with a tooltip appearing on click on said marker.
32
+ You can use simple html as the tooltip content.
33
+
34
+
35
+ [This plugin maintained on GitHub.](https://github.com/miya0001/simple-map)
36
+
37
+ = Some features: =
38
+
39
+ * Allow you to embed google map based on shortcode.
40
+ * Markers can be added using address or lat/long.
41
+ * Display static map for iPhone automatically.
42
+ * oEmbed Support.
43
+
44
+ = Arguments =
45
+
46
+ * width: Width of the map. Default value is "100%".
47
+ * height: Height of the map. Default value is "200px".
48
+ * zoom: Zoom of the map. Default value is "16".
49
+ * breakpoint: If display is narrower than this value, this plugin will display static map. Default value is "480".
50
+ * addr: Address of the map you want to place.
51
+ * lat: Lat of the map you want to place.
52
+ * lng: Lng of the map you want to place.
53
+ * infowindow: If you want to open infoWindow by Default, please set "open".
54
+
55
+ If you will set lat/lng and address, this plugin give priority to lat/lng.
56
+
57
+ = Filter Hooks =
58
+
59
+ This plugin has some filter hooks for customize default.
60
+
61
+ * simplemap_default_width
62
+ * simplemap_default_height
63
+ * simplemap_default_zoom
64
+ * simplemap_default_breakpoint
65
+ * simplemap_default_infowindow
66
+
67
+ `add_filter( 'simplemap_default_zoom', function(){
68
+ return 10; // Default zoom is 10
69
+ } );`
70
+
71
+ = Translators =
72
+
73
+ * Japanese(ja) - [Takayuki Miyauchi](http://firegoby.jp/)
74
+
75
+ Please contact to me.
76
+
77
+ * https://github.com/miya0001/simple-map/issues
78
+
79
+ = Contributors =
80
+
81
+ * [Takayuki Miyauchi](http://firegoby.jp/)
82
+ * [Zoltán Balogh](http://birdcreation.com/)
83
+ * [Takanobu Watanabe](https://github.com/tknv)
84
+ * [Shinichi Nishikawa](http://th-daily.shinichi.me/)
85
+
86
+ == Installation ==
87
+
88
+ * Download the zip, extract it and upload the extracted folder to your-wp-directory/wp-content/plugins/
89
+ * Go to the plugins administration screen in your WordPress admin and activate the plugin.
90
+
91
+ OR
92
+
93
+ * Download the zip, go to the plugins administration screen in your WordPress admin, click on Add New then on upload, browse to the downloaded zip, upload the plugin and activate it.
94
+
95
+ OR
96
+
97
+ * Go to the plugins administration screen in your WordPress admin, click on Add New, search for Simple Map and click on Install Now.
98
+
99
+ *Usage*
100
+
101
+ This plugin allows you to convert address into google maps like below:
102
+
103
+ `[map]San Francisco, California[/map]`
104
+
105
+ Another way, you can embed Google Map with url only like oEmbed.
106
+
107
+ You can also use coordinates, set width, height and zoom:
108
+
109
+ `[map lat="37.77493" lng="-122.41942" width="100%" height="400px" zoom="15"]
110
+ Text you would
111
+ like to appear
112
+ as a tooltip
113
+ goes here
114
+ [/map]`
115
+
116
+ In this case there will be a marker on the map with a tooltip appearing on click on said marker.
117
+ You can use simple html as the tooltip content.
118
+
119
+ == Screenshots ==
120
+
121
+ 1. Very easy.
122
+ 2. Info Window.
123
+ 3. Mobile Support. (Google static map)
124
+
125
+ == Changelog ==
126
+
127
+ = 2.0.0 =
128
+ * Add argument infowindow
129
+ * little fix
130
+
131
+ = 1.9.0 =
132
+ * update gmaps.js 0.4.13 to 0.4.14
133
+
134
+ = 1.8.0 =
135
+ * update gmaps.js 0.4.12 to 0.4.13
136
+
137
+ = 1.7.0 =
138
+ * update gmaps.js 0.4.11 to 0.4.12
139
+
140
+ = 1.6.0 =
141
+ * update gmaps.js 0.4.9 to 0.4.11
142
+
143
+ = 1.5.0 =
144
+ * enable ssl source of google map api js
145
+
146
+ = 1.4.0 =
147
+ * change URL match pattern.
148
+
149
+ = 1.3.0 =
150
+ * Update gmaps.js to 0.4.9.
151
+
152
+ = 1.2.0 =
153
+ * Tested on the WordPress 3.8.
154
+ * Add Grunt.
155
+
156
+ = 1.1.0 =
157
+ * Added support for gmaps.js tooltip on markers
158
+
159
+ = 1.0.0 =
160
+ * Delete hl=ja param from static map link uri.
161
+
162
+ = 0.9.0 =
163
+ * hook changed to the init.
164
+
165
+ = 0.8.0 =
166
+ * shortcode atts and address priority changed.
167
+
168
+ = 0.7.0 =
169
+ * gmaps.js updated 0.4.4 to 0.4.5
170
+
171
+ = 0.6.0 =
172
+ * oEmbed Support
173
+
174
+ = 0.1.0 =
175
+ * The first release.
176
+
177
+ == Credits ==
178
+
179
+ This plug-in is not guaranteed though the user of WordPress can freely use this plug-in free of charge regardless of the purpose.
180
+ The author must acknowledge the thing that the operation guarantee and the support in this plug-in use are not done at all beforehand.
181
+
182
+ == Contact ==
183
+
184
+ twitter @miya0001
simple-map.php ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Simple Map
4
+ Author: Takayuki Miyauchi
5
+ Plugin URI: https://github.com/miya0001/simple-map
6
+ Description: Insert google map convert from address.
7
+ Version: 2.0.0
8
+ Author URI: http://wpist.me/
9
+ Domain Path: /languages
10
+ Text Domain: simplemap
11
+ */
12
+
13
+ $simplemap = new Simple_Map();
14
+
15
+ class Simple_Map {
16
+
17
+ private $shortcode_tag = 'map';
18
+ private $class_name = 'simplemap';
19
+ private $width = '100%';
20
+ private $height = '200px';
21
+ private $zoom = 16;
22
+ private $breakpoint = 480;
23
+ private $max_breakpoint = 640;
24
+
25
+ function __construct()
26
+ {
27
+ add_action( 'init', array( $this, 'init' ) );
28
+ }
29
+
30
+ public function init()
31
+ {
32
+ add_action( 'wp_head', array( $this, 'wp_head' ) );
33
+ add_shortcode( $this->get_shortcode_tag(), array( $this, 'shortcode' ) );
34
+
35
+ wp_embed_register_handler(
36
+ 'google-map',
37
+ '#( https://( www|maps ).google.[a-z]{2,3}\.?[a-z]{0,3}/maps( /ms )?\?.+ )#i',
38
+ array( &$this, 'oembed_handler' )
39
+ );
40
+ }
41
+
42
+ public function oembed_handler( $match )
43
+ {
44
+ return sprintf(
45
+ '[%s url="%s"]',
46
+ $this->get_shortcode_tag(),
47
+ esc_url( $match[0] )
48
+ );
49
+ }
50
+
51
+ public function wp_head()
52
+ {
53
+ echo "<style>.simplemap img{max-width:none !important;padding:0 !important;margin:0 !important;}.staticmap,.staticmap img{max-width:100% !important;height:auto !important;}.simplemap .simplemap-content{display:none;}</style>\n";
54
+ }
55
+
56
+ public function wp_enqueue_scripts()
57
+ {
58
+ wp_register_script(
59
+ 'google-maps-api',
60
+ '//maps.google.com/maps/api/js?sensor=false',
61
+ false,
62
+ null,
63
+ true
64
+ );
65
+
66
+ wp_register_script(
67
+ 'simplemap',
68
+ apply_filters(
69
+ 'simplemap_script',
70
+ plugins_url( 'js/simple-map.min.js' , __FILE__ )
71
+ ),
72
+ array( 'jquery', 'google-maps-api' ),
73
+ filemtime( dirname( __FILE__ ).'/js/simple-map.min.js' ),
74
+ true
75
+ );
76
+ wp_enqueue_script( 'simplemap' );
77
+ }
78
+
79
+ public function shortcode( $p, $content = null )
80
+ {
81
+ add_action( 'wp_footer', array( &$this, 'wp_enqueue_scripts' ) );
82
+
83
+ if ( isset( $p['width'] ) && preg_match( '/^[0-9]+(%|px)$/', $p['width'] ) ) {
84
+ $w = $p['width'];
85
+ } else {
86
+ $w = apply_filters( 'simplemap_default_width', $this->width );
87
+ }
88
+ if ( isset( $p['height'] ) && preg_match( '/^[0-9]+(%|px)$/', $p['height'] ) ) {
89
+ $h = $p['height'];
90
+ } else {
91
+ $h = apply_filters( 'simplemap_default_height', $this->height );
92
+ }
93
+ if ( isset( $p['zoom'] ) && intval( $p['zoom'] ) ) {
94
+ $zoom = $p['zoom'];
95
+ } else {
96
+ $zoom = apply_filters( 'simplemap_default_zoom', $this->zoom );
97
+ }
98
+ if ( isset( $p['breakpoint'] ) && intval( $p['breakpoint'] ) ) {
99
+ if ( intval( $p['breakpoint'] ) > $this->max_breakpoint ) {
100
+ $breakpoint = $this->max_breakpoint;
101
+ } else {
102
+ $breakpoint = intval( $p['breakpoint'] );
103
+ }
104
+ } else {
105
+ $breakpoint = apply_filters(
106
+ 'simplemap_default_breakpoint',
107
+ $this->breakpoint
108
+ );
109
+ }
110
+ if ( $content ) {
111
+ $content = do_shortcode( $content );
112
+ }
113
+ if ( isset( $p['infowindow'] ) && $p['infowindow'] ) {
114
+ $infowindow = $p['infowindow'];
115
+ } else {
116
+ $infowindow = apply_filters( 'simplemap_default_infowindow', 'close' );
117
+ }
118
+
119
+ $addr = '';
120
+ $lat = '';
121
+ $lng = '';
122
+
123
+ if ( isset( $p['url'] ) && $p['url'] ) {
124
+ $iframe = '<iframe width="%s" height="%s" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="%s"></iframe>';
125
+
126
+ return sprintf(
127
+ $iframe,
128
+ $w,
129
+ $h,
130
+ esc_url( $p['url'].'&output=embed' )
131
+ );
132
+ } elseif ( isset( $p['lat'] ) && preg_match( '/^\-?[0-9\.]+$/', $p['lat'] )
133
+ && isset( $p['lng'] ) && preg_match( '/^\-?[0-9\.]+$/', $p['lng'] ) ){
134
+ $lat = $p['lat'];
135
+ $lng = $p['lng'];
136
+ } elseif ( isset( $p['addr'] ) && $p['addr'] ) {
137
+ if ( $content ) {
138
+ $addr = esc_html( $p['addr'] );
139
+ } else {
140
+ $content = esc_html( $p['addr'] );
141
+ }
142
+ } elseif ( ! $content ) {
143
+ return;
144
+ }
145
+ return sprintf(
146
+ '<div class="%1$s"><div class="%1$s-content" data-breakpoint="%2$s" data-lat="%3$s" data-lng="%4$s" data-zoom="%5$s" data-addr="%6$s" data-infowindow="%7$s" style="width:%8$s;height:%9$s;">%10$s</div></div>',
147
+ apply_filters( 'simplemap_class_name', $this->class_name ),
148
+ $breakpoint,
149
+ $lat,
150
+ $lng,
151
+ $zoom,
152
+ $addr,
153
+ $infowindow,
154
+ $w,
155
+ $h,
156
+ trim( $content )
157
+ );
158
+ }
159
+
160
+ private function get_shortcode_tag()
161
+ {
162
+ return apply_filters( 'simplemap_shortcode_tag', $this->shortcode_tag );
163
+ }
164
+
165
+ } // end class
166
+
167
+
168
+ // EOF