Skip to content

tristen/geojson-to-image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GeoJSON to Image

Build Status

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

Usage

var geojsonToImage = require('geojson-to-image');

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

About

Pass GeoJSON and get an image in return from Mapbox Static API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published