function queryShowResults(featureSet) {
//show results on map
map.graphics.clear();
var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));
var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 0, 0]), 1);
var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));
//QueryTask returns a featureSet. Loop through features in the featureSet and add them to the map.
for (var i = 0, il = featureSet.features.length; i < il; i++) {
//Get the current feature from the featureSet.
//Feature is a graphic
var graphic = featureSet.features;
switch (graphic.geometry.type) {
case "point":
alert("point");
graphic.setSymbol(markerSymbol);
break;
case "polyline":
alert("polyline");
graphic.setSymbol(lineSymbol);
break;
case "polygon":
alert("polygon");
graphic.setSymbol(polygonSymbol);
break;
}
//Add graphic to the map graphics layer.
map.graphics.add(graphic);
}
}
function queryExecute(layerLoc, layerID, qText) {
// layerLoc is location of map file, starting with "http:/"...
// layerID is the layer number the query is performed on.
var queryTask = new esri.tasks.QueryTask(layerLoc + layerID);
var queryParams = new esri.tasks.Query();
queryParams.returnGeometry = true;
queryParams.outFields = ["*"];
queryParams.where = qText;
queryTask.execute(queryParams, queryShowResults);
}
function queryShowResults(featureSet) {
//show results on map
map.graphics.clear();
var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));
var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 0, 0]), 1);
var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));
//QueryTask returns a featureSet. Loop through features in the featureSet and add them to the map.
for (var i = 0, il = featureSet.features.length; i < il; i++) {
//Get the current feature from the featureSet.
var graphic = featureSet.features;
alert('graphic geometry: '+graphic.geometry);
switch (graphic.geometry.type) {
case "point":
graphic.setSymbol(markerSymbol);
break;
case "polyline":
graphic.setSymbol(lineSymbol);
break;
case "polygon":
graphic.setSymbol(polygonSymbol);
break;
}
//Add graphic to the map graphics layer.
map.graphics.add(graphic);
}
}
var query = new esri.tasks.Query();
query.where = "1=1";
query.returnGeometry = true;
var queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3");
queryTask.execute(query, queryShowResults);
If it helps, here is the code for the function that calls my query.
When I test the graphic.geometry, it comes back null. That may be why the graphic.geometry.type will grind the code to a halt. I don't know why it would be null, though, because I set the returnGeometry = true.function queryExecute(layerLoc, layerID, qText) { // layerLoc is location of map file, starting with "http:/"... // layerID is the layer number the query is performed on. var queryTask = new esri.tasks.QueryTask(layerLoc + layerID); var queryParams = new esri.tasks.Query(); queryParams.returnGeometry = true; queryParams.outFields = ["*"]; queryParams.where = qText; queryTask.execute(queryParams, queryShowResults); } function queryShowResults(featureSet) { //show results on map map.graphics.clear(); var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25])); var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 0, 0]), 1); var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25])); //QueryTask returns a featureSet. Loop through features in the featureSet and add them to the map. for (var i = 0, il = featureSet.features.length; i < il; i++) { //Get the current feature from the featureSet. var graphic = featureSet.features; alert('graphic geometry: '+graphic.geometry); switch (graphic.geometry.type) { case "point": graphic.setSymbol(markerSymbol); break; case "polyline": graphic.setSymbol(lineSymbol); break; case "polygon": graphic.setSymbol(polygonSymbol); break; } //Add graphic to the map graphics layer. map.graphics.add(graphic); } }
I recently installed firebug and I'm still getting used to it. I've been debugging it the old fashion way with alerts.
To answer some of the questions, I'm using the following:
JavaScript API v2.1
ArcGIS Server 10.0
ArcMap 10.0
I've added to my code to get the attributes, and I can get all the visible fields and field attributes in a table (like parcel ids, owners, addresses, etc.), but no geography. I've set alerts to show graphic.geometry, and they return null.
Looking through the examples ESRI provides, I dug into their mapservers and found the fields had a supported operation: Query Layer, while my layers only supported Query.
Hi,
I ran into a similar problem where the QueryTask was not returning geometries (but the IdentifyTask was!) I found this forum post which solved the problem for me:
http://forums.esri.com/Thread.asp?c=158&f=2421&t=273166#923332
Try checking to make sure the OBJECTID and SHAPE fields are checked on in the MXD/MSD for the map service -- this worked for me.
-Jesse