Within a custom widget I'm developing I am accessing specific layers that are loaded into an existing webmap by way of:
_operLayers = this.map.itemInfo.itemData.operationalLayers;
I can then do some things like toggle visibility by setting a reference to a layerObject like this:
array.map(_operLayers, lang.hitch(this, function (lyr) {
if (lyr.layerObject) {
if (lyr.title === "Alert 7day - Hydraulic Element Set") {
lyr.layerObject.setVisibility(true);
lyr.visibility = true;
lyr.definitionExpression = "alertPriority = 'Low'";
}
}
}
))
Is there any way to set a filter/definitionExpression on this layerObject? As you can see above, what I attempted has no effect.
Of note: the service layers contained in the webmap are enriched with additional attributes from a Server Object Interceptor and consequently I'm unable to apply the desired definitionExpression/filter on the AGO item created from that service layer. We need a way to set a date value > CURRENT_TIMESTAMP but the service does not honor this type of WHERE clause.
Thanks for any input.
Solved! Go to Solution.
James,
You absolutely wouldn't in your situation. You have already looping through your layer in the webmap and getting the layer you want so you then just set the layer definitionExpression using the method provided on the layerObject. Originally in your code you were attempting to set it using the property "definitionExpression". That will not work you have to set it using the method.
lyr.setDefinitionExpression("alertPriority = 'Low'");
James,
What is the layer type (i.e. FeatureLayer or ArcGisDynamicMapServiceLayer)? If it is a Feature layer than you set the definition using the method setDefinitionExpression
https://developers.arcgis.com/javascript/3/jsapi/featurelayer-amd.html#setdefinitionexpression
Robert -- we add the specific service layer to the webmap using the "Add data from web" option, then when it's added we save it (after setting up popups, symbology, etc). So, I believe it's a "FeatureLayer" at that point?
Inspecting the lyr in dev tools says layerType: "ArcGISFeatureLayer"
Edit: also, all of the examples show for a "new FeatureLayer()" but I'm misunderstanding how this applies to the FeatureLayers already in the map?
James,
It will be a FeatureLayer if the url you provided ends with the sublayer id (i.e FeatureServer/1 or MapServer/0).
Yes that's how it is added with the layer id at the end.
I'm still not quite following the examples as they are all suggesting to create a reference to a "new FeatureLayer()", set the definitionExpress and then add it to the map. But my confusion is, it's already added to the map, I'm not seeing why I would create a new instance and add it again?
James,
You absolutely wouldn't in your situation. You have already looping through your layer in the webmap and getting the layer you want so you then just set the layer definitionExpression using the method provided on the layerObject. Originally in your code you were attempting to set it using the property "definitionExpression". That will not work you have to set it using the method.
lyr.setDefinitionExpression("alertPriority = 'Low'");
Thanks Robert, that makes sense.