-
Notifications
You must be signed in to change notification settings - Fork 0
/
carto.min.js
executable file
·1 lines (1 loc) · 6.22 KB
/
carto.min.js
1
(function(){function t(e){this.map=false,this.actualMap=false,this.el=false,this.provider=false,this.type=false,this.sensor=false,this.geocoder=false,this.center=false,this.debug=false,this.geocodeCount=0,this.markers=[],this.polylines=[],this.directions=[],this.mapTypes=[],this.unitMetrics=[],this.travelModes=[],this.animations=[],this.realignedPolylines=[];this.init(e)}var e=[];t.prototype.init=function(e){this.provider=e.provider||false;this.type=e.type||false;this.el=e.element||false;this.center=e.center||false;this.debug=e.debug||false;this.zoom=e.zoom||8;this.markers=e.markers||[];this.polylines=e.polylines||[];this.directions=e.directions||[];switch(this.provider){case"gmap":this.setupMap();var t=this;break;case"ovi":case"bing":alert("not supported");break;default:this.detectMap();this.getMapObj();this.setupMap()}};t.prototype.setupMap=function(){this.getMapObj();if(typeof this.center=="string"){var t=this;switch(this.provider){case"gmap":this.animations=google.maps.Animation;this.mapTypes=google.maps.MapTypeId;for(var n in this.mapTypes){if(this.type.toLowerCase()===this.mapTypes[n].toLowerCase()){this.type=this.mapTypes[n]}}var r=e.length;e.push();this.geocoder.geocode({address:this.center},function(e,n){t.center=e[0].geometry.location;t.actualMap=t.draw();if(t.actualMap){if(t.markers.length)t.pushMarkers(t.markers,t.actualMap);if(t.polylines.length)t.pushPolylines(t.polylines,t.actualMap);if(t.directions.length)t.pushDirections(t.directions,t.actualMap);return t}});break;case"bing":case"ovi":alert("Support not implemented");break}}};t.prototype.pushDirections=function(e,t){this.directionsService=new google.maps.DirectionsService;this.directionsDisplay=new google.maps.DirectionsRenderer;this.travelModes=google.maps.TravelMode;this.unitMetrics=google.maps.UnitSystem;for(var n in this.travelModes){if(n===e.travel.toUpperCase()){e.travel=this.travelModes[n]}}for(var n in this.unitMetrics){if(n===e.units.toUpperCase()){e.units=this.unitMetrics[n]}}var r={origin:e.from,destination:e.to,waypoints:e.waypoints||{},provideRouteAlternatives:e.alternatives||false,travelMode:e.travel,unitSystem:e.units};directionsDisplay=this.directionsDisplay;this.directionsService.route(r,function(e,t){if(t===google.maps.DirectionsStatus.OK){directionsDisplay.setDirections(e)}});this.directionsDisplay.setMap(t)};t.prototype.pushPolylines=function(e,t){var n=e.length;for(var r=0;r<n;r++){var i=e[r];if(typeof i=="object"){var s=[];for(j=0;j<i.waypoints.length;j++){var o=i.waypoints[j];var u={totalPointers:i.waypoints.length,originalWaypoints:i.waypoints,polyline:i,builder:s,currentMarker:j};if(typeof o=="object"){var a=new google.maps.LatLng(o.lat,o.long);u.builder.push(a);if(u.totalPointers===u.builder.length){var f=new google.maps.Polyline({path:u.builder,strokeColor:u.polyline.colour,strokeOpacity:u.polyline.opacity,strokeWeight:u.polyline.weight});f.setMap(t)}}else{this.geocodeAddr(i.waypoints[j],function(e,n,r){r.realignedPolylines=[];n.builder.push({location:e,address:n.originalWaypoints[n.currentMarker]});if(n.totalPointers===n.builder.length){for(var i=0;i<n.totalPointers;i++){for(var s=0;s<n.totalPointers;s++){if(n.originalWaypoints[i]===n.builder[s].address){r.realignedPolylines[i]=n.builder[s].location;if(i===s){}else{}}else if(n.builder[s].address==undefined){r.realignedPolylines[i]=n.builder[s]}}}var o=new google.maps.Polyline({path:r.realignedPolylines,strokeColor:n.polyline.colour,strokeOpacity:n.polyline.opacity,strokeWeight:n.polyline.weight});o.setMap(t);return}},u,this)}}}else{}}};t.prototype.pushMarkers=function(e,t){var n=e.length,r=this;for(var i=0;i<n;i++){if(typeof e[i]==="object"){if(e[i].location){this.geocodeAddr(e[i].location,function(e,n,r){var i=new google.maps.Marker({position:e,map:t,icon:n.image||"",title:n.name});var s=new google.maps.InfoWindow({content:n.iwindow.content||'<div id="content"><div id="siteNotice"></div><h1 id="firstHeading" class="firstHeading">'+n.name+"</h1></div>"});google.maps.event.addListener(i,"click",function(){s.open(t,i)});r.markers.push(i)},e[i],this,false)}else{var s=new google.maps.Marker({position:new google.maps.LatLng(e[i].lat,e[i].long),map:t,title:e[i].name,icon:e[i].image||""});var o=new google.maps.InfoWindow({content:e[i].iwindow.content});google.maps.event.addListener(s,"click",function(){o.open(t,s)});this.markers.push(s)}}else{this.geocodeAddr(e[i],function(e,n,r){var i=new google.maps.Marker({position:e,map:t,title:n});var s=new google.maps.InfoWindow({content:'<div id="content"><div id="siteNotice"></div><h1 id="firstHeading" class="firstHeading">'+n+"</h1></div>"});google.maps.event.addListener(i,"click",function(){s.open(t,i)});r.markers.push(i)},e[i],this)}}};t.prototype.geocodeAddr=function(t,n,r,i,s){var o=this,u=false,a=0;console.log("geocode cache length",e.length);for(var f=0;f<e.length;f++){if(e[f].address==t){u=e[f];console.log("from the cache!")}}if(u){console.log(u);setTimeout(function(){console.log(u.geocoder.geometry.location);n(u.geocoder.geometry.location,r,i)},1e3);return false}else{a=e.length;e.push({address:t,callback:n,pbObj:r,obj:i})}console.log(e);if(s){console.log("TIMEOUT");i.geocoderCount=0}if(i.geocoderCount%10==0){setTimeout("Cartograph.geocodeAddr(address, cb, pushbackObj, obj, true)",5e3)}else{this.geocoder.geocode({address:t},function(s,o){if(o==="OK"){console.log(i.type,t);e[a].geocoder=s[0];n(s[0].geometry.location,r,i)}});i.geocoderCount++}};t.prototype.authenticate=function(){};t.prototype.mapFunctions=function(){};t.prototype.detectMap=function(){this.type=window.google?"gmap":window.Microsoft?"bing":window.ovi?"ovi":false;if(this.type===false){this.callError("unsupported");return false}};t.prototype.getMapObj=function(){switch(this.provider){case"gmap":this.geocoder=new google.maps.Geocoder;this.map=window.google.maps;break;case"bing":return window.Microsoft.Maps;break;case"ovi":return window.ovi.mapsapi;break}return false};t.prototype.reverseGeocode=function(){};t.prototype.draw=function(){switch(this.provider){case"gmap":var e={zoom:this.zoom,center:this.center,mapTypeId:this.type};return new google.maps.Map(document.getElementById(this.el.replace("#","")),e);break;case"bing":case"ovi":alert("Support not yet implemented");return false;break}};t.prototype.callError=function(e){if(console){console.log(e)}else{alert(e)}};if(!window.Carto){window.Carto=t}})()