"use strict";(function(root,factory){if(typeof exports==='object'){module.exports=factory();} else if(typeof define==='function'&&define.amd){define(['jquery','googlemaps!'],factory);} else{root.GMaps=factory();}}(this,function(){/*! * GMaps.js v0.4.24 * http://hpneo.github.com/gmaps/ * * Copyright 2016, Gustavo Leon * Released under the MIT License. */var extend_object=function(obj,new_obj){var name;if(obj===new_obj){return obj;} for(name in new_obj){if(new_obj[name]!==undefined){obj[name]=new_obj[name];}} return obj;};var replace_object=function(obj,replace){var name;if(obj===replace){return obj;} for(name in replace){if(obj[name]!=undefined){obj[name]=replace[name];}} return obj;};var array_map=function(array,callback){var original_callback_params=Array.prototype.slice.call(arguments,2),array_return=[],array_length=array.length,i;if(Array.prototype.map&&array.map===Array.prototype.map){array_return=Array.prototype.map.call(array,function(item){var callback_params=original_callback_params.slice(0);callback_params.splice(0,0,item);return callback.apply(this,callback_params);});} else{for(i=0;i0&&typeof(coords[i][0])==="object"){coords[i]=arrayToLatLng(coords[i],useGeoJSON);} else{coords[i]=coordsToLatLngs(coords[i],useGeoJSON);}}} return coords;};var getElementsByClassName=function(class_name,context){var element,_class=class_name.replace('.','');if('jQuery'in this&&context){element=$("."+_class,context)[0];}else{element=document.getElementsByClassName(_class)[0];} return element;};var getElementById=function(id,context){var element,id=id.replace('#','');if('jQuery'in window&&context){element=$('#'+id,context)[0];}else{element=document.getElementById(id);};return element;};var findAbsolutePosition=function(obj){var curleft=0,curtop=0;if(obj.offsetParent){do{curleft+=obj.offsetLeft;curtop+=obj.offsetTop;}while(obj=obj.offsetParent);} return[curleft,curtop];};var GMaps=(function(global){"use strict";var doc=document;var GMaps=function(options){if(!(typeof window.google==='object'&&window.google.maps)){if(typeof window.console==='object'&&window.console.error){console.error('Google Maps API is required. Please register the following JavaScript library https://maps.googleapis.com/maps/api/js.');} return function(){};} if(!this)return new GMaps(options);options.zoom=options.zoom||15;options.mapType=options.mapType||'roadmap';var valueOrDefault=function(value,defaultValue){return value===undefined?defaultValue:value;};var self=this,i,events_that_hide_context_menu=['bounds_changed','center_changed','click','dblclick','drag','dragend','dragstart','idle','maptypeid_changed','projection_changed','resize','tilesloaded','zoom_changed'],events_that_doesnt_hide_context_menu=['mousemove','mouseout','mouseover'],options_to_be_deleted=['el','lat','lng','mapType','width','height','markerClusterer','enableNewStyle'],identifier=options.el||options.div,markerClustererFunction=options.markerClusterer,mapType=google.maps.MapTypeId[options.mapType.toUpperCase()],map_center=new google.maps.LatLng(options.lat,options.lng),zoomControl=valueOrDefault(options.zoomControl,true),zoomControlOpt=options.zoomControlOpt||{style:'DEFAULT',position:'TOP_LEFT'},zoomControlStyle=zoomControlOpt.style||'DEFAULT',zoomControlPosition=zoomControlOpt.position||'TOP_LEFT',panControl=valueOrDefault(options.panControl,true),mapTypeControl=valueOrDefault(options.mapTypeControl,true),scaleControl=valueOrDefault(options.scaleControl,true),streetViewControl=valueOrDefault(options.streetViewControl,true),overviewMapControl=valueOrDefault(overviewMapControl,true),map_options={},map_base_options={zoom:this.zoom,center:map_center,mapTypeId:mapType},map_controls_options={panControl:panControl,zoomControl:zoomControl,zoomControlOptions:{style:google.maps.ZoomControlStyle[zoomControlStyle],position:google.maps.ControlPosition[zoomControlPosition]},mapTypeControl:mapTypeControl,scaleControl:scaleControl,streetViewControl:streetViewControl,overviewMapControl:overviewMapControl};if(typeof(options.el)==='string'||typeof(options.div)==='string'){if(identifier.indexOf("#")>-1){this.el=getElementById(identifier,options.context);}else{this.el=getElementsByClassName.apply(this,[identifier,options.context]);}}else{this.el=identifier;} if(typeof(this.el)==='undefined'||this.el===null){throw 'No element defined.';} window.context_menu=window.context_menu||{};window.context_menu[self.el.id]={};this.controls=[];this.overlays=[];this.layers=[];this.singleLayers={};this.markers=[];this.polylines=[];this.routes=[];this.polygons=[];this.infoWindow=null;this.overlay_el=null;this.zoom=options.zoom;this.registered_events={};this.el.style.width=options.width||this.el.scrollWidth||this.el.offsetWidth;this.el.style.height=options.height||this.el.scrollHeight||this.el.offsetHeight;google.maps.visualRefresh=options.enableNewStyle;for(i=0;i'+option.title+'';}} if(!getElementById('gmaps_context_menu'))return;var context_menu_element=getElementById('gmaps_context_menu');context_menu_element.innerHTML=html;var context_menu_items=context_menu_element.getElementsByTagName('a'),context_menu_items_count=context_menu_items.length,i;for(i=0;i-1){var marker=this.markers[index];marker.setMap(null);if(this.markerClusterer){this.markerClusterer.removeMarker(marker);} GMaps.fire('marker_removed',marker,this);}} for(var i=0;i0){if(options.paths[0].length>0){options.paths=array_flat(array_map(options.paths,arrayToLatLng,useGeoJSON));}} var polygon=new google.maps.Polygon(options),polygon_events=['click','dblclick','mousedown','mousemove','mouseout','mouseover','mouseup','rightclick'];for(var ev=0;ev0){if(options.locations[0].length>0){options.locations=array_flat(array_map([options.locations],arrayToLatLng,false));}} var callback=options.callback;delete options.callback;var service=new google.maps.ElevationService();if(!options.path){delete options.path;delete options.samples;service.getElevationForLocations(options,function(result,status){if(callback&&typeof(callback)==="function"){callback(result,status);}});}else{var pathRequest={path:options.locations,samples:options.samples};service.getElevationAlongPath(pathRequest,function(result,status){if(callback&&typeof(callback)==="function"){callback(result,status);}});}};GMaps.prototype.cleanRoute=GMaps.prototype.removePolylines;GMaps.prototype.renderRoute=function(options,renderOptions){var self=this,panel=((typeof renderOptions.panel==='string')?document.getElementById(renderOptions.panel.replace('#','')):renderOptions.panel),display;renderOptions.panel=panel;renderOptions=extend_object({map:this.map},renderOptions);display=new google.maps.DirectionsRenderer(renderOptions);this.getRoutes({origin:options.origin,destination:options.destination,travelMode:options.travelMode,waypoints:options.waypoints,unitSystem:options.unitSystem,error:options.error,avoidHighways:options.avoidHighways,avoidTolls:options.avoidTolls,optimizeWaypoints:options.optimizeWaypoints,callback:function(routes,response,status){if(status===google.maps.DirectionsStatus.OK){display.setDirections(response);}}});};GMaps.prototype.drawRoute=function(options){var self=this;this.getRoutes({origin:options.origin,destination:options.destination,travelMode:options.travelMode,waypoints:options.waypoints,unitSystem:options.unitSystem,error:options.error,avoidHighways:options.avoidHighways,avoidTolls:options.avoidTolls,optimizeWaypoints:options.optimizeWaypoints,callback:function(routes){if(routes.length>0){var polyline_options={path:routes[routes.length-1].overview_path,strokeColor:options.strokeColor,strokeOpacity:options.strokeOpacity,strokeWeight:options.strokeWeight};if(options.hasOwnProperty("icons")){polyline_options.icons=options.icons;} self.drawPolyline(polyline_options);if(options.callback){options.callback(routes[routes.length-1]);}}}});};GMaps.prototype.travelRoute=function(options){if(options.origin&&options.destination){this.getRoutes({origin:options.origin,destination:options.destination,travelMode:options.travelMode,waypoints:options.waypoints,unitSystem:options.unitSystem,error:options.error,callback:function(e){if(e.length>0&&options.start){options.start(e[e.length-1]);} if(e.length>0&&options.step){var route=e[e.length-1];if(route.legs.length>0){var steps=route.legs[0].steps;for(var i=0,step;step=steps[i];i++){step.step_number=i;options.step(step,(route.legs[0].steps.length-1));}}} if(e.length>0&&options.end){options.end(e[e.length-1]);}}});} else if(options.route){if(options.route.legs.length>0){var steps=options.route.legs[0].steps;for(var i=0,step;step=steps[i];i++){step.step_number=i;options.step(step);}}}};GMaps.prototype.drawSteppedRoute=function(options){var self=this;if(options.origin&&options.destination){this.getRoutes({origin:options.origin,destination:options.destination,travelMode:options.travelMode,waypoints:options.waypoints,error:options.error,callback:function(e){if(e.length>0&&options.start){options.start(e[e.length-1]);} if(e.length>0&&options.step){var route=e[e.length-1];if(route.legs.length>0){var steps=route.legs[0].steps;for(var i=0,step;step=steps[i];i++){step.step_number=i;var polyline_options={path:step.path,strokeColor:options.strokeColor,strokeOpacity:options.strokeOpacity,strokeWeight:options.strokeWeight};if(options.hasOwnProperty("icons")){polyline_options.icons=options.icons;} self.drawPolyline(polyline_options);options.step(step,(route.legs[0].steps.length-1));}}} if(e.length>0&&options.end){options.end(e[e.length-1]);}}});} else if(options.route){if(options.route.legs.length>0){var steps=options.route.legs[0].steps;for(var i=0,step;step=steps[i];i++){step.step_number=i;var polyline_options={path:step.path,strokeColor:options.strokeColor,strokeOpacity:options.strokeOpacity,strokeWeight:options.strokeWeight};if(options.hasOwnProperty("icons")){polyline_options.icons=options.icons;} self.drawPolyline(polyline_options);options.step(step);}}}};GMaps.Route=function(options){this.origin=options.origin;this.destination=options.destination;this.waypoints=options.waypoints;this.map=options.map;this.route=options.route;this.step_count=0;this.steps=this.route.legs[0].steps;this.steps_length=this.steps.length;var polyline_options={path:new google.maps.MVCArray(),strokeColor:options.strokeColor,strokeOpacity:options.strokeOpacity,strokeWeight:options.strokeWeight};if(options.hasOwnProperty("icons")){polyline_options.icons=options.icons;} this.polyline=this.map.drawPolyline(polyline_options).getPath();};GMaps.Route.prototype.getRoute=function(options){var self=this;this.map.getRoutes({origin:this.origin,destination:this.destination,travelMode:options.travelMode,waypoints:this.waypoints||[],error:options.error,callback:function(){self.route=e[0];if(options.callback){options.callback.call(self);}}});};GMaps.Route.prototype.back=function(){if(this.step_count>0){this.step_count--;var path=this.route.legs[0].steps[this.step_count].path;for(var p in path){if(path.hasOwnProperty(p)){this.polyline.pop();}}}};GMaps.Route.prototype.forward=function(){if(this.step_count0){static_map_options['markers']=[];for(var i=0;i0){var polyline=this.polylines[0];static_map_options['polyline']={};static_map_options['polyline']['path']=google.maps.geometry.encoding.encodePath(polyline.getPath());static_map_options['polyline']['strokeColor']=polyline.strokeColor static_map_options['polyline']['strokeOpacity']=polyline.strokeOpacity static_map_options['polyline']['strokeWeight']=polyline.strokeWeight} return GMaps.staticMapURL(static_map_options);};GMaps.staticMapURL=function(options){var parameters=[],data,static_root=(location.protocol==='file:'?'http:':location.protocol)+'//maps.googleapis.com/maps/api/staticmap';if(options.url){static_root=options.url;delete options.url;} static_root+='?';var markers=options.markers;delete options.markers;if(!markers&&options.marker){markers=[options.marker];delete options.marker;} var styles=options.styles;delete options.styles;var polyline=options.polyline;delete options.polyline;if(options.center){parameters.push('center='+options.center);delete options.center;} else if(options.address){parameters.push('center='+options.address);delete options.address;} else if(options.lat){parameters.push(['center=',options.lat,',',options.lng].join(''));delete options.lat;delete options.lng;} else if(options.visible){var visible=encodeURI(options.visible.join('|'));parameters.push('visible='+visible);} var size=options.size;if(size){if(size.join){size=size.join('x');} delete options.size;} else{size='630x300';} parameters.push('size='+size);if(!options.zoom&&options.zoom!==false){options.zoom=15;} var sensor=options.hasOwnProperty('sensor')?!!options.sensor:true;delete options.sensor;parameters.push('sensor='+sensor);for(var param in options){if(options.hasOwnProperty(param)){parameters.push(param+'='+options[param]);}} if(markers){var marker,loc;for(var i=0;data=markers[i];i++){marker=[];if(data.size&&data.size!=='normal'){marker.push('size:'+data.size);delete data.size;} else if(data.icon){marker.push('icon:'+encodeURI(data.icon));delete data.icon;} if(data.color){marker.push('color:'+data.color.replace('#','0x'));delete data.color;} if(data.label){marker.push('label:'+data.label[0].toUpperCase());delete data.label;} loc=(data.address?data.address:data.lat+','+data.lng);delete data.address;delete data.lat;delete data.lng;for(var param in data){if(data.hasOwnProperty(param)){marker.push(param+':'+data[param]);}} if(marker.length||i===0){marker.push(loc);marker=marker.join('|');parameters.push('markers='+encodeURI(marker));} else{marker=parameters.pop()+encodeURI('|'+loc);parameters.push(marker);}}} if(styles){for(var i=0;i=latLng.lng()||vertex2.lng()=latLng.lng()){if(vertex1.lat()+(latLng.lng()-vertex1.lng())/(vertex2.lng()-vertex1.lng())*(vertex2.lat()-vertex1.lat())>>0;if(len===0){return-1;} var n=0;if(arguments.length>1){n=Number(arguments[1]);if(n!=n){n=0;}else if(n!=0&&n!=Infinity&&n!=-Infinity){n=(n>0||-1)*Math.floor(Math.abs(n));}} if(n>=len){return-1;} var k=n>=0?n:Math.max(len-Math.abs(n),0);for(;k