﻿// JScript File
var pointSymbol, lineSymbol, fillSymbol;
fillSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0,0.01]), 2), new dojo.Color([255,255,0,0.01]));
lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,255,0,0.01]), 10);
pointSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 14, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,0,0,0.0]), 2), new dojo.Color([255,0,0,0.0]));
var infoTemplateP = new esri.InfoTemplate();  
var graphicsonMouseOver_handler, graphicsonMouseOut_handler, graphicsonClick_handler;


function preLoadData() {
    map.graphics.clear();
    var serviceName = "http://www.mariettaga.gov/arcgis/rest/services/roadclosures/MapServer/";
    //var layerID = "0";
    //var taskString = serviceName + layerID;
        dojo.forEach(["0","1"], function(x) {
        //queryT = new esri.tasks.QueryTask(taskString);
			queryT = new esri.tasks.QueryTask(serviceName + x);    
			var query = new esri.tasks.Query();
			query.returnGeometry = true;
			query.outFields = ["LocationLimits, ClosureName"];
			query.where = "1=1";
			queryT.execute(query, wireResults);   
        });
    
          map.graphics.enableMouseEvents();
                 
          graphicsonMouseOver_handler = dojo.connect(map.graphics, "onMouseOver", function(evt) {
            	changeCursor();
		        var content = evt.graphic.getContent();
                var title = evt.graphic.getTitle();
				
          });
         
          graphicsonMouseOut_handler = dojo.connect(map.graphics, "onMouseOut", function(evt) {
		        changeCursor();
          });
          // Note: must override the default behavior of the graphic onclick event to get a full identify
          //  but doing this will cause over-ride the map.onclick event when user click a graphic
          graphicsonClick_handler = dojo.connect(map.graphics, "onClick", doIdentify);
}

function wireResults(featureSet) {

           //QueryTask returns a featureSet.  Loop through features in the featureSet and add them to the map.
           il=featureSet.features.length;
console.log("Features: " + il);
           for (var i=0; i<il; i++) {
          
                //Get the current feature from the featureSet.
                //Feature is a graphic
                var graphic = featureSet.features[i];

                switch (graphic.geometry.type) {
                  case "point":
                    graphic.setSymbol(pointSymbol);
                    break;
                  case "polyline":
                    graphic.setSymbol(lineSymbol); 
                    break; 
                  case "polygon":
                    graphic.setSymbol(fillSymbol);
                    break;                      
                } 
                //   graphic.setInfoTemplate(infoTemplateP);

                //Add graphic to the map graphics layer.
                map.graphics.add(graphic);
           }
}


function changeCursor() { 
    dojo.byId("map_map_graphics").style.cursor=(dojo.byId("map_map_graphics").style.cursor==='pointer') ? 'default' : 'pointer'; 
    //console.log("changeCursor: " + dojo.byId("map_map_graphics").style.cursor );
} 
