Select features and zoom to layers

3709
18
Jump to solution
04-15-2017 08:29 AM
SibghatUllah1
Occasional Contributor

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);
}
}
});

0 Kudos
18 Replies
SibghatUllah1
Occasional Contributor

Dear Robert,

Please see the screenshot and error below:

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

But do you get the same result when you use the exact code I posted above?..

0 Kudos
SibghatUllah1
Occasional Contributor

Yes i have copied the code which you posted and attached the screenshot of the error.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

What version of ArcGIS Server are you using?

0 Kudos
SibghatUllah1
Occasional Contributor

10.2.2

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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);
          }
        }
SibghatUllah1
Occasional Contributor

32640

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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};
SibghatUllah1
Occasional Contributor

finally giving manual spatial reference work. Thank you Robert for your time and support 

0 Kudos