Select to view content in your preferred language

definition expression on hosted portal layers?

833
4
Jump to solution
01-30-2024 04:45 PM
TimLohnes1
Regular Contributor

Hi, 

I'm switching my layers over to hosted feature layers on our portal. I have a javascript map that consumes the data and presents the layer differently based on what user's select.

The way I'm currently doing it is changing the definitionExpression on the layer based on selection.

Now when I'm adding a layer from portalItem 

var streetPavingHostedLayer = Layer.fromPortalItem({
      portalItem: {
          // autocasts as new PortalItem()
         id: "xxxxxxxxxxxxxxxxxx",
             portal: {
                 url: "https://xxxxxxxxxxxx/portal"
             }
       }
});
 
The above adds the whole layer. But the below doesn't filter correctly. I can't make heads or tails when I inspect the errors. Doesn't point to my code.
 
Can I add a definition expression, like   definitionExpression: "roadname = 'CHABOT CT'"? I can't get it to work. Wondering if it doesn't work or I'm just formatting the expression wrong.

If I can't do this, wondering if my best bet is to make a different view for each way I want to portray the layer and then just call the layer desired when selected by user?
 
Thanks for any thoughts.
 
-Tim

 

0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor
4 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

That definitionExpression looks valid to me. Is it possible for you to shrare your data with me so I can take a look? The following example works.

 

const view = new MapView({
  container: "viewDiv",
  map: map,
  center: [-122.907, 47.018],
  zoom:12
});

const featureLayer = new FeatureLayer({
  url: "https://data.wsdot.wa.gov/arcgis/rest/services/Shared/LocalAgencyPublicRoadData/FeatureServer/0",
  definitionExpression: "RoadName = 'Columbia St NW'"
});
0 Kudos
TimLohnes1
Regular Contributor

Thanks, @UndralBatsukh The code you showed is how I'm using it now. I'm wondering if using layers created from portal have the same capability of using the definitionExpression? See my code above. Thanks.

Here is an example layer, https://maps.hayward-ca.gov/portal/home/item.html?id=5663a61146c648ca9fd674b58693de47

0 Kudos
UndralBatsukh
Esri Regular Contributor

The definitionExpression does work for your service. Looks like it is a really small road - https://codepen.io/U_B_U/pen/abMYXbG?editors=1000

 

TimLohnes1
Regular Contributor

Awesome. Thanks. Looks a lot simpler the way you are doing it. Perfect.

0 Kudos