Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to input a geojson file #23

Closed
benebsiny opened this issue Jan 13, 2020 · 2 comments
Closed

How to input a geojson file #23

benebsiny opened this issue Jan 13, 2020 · 2 comments

Comments

@benebsiny
Copy link

I have a geojson file, and I used fs.read() to get the contents. When I'd like to call the convert function, it showed me that it is undefined, so I wondering how should I the input file correctly.
(geojsonContent is the content of geojson file, it has no problem)

const converter = geojson2svg({
    width: 256,
    height: 256
})

const svgStrings = converter.convert(geojsonContent, {})
console.log(svgStrings);
@gagan-bansal
Copy link
Owner

Parden for late reply, hope your issue was resolved.

Here is an example:

geojson file geojson.json

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [125.6, 10.1]
  },
  "properties": {
    "name": "Dinagat Islands"
  }
}

Sample code with geojson2svg

const geojson2svg = require('geojson2svg')
const fs = require('fs')
const converter = geojson2svg({
  width: 256,
  height: 256
})

fs.readFile('./geojson.json', 'utf8', function(err, data) {
  if (err) throw err
  let geojsonContent = JSON.parse(data)
  let svgStrings = converter.convert(geojsonContent, {})
  console.log(svgStrings);
})
// output
// [ '<path d="M128.00080233528666,127.99993548100002 m-1,0 a1,1 0 1,1 2,0 a1,1 0 1,1 -2,0"/>' ]

@gagan-bansal
Copy link
Owner

Hope issue is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants