Issue Setting Layer Definition on Feature Layer

09-12-2017 07:03 PM
New Contributor III

Hi everyone,

I have an app that pulls in an AGOL feature layer which contains nearly 15000 features.  I would like the app to do two things, the second I already have setup, it's the first that I can't figure out.

1.  I need the page to pull in only certain features that meet a specified definition query.  Which doesn't seem to work.  I tried using this example Feature layer with layer definition applied | ArcGIS API for JavaScript 3.21 however when I pull the feature in, the definition set doesn't hold, thus it returns features that I know don't meet the query.

2. This could be causing issue one, but I'm not sure.  Later in the JS I have another function that sets another definition expression on the same layer, which doesn't contain the original definition.  This part works, but as stated, the first definition doesn't work.  Is this actually overriding the first query?

For example, say I have 1000 features that are in the state of SC among a feature layer that contains all 50 states.  Those same features in SC have an attribute for county.  What I want to be able to do is, when the page loads using FeatureLayer Mode SNAPSHOT, ONLY pull into memory the state of SC, then later in the code set another expression to get only those in a particular county.  Thus in the end, only return the features in SC in X county.   This page always works in SC, thus I just wanna set that at the top, then do a more dynamic query later in the code for varying counties. 

Is this possible?



0 Kudos
2 Replies
MVP Esteemed Contributor


  What you are wanting is definitely possible. Can you share how you are adding the second sql portion to your existing definition expression?

0 Kudos
Regular Contributor

As far as I know there's only one definition expression so the way to handle this is to create and maintain a single definition expression.  I would guess that you should be appending the second definition expression to the first, separated by an AND.

As your needs get more complicated, sometimes it makes sense to write code that keeps track of your definition expression in some other format (say, an array of strings or a Set) and every time that variable is modified, you'll recalculate your entire definition expression.  This lets you add and remove clauses in your defintion expression easily.

0 Kudos