0.0.0 • Published 10 years ago

geojson-to-image v0.0.0

Weekly downloads
9
License
ISC
Repository
github
Last release
10 years ago

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

SettingDefault ValueDescription
coordinatescalculatedA lat/lng value for the mapview itself. eg. [-74.50, 40]
zoom2The zoom level of the static map image.
width500The width of the static image returned. Note: within size limits
height500The height of the static image returned. Note: within size limits
qualitypngThe quality of the map image

Tests

npm test