Listening for the vector layer features' events
When working with vector layers, it is common to find a situation where you need to respond to something that's occurred on the layer, such as when a new feature is added, modified, deleted, and so on. Fortunately, these types of events are available from the vector source, and we can easily subscribe to them.
The goal of this recipe is to show you how simple it is to listen for events on a vector source and perform some actions with this information.
We are going to load an external GeoJSON file of geometry points, and we will style the fill color and radius depending on the feature attributes. We will also track how many features are on the vector source layer and allow the user to delete a feature by clicking on it, subsequently updating the feature count. The source code can be found in ch04/ch04-vector-feature-events
, and here's what we'll end up with:
How to do it…
In order to understand how vector layer feature...