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?
Have to looked at using FeatureLayerView with a FeatureFIlter?
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!
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.
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.
No problem, and that's a cool solution you came up with for a unique situation, thanks for sharing.