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 )
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."); }map.graphics.add(graphic); graphicsLayer.add(graphic);
Solved! Go to Solution.
require(["dojo/ready", etc]
function (ready, etc) {
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);
}
});
require(["dojo/ready", etc]
function (ready, etc) {
});
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
//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) {
console.log(result.feature);
console.log(result);
alert("forEach Fired");
graphic = new esri.Graphic(result.feature);
graphic.spatialReference = map.spatialReference;
console.log(graphic);
graphic.setSymbol(polygonSymbol);
alert("SymbolSet");
console.log(graphicsLayer);
console.log(map.spatialReference);
console.log(graphic.spatialReference);
alert("About to attempt to add graphics");
*****This is where it breaks!! I get the above alert, but not the next alert below***************
map.graphics.add(graphic);
alert("graphic added to map");
graphicsLayer.add(graphic);
alert("graphic added to graphicsLayer");
alert("forEach looped");
});
//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.");
}
Maybe this is too obvious, but do you have variables for graphic and graphicsLayer defined earlier? I'm forever leaving out that little word 'var' when I get in a hurry.
I can get the map to open, but your services must not be public facing because nothing loads after the frame.
Sorry, Kelly... I have logged a request with our enterprise IT service to open the appropriate ports in our campus firewall. That was something I had overlooked in this conversion process.
Alex
graphic = new esri.Graphic(result.feature);
graphic = new esri.Graphic(result.feature.geometry);