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