dojo.require("esri.map");dojo.require("esri.tasks.query");dojo.require("esri.toolbars.navigation");dojo.require("dijit.form.Button");dojo.require("dijit.Toolbar");dojo.require("dijit.Dialog");dojo.require("dijit.Menu");dojo.require("dijit.layout.TabContainer");dojo.require("dijit.layout.ContentPane");var map,gMap,dynamicLayer,baseBottomLayer,baseTopLayer,diagLayer,navToolbar,mapMenu,currentHeight,currentExtent,graphicsLayer,dgraphicsLayer,ml_enabled_SQL,ml_disabled_SQL,lastClickPoint,currAlternative,masterLayerList,ptrs,ptrsEnabled,showML,isDiagramming=false,baseUrl="http://gis.arcadis-us.com/ArcGISPublic/rest/services/revive285/",baseUrl2="http://ga1ims2.arcadis-us.com/ArcGIS/rest/services/revive285/";dojo.addOnLoad(init);function init(){setMapDivSize();dynamicLayer=new esri.layers.ArcGISDynamicMapServiceLayer(baseUrl2+"Dynamic/MapServer");baseBottomLayer=new esri.layers.ArcGISTiledMapServiceLayer(baseUrl+"Base_Bottom/MapServer");baseTopLayer=new esri.layers.ArcGISTiledMapServiceLayer(baseUrl+"Base_Top/MapServer");diagLayer=new esri.layers.ArcGISDynamicMapServiceLayer(baseUrl2+"WebMapDiagram_93/MapServer");map=new esri.Map("map",{slider:true,nav:true});map.addLayer(baseBottomLayer);map.addLayer(dynamicLayer);map.addLayer(diagLayer);map.addLayer(baseTopLayer);graphicsLayer=new esri.layers.GraphicsLayer();zoomGraphicsLayer=new esri.layers.GraphicsLayer();toggleDiagrams(false);addInterchangeMenuItems();navToolbar=new esri.toolbars.Navigation(map);dojo.connect(navToolbar,"onExtentHistoryChange",extentHistoryChangeHandler);dojo.connect(window,"onresize",resizeMap);dojo.connect(map,"onLoad",initMap);dojo.connect(map,"onMouseUp",function(a){lastClickPoint=a.mapPoint});mapMenu=new dijit.Menu({targetNodeIds:["map"]});mapMenu.addChild(new dijit.MenuItem({label:"See in Google Maps",onClick:function(a){showGoogleMap(lastClickPoint)}}));resizeHeader();showWelcomeScreen()}function initMap(){fullExtent();map.enableScrollWheelZoom()}function fullExtent(){var a=new esri.geometry.Extent(-9404050,4008435.374,-9377474,4022449.377,new esri.SpatialReference({wkid:102100}));map.setExtent(a,false)}function indicate(b){var a=b.graphic.attributes.TYP;xhrArgs={url:"AJAX/GlossaryHandler.ashx",handleAs:"text",content:{w:a},load:function(c){map.infoWindow.setTitle(a);map.infoWindow.setContent("<div style='width: 160px;'>"+c+"</div>");map.infoWindow.resize(200,200);if(map.infoWindow.isShowing==false){map.infoWindow.show(b.screenPoint,map.getInfoWindowAnchor(b.screenPoint))}else{map.infoWindow.move(b.screenPoint)}}};dojo.xhrGet(xhrArgs)}function resizeMap(){if(currentHeight!=document.documentElement.clientHeight){setMapDivSize();map.resize();resizeHeader();map.infoWindow.hide()}currentHeight=document.documentElement.clientHeight}function resizeHeader(){var a=dojo.marginBox("header").w-176;dojo.byId("gradientImg").src="AJAX/Gradient.ashx?o=h&h=87&w="+a+"&color1=FFFFFF&color2=007ea1";dojo.contentBox("gradientImg",{w:a})}function setMapDivSize(){var c,a,d,b;if(typeof(window.innerWidth)=="number"){b=window.innerWidth;d=window.innerHeight}else{if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){b=document.documentElement.clientWidth;d=document.documentElement.clientHeight}else{if(document.body&&(document.body.clientWidth||document.body.clientHeight)){b=document.body.clientWidth;d=document.body.clientHeight}}}c=d-dojo.marginBox("header").h-dojo.marginBox("navToolbar").h-dojo.marginBox("copyright").h;a=b-dojo.marginBox("menupane").w;dojo.query("#map").style("height",c+"px").style("width",a+"px")}function extentHistoryChangeHandler(){dijit.byId("zoomprev").disabled=navToolbar.isFirstExtent();dijit.byId("zoomnext").disabled=navToolbar.isLastExtent()}function getManagedLaneSQLStrings(a){xhrArgs={url:"AJAX/AlternativesHandler.ashx",handleAs:"json",preventCache:true,content:{a:a,f:"managedSQL"},load:function(c,b){dojo.byId("Idic").innerHTML=c.enabledQuery+" | "+c.disabledQuery;ml_enabled_SQL=c.enabledQuery;ml_disabled_SQL=c.disabledQuery},error:function(b){alert(b)}};dojo.xhrGet(xhrArgs)}function showWelcomeScreen(){var b=new esri.geometry.Point([map.width/2,map.height/2],new esri.SpatialReference({wkid:102100}));console.log(b);var a=dijit.byId("alternativeDescriptionDialog");a.draggable=false;a.closeable=false;a.attr("href","r285Welcome.html");a.attr("width","400px");a.attr("height","400px");a.show()}function showGoogleMap(b){var a={url:"AJAX/Converter.ashx",handleAs:"text",preventCache:true,content:{x:b.x,y:b.y},load:function(e){var d,f,c;d=e.split(",");f=new google.maps.LatLng(d[1],d[0]);c={zoom:16,center:f,mapTypeId:google.maps.MapTypeId.HYBRID,mapTypeControl:false};dijit.byId("googleMapsDialog").show();if(gMap==null){gMap=new google.maps.Map(document.getElementById("googleMap"),c)}else{gMap.setCenter(f)}},error:function(c){alert("An unexpected error occurred: "+c)}};dojo.xhrGet(a)}function toggleLegend(){if(dojo.style("legend","display")=="none"){dojo.style("legend","display","");dojo.byId("legendToggle").innerHTML="(click to hide)";dojo.style("alternativesPanel","display","none");dojo.style("linksPanel","display","none")}else{dojo.style("legend","display","none");dojo.byId("legendToggle").innerHTML="(click to show)";dojo.style("alternativesPanel","display","");dojo.style("linksPanel","display","")}}function filterNoneLayers(d,c,b){if(d==-1){return false}else{return true}}function getLyrGroup(a,c,b){if(a[c]==-1){return new Array()}if(c+1==a.length){return b.slice(a[c])}else{return b.slice(a[c],a[c+1])}}function getRdwyLayers(){return getLyrGroup(ptrs,2,masterLayerList)}function getTransitLayers(){return getLyrGroup(ptrs,1,masterLayerList)}function getViewshedLayers(){return getLyrGroup(ptrs,0,masterLayerList)}function showLayers(){var a=new Array();if(ptrsEnabled!=null){for(i=0;i<3;i++){if(ptrsEnabled[i]==true){var c=getLyrGroup(ptrs,i,masterLayerList);if(i==2){switch(showML){case 0:break;case 1:c.pop();break;case 2:var b=c.pop();c.pop();c.push(b);break}}a=a.concat(c)}}}dynamicLayer.setVisibleLayers(a)}function toggleViewsheds(a){var b=0;if(a==false){graphicsLayer.hide()}else{graphicsLayer.show()}ptrsEnabled[0]=a;showLayers()}function toggleTransit(a){ptrsEnabled[1]=a;showLayers()}function toggleDiagrams(a){dijit.byId("DesignButton").setChecked(!a);dijit.byId("DiagramButton").setChecked(a);isDiagramming=a;if(a==false){if(ptrs!=null){dojo.style("vsheds","display",(ptrs[0]!=-1)?"":"none");dojo.style("transpSelection","display",(ptrs[1]!=-1)?"":"none");dojo.style("managedLaneSelection","display",(ptrs[2]!=-1)?"":"none")}diagLayer.setVisibleLayers([]);if(dgraphicsLayer!=null){dgraphicsLayer.hide()}showLayers()}else{dojo.style("transpSelection","none");switch(currAlternative){case"4":queryDefinitionsLayer(4);break;case"6a":queryDefinitionsLayer(10);break;case"6b":queryDefinitionsLayer(16);break}showDiagrams([0,1,2,3]);dynamicLayer.setDefaultVisibleLayers();if(dgraphicsLayer!=null){dgraphicsLayer.show()}}}var numVisibleLayers=20;function showDiagrams(a){var b=Array();var e=Array();switch(currAlternative){case"4":b=[1,2,3];break;case"6a":b=[6,7,8,9];break;case"6b":b=[12,13,14,15];break}for(var d=0;d<a.length;d++){var c=a[d];if(c<b.length){e.push(b[c])}}if(map.extent.getWidth()>1000){zoomToNearestInterchange()}showLayers();console.log(e);diagLayer.setVisibleLayers(e)}function alterDefnQuery(b,c){var a=[];a[b]=c;dynamicLayer.setLayerDefinitions(a)}function displayManagedLanes(a){if(isDiagramming==false){switch(a){case 0:alterDefnQuery(getRdwyLayers()[0],"");showML=0;showLayers();break;case 1:alterDefnQuery(getRdwyLayers()[0],ml_disabled_SQL);showML=1;showLayers();break;case 2:alterDefnQuery(getRdwyLayers()[0],ml_enabled_SQL);showML=2;showLayers();break}}else{switch(a){case 0:showDiagrams([0,1,2,3]);break;case 1:showDiagrams([0,1,3]);break;case 2:showDiagrams([0,2,3]);break}}}var ichanges=[{id:0,name:"Windy Hill Rd",x:-9403374.6194,y:4015736.9769},{id:1,name:"I-75",x:-9402125.8068,y:4014085.0372},{id:2,name:"Northside Dr / New Northside Dr",x:-9398697.8484,y:4016380.0007},{id:3,name:"Riverside Dr",x:-9395973.2138,y:4017455.0169},{id:4,name:"Roswell Rd",x:-9393195.8812,y:4017041.1963},{id:5,name:"GA-400",x:-9390663.9684,y:4016921.5829},{id:6,name:"Ashford-Dunwoody Rd",x:-9388451.034,y:4017812.7941},{id:7,name:"Chamblee-Dunwoody Rd",x:-9385888.9308,y:4018111.4704},{id:8,name:"North Peachtree Rd",x:-9384510.0977,y:4018287.9346},{id:9,name:"Peachtree-Industrial Blvd",x:-9382757.9651,y:4017245.8214},{id:10,name:"Buford Hwy",x:-9381667.6447,y:4015851.8229},{id:11,name:"I-85",x:-9379874.0517,y:4014349.4986}];function zoomToNearestInterchange(){var l=map.extent;var e=Array();var d=Array();var b=Infinity;var a=-1;for(var c=0;c<ichanges.length;c++){var h=Math.abs(ichanges[c].x-l.getCenter().x);console.log(c);console.log(h);if(h<b){a=c;b=h}console.log(a)}if(a==0||a==1){if(Math.abs(ichanges[0].y-l.getCenter().y)<Math.abs(ichanges[1].y-l.getCenter().y)){a=0}else{a=1}}var g=ichanges[a].x;var f=ichanges[a].y;var l=new esri.geometry.Extent(g-600,f-600,g+600,f+600,new esri.SpatialReference({wkid:102100}));map.setExtent(l)}function addInterchangeMenuItems(){for(var a=0;a<ichanges.length;a++){dijit.byId("quickZoomMenu").addChild(new dijit.MenuItem({label:ichanges[a].name,onClick:function(c){var e=dijit.byId("quickZoomMenu").getIndexOfChild(this);var b=ichanges[e].x;var f=ichanges[e].y;var d=new esri.geometry.Extent(b-600,f-600,b+600,f+600,new esri.SpatialReference({wkid:102100}));map.setExtent(d)}}))}};
