• Stars
    star
    147
  • Rank 251,347 (Top 5 %)
  • Language
    JavaScript
  • License
    GNU General Publi...
  • Created about 11 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Openstreetmap static maps is a nodejs lib, CLI and server open source inspired on google static map service

osm-static-maps

Openstreetmap static maps is a nodejs lib, CLI and server open source inspired on google static map service

Here you have a demo. Also a dynamic version of the demo, for testing purposes.

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 puppeteer/puppeteer#367, you can workaround by installing globally with the unsafe-perm flag:
sudo npm i -g osm-static-maps --unsafe-perm=true

2. nodejs library

npm install osm-static-maps
// index.js old school
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 [email protected]:jperelli/osm-static-maps.git
cd osm-static-maps
docker-compose up

4. Cloud service

You can use the heroku-hosted alternative directly here

We are currently in the cloud beta, contact me directly at [email protected] so I can give you access to the cloud service.

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)

Parameter Description Default Value
g geojson geojson object to be rendered in the map undefined
f geojsonfile filename or url to read geojson data from (use '-' to read from stdin on CLI) undefined
H height height in pixels of the returned img 600
W width height in pixels of the returned img 800
c center center of the map lon,lat floats string (center of the geojson) or '-57.9524339,-34.921779'
z zoom zoomlevel of the leaflet map if vectorserverUrl available, use 12 else 20
Z maxZoom max zoomlevel of the leaflet map 17
A attribution attribution legend 'osm-static-maps / © OpenStreetMap contributors'
t tileserverUrl url of a tileserver 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
m vectorserverUrl url of a vector tile server (MVT style.json) undefined
M vectorserverToken token of the vector tile server (MVT) 'no-token'
D renderToHtml returns html of the webpage containing the map (instead of a binary image) false
F type format of the image returned ('jpeg'/'png') 'png'
q quality quality of the image returned (0-100, only for jpg) 100
x imagemin enable lossless compression with optipng / jpegtran false
X oxipng enable losslsess compression with oxipng false
a arrows render arrows to show the direction of linestrings false
s scale enable render a scale ruler (boolean or a json options object) false
T timeout miliseconds until page load throws timeout 20000
k markerIconOptions set marker icon options (a json options object) *see note undefined (leaflet's default marker)
S style style to apply to each feature (a json options object) *see note undefined (leaflet's default)
e haltOnConsoleError throw error if there is any console.error(...) when rendering the map image false
  • 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

More Repositories

1

vue2-leaflet-markercluster

markercluster plugin extension for vue2-leaflet package
Vue
132
star
2

Redmine-Periodic-Task

A redmine plugin that lets you schedule an issue to fire every x days/weeks/months
Ruby
64
star
3

vue2-leaflet-googlemutant

GoogleMutant plugin extension for vue2-leaflet package
Vue
21
star
4

vue2-leaflet-polylinedecorator

polylinedecorator plugin extension for vue2-leaflet package
Vue
5
star
5

eucovidcert

EU digital covid certificate QR decoder
TypeScript
4
star
6

Constitucion_Argentina

Constitución de la Nación Argentina
3
star
7

run279

TypeScript
3
star
8

vercel-python-gis

Vercel runtime with geos, gdal and proj for geodjango
Python
2
star
9

redmine_print_style_black

A super-simple plugin to change the css style to print in B&W printers
Ruby
2
star
10

redmine_contacter

Redmine plugin to add multiple contacts to an issue. A contact has name, direction and telephones. You manage the contacts in one place, and use them in any project.
SQL
2
star
11

multiplechoiceshuffler

TypeScript
2
star
12

proteccionista-app

proteccionista.org frontend web y mobile
Vue
1
star
13

exponent-react-native-workshop-2

Workshop: Intro to React Native with Exponent - Project 2
JavaScript
1
star
14

cuantosabortos.org

Contador de numeros de abortos en argentina
Vue
1
star
15

Qplanif

Simulador de planificacion de la CPU
C++
1
star
16

cordova-plugin-register-filetype

Register a filetype to be opened with your app when tapping on a file
JavaScript
1
star
17

dolar-notify

mostrar desktop notification cuando el precio del dolar cambia en el banco nacion argentino
JavaScript
1
star
18

jperelli.github.io

Personal website
CSS
1
star
19

cualbondi-issues

1
star
20

notion-jira-link-chrome-extension

Chrome extension that makes jira links in Notion appear as in confluence
JavaScript
1
star
21

proteccionista.org

proteccionista.org API server
JavaScript
1
star