geojson-svgify
Convert GeoJSON to virtual-dom <polyline>
nodes using the projection of your choice.
Installation
npm install geojson-svgify
API
svgify(geojson, [options])
geojson
must be an object in the GeoJSON format. options
may have the following keys:
projection
– A function with the signature([longitude, latitude]) => [x, y]
. Default:mercator-projection
computeProps
– A function that will compute the attributes of the<polyline>
element, given the GeoJSON feature. By default, it will add ashape
class
.
Guide
Let's assume you have GeoJSON data.
const geoJSON =
svgify
lets you pass in any projection; The default projection is mercator-projection
. For demonstration purposes, we are not going to project our coordinates:
const myProjection = lon lat
The GeoJSON you pass in will be flattened using geojson-flatten
.
const svgify = const polylines =
polylines
will be an array of virtual-dom <polyline>
nodes. You may want to wrap them in an <svg>
that fits their size:
const bbox = const h = const west south east north = const left top = const right bottom = const width = right - leftconst height = bottom - top const styles = const svg = )
If you want to convert the virtual DOM tree to HTML, use [virtual-dom-stringify
]:
const toHTML = const html =
Contributing
If you found a bug, want to propose a feature or feel the urge to complain about your life, feel free to visit the issues page.