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);
-
1Can you post the code snippet in the question?Aamir Suleman– Aamir Suleman2015年01月05日 13:56:18 +00:00Commented 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.Aamir Suleman– Aamir Suleman2015年01月06日 02:13:09 +00:00Commented 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 queryStephen Lead– Stephen Lead2015年01月06日 02:31:35 +00:00Commented 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– Ikki Cheng2015年01月06日 06:37:38 +00:00Commented 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– Ikki Cheng2015年01月06日 06:46:11 +00:00Commented 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?Aamir Suleman– Aamir Suleman2015年01月26日 02:41:31 +00:00Commented 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– Ikki Cheng2015年01月28日 15:03:58 +00:00Commented Jan 28, 2015 at 15:03
Explore related questions
See similar questions with these tags.