Skip to content

An API for creating static images of maps using leaflet and puppeteer

Notifications You must be signed in to change notification settings

smcllns/static-map-images

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Leaflet Static Images Service

Goal: API endpoint to get static images of maps.

Alternatives | Shortcoming

  1. Mapbox static images service | 50K requests/mo free but then $1/1,000 requests (maybe caching makes this scale better but unclear what their caching policy is)
  2. Headless Leaflet | Running node-canvas requires installing deps that requires I set up containers (was looking for something I could run in a lambda function)

Trying another approach:

  1. Render the map in a browser, setting map properties through url parameters (public/index.html)
  2. Launch with Puppeteer and return a screenshot (api/screenshot.js)

Note: this is using browserless.io which is paid but is quicker to run puppeteer (can make that cheaper later), and I can permanently cache the images unlike Mapbox.

Dev

  1. Needs .env file:
BROWSERLESSTOKEN=xxx
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
(see _db.js for Firebase env vars required)
  1. npm run i

Deploy

vercel

About

An API for creating static images of maps using leaflet and puppeteer

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published