datamade / how-to

📚 Doing all sorts of things, the DataMade way
MIT License
89 stars 12 forks source link

Document Maplibre patterns #339

Open derekeder opened 1 year ago

derekeder commented 1 year ago

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

derekeder commented 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/

derekeder commented 1 year ago

I have my first working map using Mapbox-GL: https://ilsolarmap.com/

Screen Shot 2023-08-04 at 10 35 42 AM

The map code is here:

I implemented using plain javascript with bootstrap and jquery. The map features:

Things to note / differences with Leaflet:

smcalilly commented 1 year ago

Next steps:

smcalilly commented 1 year ago

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!

fgregg commented 10 months ago

you can use other basemaps, including raster ones:

https://docs.mapbox.com/mapbox-gl-js/example/map-tiles/

smcalilly commented 10 months ago

@antidipyramid is doing this for a DPD project, has positive first impressions.