[GIS] ArcGIS javascript API setDefinitionExpression returns wrong result set

arcgis-javascript-apifeature-layerjavascript

New to GIS and ArcGIS.

I am trying to use the javascript API setDefinitionExpression to limit the output of a FeatureLayer on the map; however, the result set returned by the function is incorrect. The function returns only one result set but when I try to run the same query on the either the ArcGIS server or the database server, there are 6 results.

Anyone know why this is the case?

I am using SQL Server 2012 and following is the code I am using:


var layer1 = new FeatureLayer(path + "/arcgis/rest/services/MammalDistributionMapOIMap/MapServer/0", {
    outFields: ["*"],
    opacity: 0.5
});
var speciesID = document.getElementById("speciesID").value;
stringquery = "species_id = " + speciesID;
layer1.setDefinitionExpression(stringquery);

Best Answer

Finally found out what may cause the problem as now my query returns correctly and the layer is shown.


var layer1 = new FeatureLayer(path + "/arcgis/rest/services/MammalDistributionMapOIMap/MapServer/0", {
    opacity: 0.5
});

By removing the outFields["*"] from the code, the whole layer is shown when no definition expression is set and correct data is shown when a definition expression is set.

Not sure why it is the case, may be some one with more experience can answer it.