geojson-to-image

0.0.0 • Public • Published

GeoJSON to Image

Build Status

Pass GeoJSON and return an image from Mapbox Static API. Currently, only markers are supported.

Usage

var geojsonToImage = require('geojsonToImage');
 
var geojson = {
    "type": "FeatureCollection",
    "features": [ 
        {
            "type": "Feature",
            "properties": {
            "marker-color": '#a3e46b',
            "marker-size": 'large',
            "marker-symbol": 'triangle'
        },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -79.39712047576904,
                    43.62669447164394
                ]
            }
        },
        {
            "type": "Feature",
            "properties": {
                "marker-url": 'https://raw.githubusercontent.com/tristen/vintages/gh-pages/img/marker@2x.png'
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -87.63072967529297,
                    41.874673839758
                ]
            }
        }
    ]
}
 
var image = geojsonToImage({
    'mapID': 'username.mapid',
    'accessToken': '<your access token here>'
}, geojson);
 
// Returns
// https://api.tiles.mapbox.com/v4/tristen.map-4s93c8qx/pin-l-triangle+A3E46B(-79.39712047576904,43.62669447164394),url-https%3A%2F%2Fraw.githubusercontent.com%2Ftristen%2Fvintages%2Fgh-pages%2Fimg%2Fmarker%402x.png(-87.63072967529297,41.874673839758)/-79.39712047576904,41.874673839758,2/500x500.png?access_token=pk.eyJ1IjoiZmFsbHNlbW8yIiwiYSI6IjhsbHFBMkEifQ.OMXud5BW3OAF-_usSJjy0Q
 

Marker result

API

geojsonToImage(authentication, geojson, options)

authentication

Takes an object with two required keys: accessToken & mapID.

{
    'mapID': 'username.mapid',
    'accessToken': '<your access token here>'
}

geojson

Takes a valid geojson object. Not passing a geojson object results in a blank map.

options

Setting Default Value Description
coordinates calculated A lat/lng value for the mapview itself. eg. [-74.50, 40]
zoom 2 The zoom level of the static map image.
width 500 The width of the static image returned. Note: within size limits
height 500 The height of the static image returned. Note: within size limits
quality png The quality of the map image

Tests

npm test

Readme

Keywords

Package Sidebar

Install

npm i geojson-to-image

Weekly Downloads

9

Version

0.0.0

License

ISC

Last publish

Collaborators

  • tristen