I am trying to select highlight features and zoom to selected features layer extent.My code below runs but doesn't highlight any feature.
on(dom.byId("try"), "click", function () {
var queryTask = new QueryTask("http://localhost:6080/arcgis/rest/services/RAEC/MapServer/12");
//build query filter
var que = new Query();
que.returnGeometry = true;
que.outFields = ["FeederID", "OBJECTID"];
que.outSpatialReference = { "wkid": 32640 };
que.where = "FeederID<> ''";
symbol = new SimpleMarkerSymbol();
symbol.setStyle(SimpleMarkerSymbol.STYLE_SQUARE);
symbol.setSize(10);
symbol.setColor(new Color([255,255,0,0.5]));
queryTask.execute(que,showResults);
function showResults(featureSet) {
map.graphics.clear();
var resultFeatures = featureSet.features;
for (var i=0, il=resultFeatures.length; i<il; i++) {
var graphic = resultFeatures;
graphic.setSymbol(symbol);
map.graphics.add(graphic);
}
}
});
Solved! Go to Solution.
Dear Robert,
Please see the screenshot and error below:
But do you get the same result when you use the exact code I posted above?..
Yes i have copied the code which you posted and attached the screenshot of the error.
What version of ArcGIS Server are you using?
10.2.2
Can you update your code by adding line 6 below and tell me the results of the console?
function showResults(featureSet) {
//remove all graphics on the maps graphics layer
map.graphics.clear();
//Performance enhancer - assign featureSet array to a single variable.
var resultFeatures = featureSet.features;
console.info(resultFeatures[0].geometry.spatialReference.wkid);
//Loop through each feature returned
for (var i = 0, il = resultFeatures.length; i < il; i++) {
//Get the current feature from the featureSet.
//Feature is a graphic
var graphic = resultFeatures[i];
graphic.setSymbol(symbol);
//Set the infoTemplate.
graphic.setInfoTemplate(infoTemplate);
//Add graphic to the map graphics layer.
map.graphics.add(graphic);
}
}
32640
OK, That is what does not make sense then.
query = new Query();
query.returnGeometry = true;
query.outFields = ["FeederID"];
query.outSpatialReference = map.spatialReference;
line 2 and line 4 should cause the returned queries geometry to be in the maps spatial reference (WKID 102100).
You could try to manually set it:
query.outSpatialReference = {"wkid": 102100};
finally giving manual spatial reference work. Thank you Robert for your time and support