Tesla.Map={};Tesla.Map.MapTypes={Street:G_NORMAL_MAP,Satellite:G_SATELLITE_MAP,Hybrid:G_HYBRID_MAP};Tesla.Map.MapControl=function(k){var e=true,o="dblclick",n="Local não encontrado",c=null,a=this,f=Tesla.Map,b=new GMap2(document.getElementById(k)),i=[],j=[],r=k.tagName&&k.tagName.toLowerCase()=="div"?k:document.getElementById(k),d=a,q=c,l=c,g=c,h={};h[G_GEO_UNKNOWN_ADDRESS]=n;h[G_GEO_MISSING_QUERY]=n;h[G_GEO_BAD_REQUEST]=n;h[G_GEO_BAD_KEY]="Chave de API incorreta";h[G_GEO_SERVER_ERROR]="Erro no servidor de mapas do Google";var s=new GStreetviewPanorama(r),p=c;GEvent.addListener(b,"moveend",function(){d.OnMove&&!l&&d.OnMove(d.GetCenter());l=c});GEvent.addListener(b,"click",function(a,b){!a&&d.OnClick&&d.OnClick(f.Point.FromApiObject(b))});GEvent.addListener(b,"singlerightclick",function(){d.OnRightClick&&d.OnRightClick(d.GetPointFromPixel(Tesla.Map.Point.FromApiObject(arguments[0])),Tesla.Map.Point.FromApiObject(arguments[0]))});GEvent.addListener(b,o,function(b,a){d.OnDoubleClick&&d.OnDoubleClick(f.Point.FromApiObject(a))});Tesla.Map.CurrentMap=a;function m(d,a,c){markerEvent="On"+c;mapEvent="OnMarker"+c;a["__"+markerEvent]&&a["__"+markerEvent]();var b;if(a[markerEvent])b=a[markerEvent]();(b===undefined||b)&&d[mapEvent]&&d[mapEvent](a)}function t(b){var a=57.2958,i=r,h=Math.min(i.offsetWidth,i.offsetHeight-60),c=0,e=0,d=0,g=0,f=0;if(b.Width>b.Height){c=b.Width/2;e=b.X1;d=b.X2;g=b.CenterY-c;f=b.CenterY+c}else{c=b.Height/2;g=b.Y1;f=b.Y2;e=b.CenterX-c;d=b.CenterX+c}var j=6371*Math.acos(Math.sin(e/a)*Math.sin(d/a)+Math.cos(e/a)*Math.cos(d/a)*Math.cos(f/a-g/a));return Math.min(Math.floor(8-Math.log(1.6446*j/Math.sqrt(2*(h*h)))/Math.log(2)),15)}function u(){for(var c=g.getRoute(0),e=c.getNumSteps(),b=[],a=0;a<e;a++){var d=c.getStep(a);b[a]={};b[a].Text=d.getDescriptionHtml();b[a].Distance=d.getDistance().html;b[a].Point=Tesla.Map.Point.FromApiObject(d.getLatLng())}b.Distance=c.getDistance().html;return b}a.GetRoute=function(j,i,a,d,f){a=a||Function.Empty;if(!g)g=new GDirections(b,c);GEvent.addListener(g,"load",function(){a(u(),(f||{}).SendPolygon?g.getPolyline():c)});d&&GEvent.addListener(g,"error",function(){var a=g.getStatus().code;d(a,h[a]||"Erro desconhecido")});g.load(String.Format("from:{0} to:{1}",j,i),{locale:"pt_BR",getSteps:e,preserveViewport:(f||{}).KeepMapPosition?e:false})};a.CoreExec=function(a,d){var e=$D(b,a);e.apply(c,d)};a.SetMapType=function(a){b.setMapType(a)};a.SetCenter=function(c,d,a){l=a;b.setCenter(c.ToApiObject(),d||this.GetZoom())};a.GetCenter=function(){return f.Point.FromApiObject(b.getCenter())};a.MoveTo=function(a){b.panTo(a.ToApiObject())};a.ZoomIn=function(){this.SetZoom(this.GetZoom()+1)};a.ZoomOut=function(){this.SetZoom(this.GetZoom()-1)};a.CreateMarker=function(a){return new f.Marker(this,a,b)};a.GetMarkers=function(){return j.Clone()};a.GetMapDiv=function(){return r};a.GetPointFromPixel=function(a){return Tesla.Map.Point.FromApiObject(b.fromContainerPixelToLatLng(a.ToApiObject(e)))};a.GetPixelFromPoint=function(d){var a=b.fromLatLngToDivPixel(b.fromContainerPixelToLatLng(new GPoint(0,0),e)),c=b.fromLatLngToDivPixel(d.ToApiObject());return new f.Point(c.x-a.x,c.y-a.y)};a.GetRectangle=function(){return f.Rectangle.FromApiObject(b.getBounds())};a.toString=function(){return "{TeslaMapControl}"};a.GetZoom=function(){return b.getZoom()};a.SetZoom=function(a,c){if(!a)return;l=c;if(a.constructor==Tesla.Map.Rectangle){this.SetCenter(a.Center);a=t(a)}b.setZoom(a)};a.SetZoomInMarkers=function(){var b=j.Select("i => i.GetPoint().Latitude"),a=j.Select("i => i.GetPoint().Longitude"),e=b.Min(),c=b.Max(),f=a.Min(),d=a.Max(),g=new Tesla.Map.Point(e,f),h=new Tesla.Map.Point(c,d);this.SetZoom(new Tesla.Map.Rectangle(g,h))};a.GetGeoCode=function(c,b,a){var d=this;if(!q)q=new GClientGeocoder;q.getLocations(c,function(c){if(c.Status.code!=200)a();else b(v(c.Placemark))})};function v(b){for(var d=[],a=0;a<b.length;a++){obj={};obj.Address=b[a].address;var c=obj.Address.split(",");obj.Address=c[0];obj.District=c[1];obj.City=c[2];obj.State=c[3];obj.Point=new Tesla.Map.Point(b[a].Point.coordinates[1],b[a].Point.coordinates[0]);d.push(obj)}return d}a.AddMarker=function(a){var d=this;if(!d.GetCenter()){throw"Não é possível adicionar um marker em um mapa sem centralização definida.";return}if(a!=c&&a instanceof f.Marker&&!a.ApiObject){var e=d;a.Index=j.Add(a);var g;a.ApiObject=new GMarker(a.GetPoint().ToApiObject(),a.GetApiOptions());GEvent.addListener(a.ApiObject,"click",function(){m(e,a,"Click")});GEvent.addListener(a.ApiObject,o,function(){m(e,a,"DoubleClick")});GEvent.addListener(a.ApiObject,"mouseover",function(){m(e,a,"MouseOver")});GEvent.addListener(a.ApiObject,"mouseout",function(){m(e,a,"MouseOut")});b.addOverlay(a.ApiObject);d.OnMarkerAdded&&d.OnMarkerAdded(a)}};a.RemoveMarker=function(a){if(a!=c&&a instanceof f.Marker&&a.ApiObject){j.Remove(a);b.removeOverlay(a.ApiObject);a.ApiObject=c;this.OnMarkerRemoved&&this.OnMarkerRemoved(a)}};a.ClearMarkers=function(){j=[];b.clearOverlays();this.OnClearMarkers&&this.OnClearMarkers()};a.EnableToolPanel=function(){if(!this.IsToolPanelEnabled()){b.addControl(i[0]=new GSmallMapControl);b.addControl(i[1]=new GMapTypeControl)}};a.DisableToolPanel=function(){if(this.IsToolPanelEnabled()){b.removeControl(i[0]);b.removeControl(i[1])}i=[]};a.IsToolPanelEnabled=function(){return i.length>0};a.EnableToolPanel();a.AddPolyLine=function(g,d,e,a){if(a===c||a===undefined)a=.4;if(!d||d.length!=7)d="#FF0033";if(!e||e<0)e=10;var f=new GPolyline(g.Select("i => i.ToApiObject()"),d,e,a);b.addOverlay(f)};a.HasStreetViewData=function(){var a=this;if(p==c){panoClient=new GStreetviewClient;panoClient.getNearestPanoramaLatLng(a.GetCenter().ToApiObject(),a.HasStreetViewData_CallBack);window.setTimeOut(a.HasStreetViewData(a.GetCenter().ToApiObject()),3e3)}else return p};a.HasStreetViewData_CallBack=function(a){p=a==c};a.AddStreetViewPanorama=function(){s.setLocationAndPOV(this.GetCenter().ToApiObject())};a.AddNearestStreetViewPanorama=function(){panoClient=new GStreetviewClient;panoClient.getNearestPanorama(this.GetCenter().ToApiObject(),this.AddNearestStreetViewPanorama_CallBack)};a.AddNearestStreetViewPanorama_CallBack=function(a){console.log(a);s.setLocationAndPOV(a.location.latlng)};a.RemoveStreetViewPanorama=function(){s.remove()}};Tesla.Map.MapControl.IsBrowserCompatible=function(){return GBrowserIsCompatible()};Tesla.Map.MapControl.Unload=function(){GUnload()};Tesla.Map.Point=function(c,b){var a=this;a.Latitude=c;a.Longitude=b;a.X=c;a.Y=b;a.ToApiObject=function(b){var a=this;return b?new GPoint(a.X,a.Y):new GLatLng(a.Latitude,a.Longitude)};a.toString=function(){return "("+this.Latitude+", "+this.Longitude+" )"};a.toLocation=function(){return this.Latitude+", "+this.Longitude}};Tesla.Map.Point.FromApiObject=function(a){if(a instanceof GLatLng)return new Tesla.Map.Point(a.lat(),a.lng());if(a instanceof GPoint)return new Tesla.Map.Point(a.x,a.y)};Tesla.Map.Rectangle=function(b,c){var a=this;if(b){a.X1=b.X;a.Y1=b.Y+.003}if(c){a.X2=c.X-.003;a.Y2=c.Y;a.Width=a.X2-a.X1;a.Height=a.Y2-a.Y1;a.CenterX=a.X2-(a.X2-a.X1)/2;a.CenterY=a.Y2-(a.Y2-a.Y1)/2;a.Center=new Tesla.Map.Point(a.CenterX,a.CenterY)}a.toString=function(){var a=this;return String.Format("( ({0},{1}) , ({2},{3}) )",a.X1,a.Y1,a.X2,a.Y2)}};Tesla.Map.Rectangle.FromApiObject=function(a){var b=Tesla.Map.Point.FromApiObject;return new Tesla.Map.Rectangle(b(a.getSouthWest()),b(a.getNorthEast()))};Tesla.Map.Size=function(c,b){var a=this;a.Height=b;a.Width=c;a.ToApiObject=function(){return new GSize(this.Width,this.Height)};a.toString=function(){return "("+this.Width+", "+this.Height+" )"}};Tesla.Map.Size.FromApiObject=function(a){return new Tesla.Map.Size(a.width,a.height)};Tesla.Map.Marker=function(b,d){var a=this,e=b,c=d;a.Map=b;a.constructor.name="Marker";a.GetPixelPoint=function(){return e.GetPixelFromPoint(this.GetPoint())};a.GetPoint=function(){return c};a.Hide=function(){this.ApiObject.hide()};a.Show=function(){this.ApiObject.show()};a.SetImage=function(a,b){this.Icon=new Tesla.Map.MarkerIcon(a,b);this.ApiObject.setImage(a)};a.GetApiOptions=function(){if(this.Icon)return {icon:this.Icon.ToApiObject()}};a.ShowInfo=function(b,c){var a="";if(b)a+="<strong>"+b+"</strong><br/>";a+=c;this.ApiObject.openInfoWindowHtml(a)};a.CoreExec=function(a){var b=$D(this.ApiObject,a);b.apply(null,Array.Create(arguments,1))}};Tesla.Map.MarkerIcon=function(f,g,d,c,e,b){var a=this;a.IconImage=f;a.IconSize=g;a.IconAnchor=d;a.ShadowImage=c;a.ShadowSize=e;a.InfoWindowAnchor=b;a.ToApiObject=function(){var a=this,b=new GIcon;b.image=a.IconImage;if(a.ShadowImage)b.shadow=a.ShadowImage;if(a.IconAnchor)b.iconAnchor=a.IconAnchor.ToApiObject();if(a.IconSize)b.iconSize=a.IconSize.ToApiObject();if(a.ShadowSize)b.shadowSize=a.ShadowSize.ToApiObject();if(a.InfoWindowAnchor)b.infoWindowAnchor=a.InfoWindowAnchor.ToApiObject();return b}}