TypeError: a.spatialReference is undefined on a selectFeatures()

739
2
01-20-2014 05:51 AM
MaxDemars
New Contributor III
I use a draw tool to select features like this:

function SelectTool(map) {
    featureLayer = new esri.layers.FeatureLayer("http://localhost:6080/arcgis/rest/services/carte1/MapServer/0", {
      mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
      outFields: ["*"]
     });
     
      selectionToolbar = new esri.toolbars.Draw(map);
      selectionToolbar.activate(esri.toolbars.Draw.FREEHAND_POLYGON);
      var selectQuery = new esri.tasks.Query();
      var fieldsSelectionSymbol = new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255,255,0,0.5]));
      fieldsSelectionSymbol.setOutline(new esri.symbol.SimpleLineSymbol("dashdot", new dojo.Color([255,0,0]), 2));
      
      selectionToolbar.on("draw-end", function(geometry) {
        selectionToolbar.deactivate();
        selectQuery.geometry = geometry;
 console.log(selectQuery);
        featureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW);
        featureLayer.setSelectionSymbol(fieldSelectionSymbol);
        map.addLayer(featureLayer);
      });


I receive this error TypeError: a.spatialReference is undefined when the selectFeatures() is performed and the script stops after that. What could be the problem?

the selectQuery seems to be correct with spatialReference object (wkid: 4326)

Thank you for your help
0 Kudos
2 Replies
JohnathanBarclay
Occasional Contributor
The Feature Layer needs to be added to the map before you can perform selectFeatures.
0 Kudos
MaxDemars
New Contributor III
The Feature Layer needs to be added to the map before you can perform selectFeatures.


Thank you for your reply. I tryed to add the layer to map before, but I have the same error. I re-instantiated the geometry.spatialReference before the selectFeatures() and it works.


        ...
        selectQuery.geometry = geometry;
        selectQuery.geometry.spatialReference = sr;
        featureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW);
        featureLayer.setSelectionSymbol(fieldsSelectionSymbol);
        map.addLayer(featureLayer);
      });
0 Kudos