Leaflet / Leaflet/Leaflet.VectorGrid
Refactor Renderers to be more universally useful.
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 676
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
The new concept of a RenderService is introduced. There are two implementations, one for SVG/VML and one for Canvas. A RenderService provides methods for render-method agnostic initialisation and sizing of a target DOM element, drawing and styling of points, paths and polygons and mouse event handling for the generated features. It doesn't extend any class, but can be associated to a Map instance for the purpose of firing events.
The concept of Renderer remains unchanged: it extends Layer and reacts to changes in the map by updating its viewport. There are two implementations of Renderer, one utilising a RenderService for SVG and one for Canvas. A Renderer can be added and removed from a Map or serve as an implicit layer for vector layers added to the Map. It draws vector layers by forwarding their requests to its RenderService. The RenderService fires mouse events at the Layer subclasses as before.
The vector layers such as Polyline and siblings remain unchanged.
For VectorGrid, a Tile is an object that provides a DOM element to act as a map tile. Tile does not extend Layer or any class at all. There are two implementations, one utilising a RenderService for SVG and one for Canvas. A Tile receives its DOM element from its RenderService. The advantage over the current design of using Renderer subclasses for this purpose is that there is no need to work around undesirable actions of Renderer like overriding onAdd() to prevent inserting itself into a map pane, preventing it from reacting to the map's update event by adjusting its viewport or overriding Layer's addTo() method to prevent unnecessary actions like adding attributions or firing events.
For VectorGrid, a TileFeature is an object extending Evented that represents a single feature in a vector-tile. The advantage over the current design of subclassing Polyline and siblings is that there is no need to override code that projects latitude/longitude to screen coordinates, or using private methods of Renderer to do the actual drawing. TileFeatures use Symbolizers for their visual representations, which are rendered by the RenderService associated to their containing Tile. The RenderService fires mouse events at the TileFeature instances, providing access to the vector-tile features from the event handlers.
TileFeatures are added to a Map using the new Map.addInteractiveTarget(Evented, domElement) method.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin by locating the existing Renderer and VectorGrid implementations and the Map event-target entry point. Compare them with the proposed RenderService, Tile, TileFeature, and Symbolizer responsibilities. Done means SVG/VML and Canvas rendering share the new design without changing vector-layer behavior, while interactive tile features receive mouse events.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100