View layer from FeatureLayer

734
5
01-30-2021 02:16 PM
cgrove
by
New Contributor II

I have a page (ArcGIS API for JavaScript 4.18) that creates and displays a client side FeatureLayer, which shows dynamic data that is edited every 30 seconds or so with applyEdits. Everything works great with that.

Is there a way to create a "view" of that FeatureLayer, that shows up as a second layer in the TOC? The view layer needs to have all the same data as the original FL, but I want to apply a different definition query.

An example of this is showing current transit bus locations, where the original FL contains all of the bus locations, but only shows features that have been updated within the last hour. I need a view layer that uses the original FLs data, but lets me set a definition query to only show features that are older than an hour. I'm trying to not have to maintain edits on two Feature Layers.

Is this possible?

0 Kudos
5 Replies
by Anonymous User
Not applicable

Have to looked at using FeatureLayerView  with a FeatureFIlter

0 Kudos
cgrove
by
New Contributor II

Jeff,

I am aware of FeatureLayerView and have looked at it in the API. I'm not sure from the description and sample how to implement it from an existing FL, and also how I can add that to the layer list as a toggle-able item. I will look more into it today, but it doesn't appear to be able to meet the second requirement.

Thanks for the reply!

0 Kudos
by Anonymous User
Not applicable

Sometimes the JS API docks can get frustrating with the lack of examples or the repeated use of the basemap example.  Anyway, I created a codepen for this to create a filtered 'view' between two dates on top of the complete featurelayer and is toggled in a layer list.  If your applyEdits is saving back to the service, could you create a second alternative-named variable FeatureLayer just for the view?  Check out the pen, maybe it can give you some ideas.

LayerViewFilter 

cgrove
by
New Contributor II

Thanks for making that codepen to demonstrate. Actually my FeatureLayers are completely client-based, with no FeatureService or server interaction. GeoJSON data (add/remove/delete) comes in, and I add/update/delete all on the client side.

I figured out a reasonable solution using a secondary empty FeatureLayer as a placeholder in TOC, watching its visible property, then change the source layer's definitionExpression based on whether the placeholder layer is visible or not. It seems to work well enough for now, but I'd really like to be able to have a better way. Though, I'm probably only one of a few devs creating a FeatureLayer and applying edits that's totally disconnected from a FeatureService or PortalItem.

0 Kudos
by Anonymous User
Not applicable

No problem, and that's a cool solution you came up with for a unique situation, thanks for sharing.

0 Kudos