Error 400 (Invalid or missing input parameters) on a selectFeatures()

11605
13
01-20-2014 06:46 AM
MaxDemars
New Contributor III
Hi,

I use a draw tool to select features like this:

    function initSelectToolbar(map) {
      featureLayer = new esri.layers.FeatureLayer("http://localhost:6080/arcgis/rest/services/carte1/MapServer/0", {
        mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
        outFields: ["*"]
      });

      console.log(featureLayer);
      selectionToolbar = new esri.toolbars.Draw(map);
      selectionToolbar.activate(esri.toolbars.Draw.FREEHAND_POLYGON);
      var selectQuery = new esri.tasks.Query();
      var fieldsSelectionSymbol = new esri.symbol.SimpleMarkerSymbol(
        esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND,
        20,
        new esri.symbol.SimpleLineSymbol(
          esri.symbol.SimpleLineSymbol.STYLE_SOLID,
          new dojo.Color([88,116,152]), 2
        ),
        new dojo.Color([88,116,152,0.45])
      );

      selectionToolbar.on("draw-end", function(geometry) {
        selectionToolbar.deactivate();
        selectQuery.geometry = geometry;
        selectQuery.geometry.spatialReference = sr;
        featureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW);
        featureLayer.setSelectionSymbol(fieldsSelectionSymbol);
        map.addLayer(featureLayer);
      });
    }


I receive an error 400 Missing Parameters when selectFeatures() is performed.

What could be the error?

Thank you for your help
0 Kudos
13 Replies
JamieSimko
New Contributor III
You may want to look at some samples for feature layers.

I haven't used selectFeatures in a while but from first glance I think you have at least two issues:

  1. You don't add feature layer to the map until after calling the selection. This may be causing issues because the layer wouldn't have had time to do any loading. I would try: adding a layer add listener to the map, add the feature layer, and wait for the listener to fire before doing your selection

  2. the feature layer is in ON_DEMAND mode. I believe it has to be SELECTION to work with that function

0 Kudos
MaxDemars
New Contributor III


  1. You don't add feature layer to the map until after calling the selection. This may be causing issues because the layer wouldn't have had time to do any loading. I would try: adding a layer add listener to the map, add the feature layer, and wait for the listener to fire before doing your selection

  2. the feature layer is in ON_DEMAND mode. I believe it has to be SELECTION to work with that function



I have tryed what you suggested by adding the FeatureLayer to the map, changing mode to SELECTION, and creating an event callback when the selection is completed but I still have the 400 error:

      featureLayer = new esri.layers.FeatureLayer("http://localhost:6080/arcgis/rest/services/immeubles/MapServer/0", {
        mode: esri.layers.FeatureLayer.MODE_SELECTION,
        outFields: ["*"]
      });
      
      map = new Map("maptest1");
      map.addLayers([featureLayer,]);

      function initSelectToolbar(map) {
       selectionToolbar = new esri.toolbars.Draw(map);
       selectionToolbar.activate(esri.toolbars.Draw.FREEHAND_POLYGON);
       var selectQuery = new esri.tasks.Query();
       var fieldsSelectionSymbol = new esri.symbol.SimpleMarkerSymbol(
         esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND,
         20,
         new esri.symbol.SimpleLineSymbol(
           esri.symbol.SimpleLineSymbol.STYLE_SOLID,
           new dojo.Color([88,116,152]), 2
         ),
         new dojo.Color([88,116,152,0.45])
       );
      

       selectionToolbar.on("draw-end", function(geometry) {
         selectionToolbar.deactivate();
         selectQuery.geometry = geometry;
         selectQuery.geometry.spatialReference = sr;
         featureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW);  //the 400 error is here
         featureLayer.on("selection-complete", function(){ // this function was never launched
          featureLayer.setSelectionSymbol(fieldsSelectionSymbol);
          console.log(featureLayer);
          map.addLayer(featureLayer);
         });
       });
            }
0 Kudos
MaxDemars
New Contributor III
bang to up this post
0 Kudos
JamieSimko
New Contributor III
I missed this the first time I read your post but your feature layer is being initialized with a MapServer url. It needs to be setup with a FeatureServer url.

This:
http://localhost:6080/arcgis/rest/services/immeubles/MapServer/0

should be changed to:
http://localhost:6080/arcgis/rest/services/immeubles/FeatureServer/0


If you don't have a FeatureServer url you need to go into the ArcGIS Manager and toggle the FeatureServer capability on that map service and restart it.
0 Kudos
MaxDemars
New Contributor III
Hi Jamie,

Thank you for your help but unfortunately I still have a 400 error but with the message: Unable to perform query operation.
0 Kudos
MaxDemars
New Contributor III
Maybe that could help. I have copied the url of the query GET request:

http://localhost:6080/arcgis/rest/services/immeubles/FeatureServer/0/query?f=json&returnGeometry=true&spatialRel=esriSpatialRelIntersects&inSR=4326&outFields=*&outSR=4326
0 Kudos
JamieSimko
New Contributor III
Alright,

making some progress at least.

Another thing you may want to change are the outfields. I recall having some issues in the past with passing "*" for them. I believe now I iterate through all the fields in the layerDetails and pass in the field names directly instead of *. It may be worth just testing with only one field.

I would suggest trying out your query directly through the rest API for testing purposes. You may be able to figure out the error faster that way.
0 Kudos
JamieSimko
New Contributor III
Maybe that could help. I have copied the url of the query GET request:

http://localhost:6080/arcgis/rest/services/immeubles/FeatureServer/0/query?f=json&returnGeometry=true&spatialRel=esriSpatialRelIntersects&inSR=4326&outFields=*&outSR=4326


It doesn't look like that get request has any geometry information associated with it (there should be a JSON geometry object with a collection of x/y points I believe). I don't have time to dig into this further currently but you may require a POST request which I *think* needs a proxy page setup. If you look around the forum I'm sure you will find some more info regarding if that is correct or not.
0 Kudos
MaxDemars
New Contributor III
Is it normal that there is no coordinates of the query object in the query url? I am trying to query features that Intersects a drawn object.

I also try to change the url to select only one field but I still have the same error when pasted the url in the browser.

http://localhost:6080/arcgis/rest/services/immeubles/FeatureServer/0/query?f=json&returnGeometry=true&spatialRel=esriSpatialRelIntersects&inSR=4326&outFields=adresse&outSR=4326
0 Kudos