1

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);
asked Jan 5, 2015 at 5:06
7
  • 1
    Can you post the code snippet in the question? Commented 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. Commented 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 Commented Jan 6, 2015 at 2:31
  • @Aamir, does not seem to be the mode's problem as I am getting the same result. Commented 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. Commented Jan 6, 2015 at 6:46

1 Answer 1

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.

answered Jan 7, 2015 at 9:07
2
  • sounds like some character(s) in the data that may be causing a JavaScript error? Did you see any errors in browser console? Commented 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. Commented Jan 28, 2015 at 15:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.