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