Last active
October 22, 2024 15:29
-
-
Save mjumbewu/01d090346fb3013bc2d1b8f5a27e5e89 to your computer and use it in GitHub Desktop.
A Leaflet renderer that will reproject vector layers at each step of an animated transition. This renderer is best when you have relatively few features.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SmoothRenderer = L.SVG.extend({ | |
// Override the default _onZoom function, which simply scales the lower | |
// resolution shapes. Instead, we want to reproject the shapes at each new | |
// zoom level, as is done by default when zooming ends. | |
_onZoom: function () { | |
this._onZoomEnd(); | |
this._update(); | |
} | |
}); | |
/* | |
Update the base renderer to L.Canvas insetad of L.SVG as necessary. | |
Use with the `renderer` option either on `Map` objects or `Path` objects. For | |
example: | |
const map = L.map('map', { renderer: new SmoothRenderer() }).setView([0, 0], 0); | |
Then, when you add vector data to the map and use animated zooming, your vectors | |
will be reprojected at each step, instead of scaled from a low-resolution. | |
const layer = L.geoJSON(...); | |
map.flyTo(layer.getBounds()); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment