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;
  • 1
    Can you post the code snippet in the question? Jan 5, 2015 at 13:56
  • looks ok to me. It is possible that the features are not in the current map extent. The default mode that FeatureLayer runs in is the FeatureLayer.MODE_ONDEMAND. Set it explicitly to FeatureLayer.MODE_SNAPSHOT. Jan 6, 2015 at 2:13
  • you could test it with queryCount, which gets a count of the number of features that satisfy the input query Jan 6, 2015 at 2:31
  • @Aamir, does not seem to be the mode's problem as I am getting the same result.
    – Ikki Cheng
    Jan 6, 2015 at 6:37
  • @Stephen, the query does return 6 matches but the map shows only one. Another strange thing is when I am not setting the expression, half of the layer is missing.
    – Ikki Cheng
    Jan 6, 2015 at 6:46

1 Answer 1


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.

  • sounds like some character(s) in the data that may be causing a JavaScript error? Did you see any errors in browser console? Jan 26, 2015 at 2:41
  • @AamirSuleman, no, I don't see any error in the console related to the data except id==mainWindow already registered error. And I do have other maps return even more data that works without problem.
    – Ikki Cheng
    Jan 28, 2015 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.