npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

geojson-svgify

v0.5.0

Published

Convert GeoJSON geometry paths to SVG polyline elements

Downloads

91

Readme

geojson-svgify

Convert GeoJSON to virtual-dom <polyline> nodes using the projection of your choice.

npm version build status dependency status dev dependency status license

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 a shape class.

Guide

Let's assume you have GeoJSON data.

const geoJSON = require('path/to/geojson-file.json')

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]) => [lon, lat]

The GeoJSON you pass in will be flattened using geojson-flatten.

const svgify = require('geojson-svgify')

const polylines = svgify(geoJSON, {projection: myProjection})

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 = require('@turf/bbox')
const h = require('virtual-hyperscript-svg')

const [west, south, east, north] = bbox(geojson)

const [left, top] = myProjection([west, north])
const [right, bottom] = myProjection([east, south])
const width = right - left
const height = bottom - top

const styles = h('style', {}, `
	.shape {
		stroke: #f60;
		stroke-width: .05;
		fill: none;
	}
`)

const svg = h('svg', {
    width: Math.abs(width) * 100,
    height: Math.abs(height) * 100,
    viewBox: [left, top, width, height].join(',')
}, [].concat(styles, polylines)))

If you want to convert the virtual DOM tree to HTML, use [virtual-dom-stringify]:

const toHTML = require('virtual-dom-stringify')
const html = toHTML(svg)

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.