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