Morning,In my quest to update one of my web apps to AMD style, I am running into a perplexing issue with my find task. The structure of this task is found in many places in the Samples. The following code is my version of it on my app:Global variables, require and function calls var map, navToolbar, infoTemplate, identifyTask, identifyParams, findTask, findParams, graphicsLayer, searchText; require(["dojo/parser", "dojo/_base/connect", "dojo/_base/array", "esri/map", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/GraphicsLayer", "esri/graphic", "esri/InfoTemplate", "esri/toolbars/navigation", "dojo/dom", "esri/tasks/FindTask", "esri/tasks/FindParameters", "dijit/dijit", "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/layout/AccordionContainer", "dijit/form/TextBox", "dijit/form/Button", "dijit/Toolbar", "dijit/Tooltip", "dijit/registry", "dojo/_base/Color", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/tasks/IdentifyTask", "esri/tasks/IdentifyParameters", "esri/tasks/IdentifyResult", "dojo/domReady!" ], function ( parser, connect, array, Map, ArcGISDynamicMapServiceLayer, GraphicsLayer, Graphic, InfoTemplate, Navigation, dom, FindTask, FindParameters, Color, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, IdentifyTask, IdentifyParameters, IdentifyResult, registry )
The find task:function execute(searchText) { //set the search text to find parameters //create find tasks with url to map services findTask = new esri.tasks.FindTask("http://eagle.camplan.uga.edu:6080/arcgis/rest/services/CampusMap/UGA_CampusMap_Base/MapServer"); //create find parameters and define known values findParams = new esri.tasks.FindParameters(); findParams.returnGeometry = true; //findParams.outSpatialReference = map.spatialReference; findParams.layerIds = [7]; findParams.searchFields = ["NAME", "NUMBER"]; findParams.searchText = searchText; findTask.execute(findParams, showResults, findErr); } function showResults(results) { //display the results of the building text search //symbology for graphics markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 20, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 255, 255]), 1), new dojo.Color([0, 255, 255, 0.25])); lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([0, 255, 255]), 1); polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([0, 255, 255]), 2), new dojo.Color([0, 255, 255, 0.25])); //find results return an array of graphics in the graphicslayer. graphicsLayer = new esri.layers.GraphicsLayer(); graphicsLayer.spatialReference = map.spatialReference; map.graphics.clear(); //Build an array of attribute information and add each found graphic to the map dojo.forEach(results, function (result) { var graphic = new esri.Graphic(result.feature); graphic.spatialReference = map.spatialReference; graphic.setSymbol(polygonSymbol); map.graphics.add(graphic); graphicsLayer.add(graphic); }); //create an extent matching the graphics of the parcel(s) var zoomExtent = esri.graphicsExtent(graphicsLayer.graphics); var zoomXmin = zoomExtent.xmin; var zoomXmax = zoomExtent.xmax; var zoomScale = zoomXmax - zoomXmin; if (zoomExtent.xmin < 2460000 || zoomExtent.ymin < 1345000 || zoomExtent.xmax > 2630000 || zoomExtent.ymax > 1505000) { apprise("Your Find Building results include a building outside of ACC/Main UGA Campus. Please refine your search"); } else if (zoomScale > 10000) { apprise("Your Find Building results require a coarse scale to display. Please refine your search"); } else { map.setExtent(zoomExtent.expand(2)); } } function findErr(error) { //Alerts the user to a return of no results in building search apprise("Your search returned no results. Please refine your search."); }The find task function showResults is failing to findErr at the point when I attempt to add the graphic to the map and to the graphicsLayer: map.graphics.add(graphic); graphicsLayer.add(graphic);
If I comment out these add statements, I fail out at the extent creation, but one thing at a time, right? 🙂Anyone have any ideas on why I cannot add the graphics to the map or to the graphics layer? I tried to address any issue that spatial reference might cause with setting the graphics returned from the FindTask and the GraphicsLayer to the map Spatial Reference, but I am at a loss.Alex DeVine