Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@brakebein/osm-static-maps

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@brakebein/osm-static-maps

Create a static image of a map with the features you want

  • 3.11.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

osm-static-maps

Openstreetmap static maps is a Node.js lib, CLI and server open source inspired on Google static map service.

How to use

1. CLI

sudo npm i -g osm-static-maps
osmsm --help
osmsm -g '{"type":"Point","coordinates":[-105.01621,39.57422]}' > map.png
  • note: if you have this error trying to install globally Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/osm-static-maps/node_modules/puppeteer/.local-chromium', it's caused by this pupeteer issue https://github.com/puppeteer/puppeteer/issues/367, you can workaround by installing globally with the unsafe-perm flag:
sudo npm i -g osm-static-maps --unsafe-perm=true

2. Node.js library

npm install osm-static-maps
// index.js old school
const { osmsm } = require('osm-static-maps');
osmsm({geojson: geojson})
  .then(function(imageBinaryBuffer) { ... })
  .catch(function(error) { ... });

// index.js modern style (also supports typescript)
import { osmsm } from 'osm-static-maps';
const imageBinaryBuffer = await osmsm({geojson});

3. Standalone sample server

sudo npm i -g osm-static-maps
osmsm serve

Or you can use docker-compose

git clone git@github.com:jperelli/osm-static-maps.git
cd osm-static-maps
docker-compose up

API Reference

All parameters have a short and long version. The short version can be used only with the shell CLI. The long version can be used with the library and can be passed to the app server as GET query params, or POST json body (remember to set the header Content-Type: application/json)

ParameterDescriptionDefault Value
ggeojsongeojson object to be rendered in the mapundefined
fgeojsonfilefilename or url to read geojson data from (use '-' to read from stdin on CLI)undefined
Hheightheight in pixels of the returned img600
Wwidthheight in pixels of the returned img800
ccentercenter of the map lon,lat floats string(center of the geojson) or '-57.9524339,-34.921779'
zzoomzoomlevel of the leaflet mapif vectorserverUrl available, use 12 else 20
ZmaxZoommax zoomlevel of the leaflet map17
Aattributionattribution legend'osm-static-maps / © OpenStreetMap contributors'
ttileserverUrlurl of a tileserver'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
mvectorserverUrlurl of a vector tile server (MVT style.json)undefined
MvectorserverTokentoken of the vector tile server (MVT)'no-token'
DrenderToHtmlreturns html of the webpage containing the map (instead of a binary image)false
Ftypeformat of the image returned ('jpeg'/'png')'png'
qqualityquality of the image returned (0-100, only for jpg)100
ximageminenable lossless compression with optipng / jpegtranfalse
aarrowsrender arrows to show the direction of linestringsfalse
sscaleenable render a scale ruler (boolean or a json options object)false
Ttimeoutmiliseconds until page load throws timeout20000
kmarkerIconOptionsset marker icon options (a json options object) *see noteundefined (leaflet's default marker)
Sstylestyle to apply to each feature (a json options object) *see noteundefined (leaflet's default)
ehaltOnConsoleErrorthrow error if there is any console.error(...) when rendering the map imagefalse
  • Note on markerIconOptions: it's also accepted a markerIconOptions attribute in the geojson feature, for example
{"type":"Point","coordinates":[-105.01621,39.57422],"markerIconOptions":{"iconUrl":"https://leafletjs.com/examples/custom-icons/leaf-red.png"}}
  • Note on style: it's also accepted a pathOptions attribute in the geojson feature, for example
{"type":"Polygon","coordinates":[[[-56.698,-36.413],[-56.716,-36.348],[-56.739,-36.311]]],"pathOptions":{"color":"#FF5555"}}
  • also remember that the # char needs to be passed as %23 if you are using GET params

Design considerations & architecture

Read the blogpost on the creation of this library and how it works internally.

LICENSE

  • GPLv2

Credits

Specially to the contributors of

  • OpenStreetMap
  • Leaflet
  • Puppeteer
  • ExpressJS
  • Handlebars

FAQs

Package last updated on 30 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc