Open derekeder opened 1 year ago
There is an alternative library that does mapping with vector tiles called MapLibre: https://maplibre.org/maplibre-gl-js/docs/
It looks to be a fork of mapbox-gl and has many of the same features. The biggest difference that I can tell so far is mapbox gives easier access to nice looking vector tile basemaps.
ArcGIS offers some vector tile basemaps of their own and have documentation on how to use them with maplibre: https://developers.arcgis.com/maplibre-gl-js/maps/change-the-basemap-style-v2/
I have my first working map using Mapbox-GL: https://ilsolarmap.com/
The map code is here:
I implemented using plain javascript with bootstrap and jquery. The map features:
Things to note / differences with Leaflet:
layout
, source
, type
and paint
for styling. Instead of using onEachFeature (which I imagine is pretty inefficient for larger data), we set the style based on attributes passed in to the layer directly: https://docs.mapbox.com/mapbox-gl-js/api/map/#map#addlayerid
property needs to be added to each GeoJSON feature at the same level as properties
. This ID must be a number (I tired unique strings but it didnt work)Next steps:
this blog post might be a good place to research mapbox + react? https://evilmartians.com/chronicles/how-to-build-a-better-react-map-with-pigeon-maps-and-mapbox
this tool was used in that post, seems kind of interesting: https://pigeon-maps.js.org/ from their docs:
Are you tired of waiting 3 seconds to parse 200kb of Google Maps JavaScript just to display a few tiles and a marker? 140kb of minified Leaflet too much?
Welcome to the club!
you can use other basemaps, including raster ones:
@antidipyramid is doing this for a DPD project, has positive first impressions.
Background
We've been using Leaflet.js and CARTO for our interactive maps for many years now. After working on a side project that leverages mapbox-gl and kepler.gl (https://ilsolarmap.com), I see there are some potentially big advantages to making maps with Mapbox-GL, including:
Our current pattern for rendering GeoJSON data has some pretty hard limits. Anything over 1mb or with over 1,000 features starts to get very slow in Leaflet. In this case, we have switched over to CARTO to render large files, but the switch can be awkward and the plan we are on has limited space and the latest plans are 10x more expensive. If Mapbox GL works out, we can potentially drop our dependence on CARTO and serve all of our map data directly in the browser.
Proposal
I'll create a test project using Mapbox-GL following their tutorials & documentation with some larger data: https://docs.mapbox.com/mapbox-gl-js/guides/
I will also try out a project using React Map GL, a React wrapper for Mapbox GL: https://visgl.github.io/react-map-gl/
Deliverables
I'll summarize my experience and findings and share them back on this thread along with a recommendation on next steps.
Timeline
Probably a day or so