{"id":17369788,"url":"https://github.com/juliuste/geojson-svgify","last_synced_at":"2025-04-08T03:34:47.409Z","repository":{"id":57249880,"uuid":"67946988","full_name":"juliuste/geojson-svgify","owner":"juliuste","description":"Convert GeoJSON geometry paths to SVG polyline elements.","archived":false,"fork":false,"pushed_at":"2022-10-11T10:45:47.000Z","size":102,"stargazers_count":17,"open_issues_count":4,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-23T04:41:16.261Z","etag":null,"topics":["library"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juliuste.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-11T18:28:05.000Z","updated_at":"2024-03-24T13:29:33.000Z","dependencies_parsed_at":"2022-09-01T04:12:36.982Z","dependency_job_id":null,"html_url":"https://github.com/juliuste/geojson-svgify","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fgeojson-svgify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fgeojson-svgify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fgeojson-svgify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fgeojson-svgify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juliuste","download_url":"https://codeload.github.com/juliuste/geojson-svgify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247772938,"owners_count":20993627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library"],"created_at":"2024-10-16T00:13:52.808Z","updated_at":"2025-04-08T03:34:47.055Z","avatar_url":"https://github.com/juliuste.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# geojson-svgify\n\n**Convert [GeoJSON](http://geojson.org/) to [virtual-dom](https://github.com/Matt-Esch/virtual-dom#virtual-dom) `\u003cpolyline\u003e` nodes** using the projection of your choice.\n\n[![npm version](https://img.shields.io/npm/v/geojson-svgify.svg)](https://www.npmjs.com/package/geojson-svgify)\n[![Build Status](https://travis-ci.org/juliuste/geojson-svgify.svg?branch=master)](https://travis-ci.org/juliuste/geojson-svgify)\n[![Greenkeeper badge](https://badges.greenkeeper.io/juliuste/geojson-svgify.svg)](https://greenkeeper.io/)\n[![dependency status](https://img.shields.io/david/juliuste/geojson-svgify.svg)](https://david-dm.org/juliuste/geojson-svgify)\n[![dev dependency status](https://img.shields.io/david/dev/juliuste/geojson-svgify.svg)](https://david-dm.org/juliuste/geojson-svgify#info=devDependencies)\n[![license](https://img.shields.io/github/license/juliuste/geojson-svgify.svg?style=flat)](LICENSE)\n[![chat on gitter](https://badges.gitter.im/juliuste.svg)](https://gitter.im/juliuste)\n\n## Installation\n\n```shell\nnpm install geojson-svgify\n```\n\n## API\n\n```\nsvgify(geojson, [options])\n```\n\n`geojson` must be an object in the [GeoJSON format](http://geojson.org/). `options` may have the following keys:\n\n- `projection` – A function with the signature `([longitude, latitude]) =\u003e [x, y]`. Default: [`mercator-projection`](https://github.com/zacbarton/node-mercator-projection#readme)\n- `computeProps` – A function that will compute the attributes of the `\u003cpolyline\u003e` element, given the GeoJSON feature. By default, it will add a `shape` `class`.\n\n## Guide\n\nLet's assume you have GeoJSON data.\n\n```js\nconst geoJSON = require('path/to/geojson-file.json')\n```\n\n`svgify` lets you pass in any [projection](https://en.wikipedia.org/wiki/Map_projection); **The default projection is [`mercator-projection`](https://github.com/zacbarton/node-mercator-projection#readme)**. For demonstration purposes, we are *not* going to project our coordinates:\n\n```js\nconst myProjection = ([lon, lat]) =\u003e [lon, lat]\n```\n\nThe GeoJSON you pass in will be flattened using [`geojson-flatten`](https://github.com/mapbox/geojson-flatten#geojson-flatten).\n\n```js\nconst svgify = require('geojson-svgify')\n\nconst polylines = svgify(geoJSON, {projection: myProjection})\n```\n\n**`polylines` will be an array of [virtual-dom](https://github.com/Matt-Esch/virtual-dom#virtual-dom) `\u003cpolyline\u003e` nodes.** You may want to wrap them in an `\u003csvg\u003e` that fits their size:\n\n```js\nconst bbox = require('@turf/bbox')\nconst h = require('virtual-hyperscript-svg')\n\nconst [west, south, east, north] = bbox(geojson)\n\nconst [left, top] = myProjection([west, north])\nconst [right, bottom] = myProjection([east, south])\nconst width = right - left\nconst height = bottom - top\n\nconst styles = h('style', {}, `\n\t.shape {\n\t\tstroke: #f60;\n\t\tstroke-width: .05;\n\t\tfill: none;\n\t}\n`)\n\nconst svg = h('svg', {\n    width: Math.abs(width) * 100,\n    height: Math.abs(height) * 100,\n    viewBox: [left, top, width, height].join(',')\n}, [].concat(styles, polylines))\n```\n\nIf you want to convert the virtual DOM tree to HTML, use [`virtual-dom-stringify`]:\n\n```js\nconst toHTML = require('virtual-dom-stringify')\nconst html = toHTML(svg)\n```\n\n## Contributing\n\nIf 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](https://github.com/juliuste/geojson-svgify/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliuste%2Fgeojson-svgify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliuste%2Fgeojson-svgify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliuste%2Fgeojson-svgify/lists"}