Select to view content in your preferred language

Apply definitionExpression to operationalLayer?

1138
6
Jump to solution
02-19-2021 05:37 AM
JamesCrandall
MVP Frequent Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

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'");

 

 

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

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

 

0 Kudos
JamesCrandall
MVP Frequent Contributor

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?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

James,

   It will be a FeatureLayer if the url you provided ends with the sublayer id (i.e FeatureServer/1 or MapServer/0).

0 Kudos
JamesCrandall
MVP Frequent Contributor

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?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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'");

 

 

JamesCrandall
MVP Frequent Contributor

Thanks Robert, that makes sense.

0 Kudos