Coder Social home page Coder Social logo

geojson-to-image's Introduction

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/[email protected]'
            },
            "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

geojson-to-image's People

Contributors

tristen avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

geojson-to-image's Issues

confused about map ID and access token

I have a json with a lot of type features present and i wish to use this geojson-to-image to download the images. The code is, however, asking me to provide an access token and map ID, I have provided it my public access token but I don't know what to put in map ID because I haven't created this Json file on Mapbox, so it is not a 'tileset' and doesn't have a map ID.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.