Coder Social home page Coder Social logo

geojson2svg's People

Contributors

dependabot[bot] avatar gagan-bansal avatar georgemandis avatar m4jing avatar psohm avatar tchak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

geojson2svg's Issues

attributes of svg element are not correct

Attributes of an svg element can be given at two place, one in constructor and other in .convert function.
If given at both places, attributes should be merged at .convert function and output svg string should contain attributes from both.
There is issue only attributes from .convert function are being considered.

Need to be resolved.

SVG precision

There should be option to set the precision after decimal place for numbers in SVG path.

final step?

I'm trying to covert "Null Island.geo.json" to SVG using this tool.
The conversion appears to go well but the svgString is a javascript array.
[ 'M99.99268888888889,49.98556111111111 ...

It is possible to get this output in XML/SVG, especially such that Inkscape can open it?

data display at 180 degree

At dateline i.e. at 180 degree data is not displayed properly. So in example I modified 180 to 179.999999. This need be fixed.

Option to specify the id key

Should have option to specify the id key in feature properties.postcode as

var converter = geojson2svg({attributes: {id: 'properties.postcode'}});

Typescript definition file

Fantastic library!

Any chance you can add a Typescript definition file to the package? I can submit a PR for the following if it looks good to you:

/***
 * https://github.com/gagan-bansal/geojson2svg
 */
declare module 'geojson2svg' {
  import { GeoJSON } from 'geojson'

  export interface ScreenDims {
    width: number
    height: number
  }

  export interface Origin {
    x: number
    y: number
  }

  export interface Extent {
    left: number
    right: number
    bottom: number
    top: number
  }

  export interface StaticAttribute {
    type: 'static'

    /** The output attribute name */
    property: string

    /** The output attribute value */
    value: string
  }

  export interface DynamicAttribute {
    type: 'dynamic'

    /** The geojson source property name holding the output attribute value
     * ... also used as the output attribute name
     */
    property: string

    /** Override the output attribute name */
    key?: string
  }

  export interface ObjectAttributes {
    [key: string]: string
  }

  export interface Options {
    /** viewportSize is object containing width and height in pixels */
    viewportSize?: ScreenDims

    /** Coordinates should be in same projection as of geojson. Default maps extent are of Web Mercator projection (EPSG:3857). */
    mapExtent?: Extent

    /** Output format
     * 'svg' - svg element string is returned like '<path d="M0,0 20,10 106,40"/>'
     * 'path' - path 'd' value is returned 'M0,0 20,10 106,40' a linestring
     */
    output?: 'svg' | 'path'

    /** Fit ouput svg map to width or height. */
    fitTo?: 'width' | 'height'

    /** a number, precision of output svg coordinates. */
    precision?: number

    /** Should multigeojson be exploded to many svg elements or not. default is false. */
    explode?: boolean

    /** Attributes which are required to attach as SVG attributes from features can be passed here as list of path in feature or json object for static attributes */
    attributes?: (StaticAttribute | DynamicAttribute | ObjectAttributes)[] | ObjectAttributes

    /** Return geojson point objects as SVG circle elements. default is false. */
    pointAsCircle?: boolean

    /** radius of point svg element */
    r?: number

    /** function that will be called on every geojson conversion with output string as one input variable */
    callback?: (svgString: string) => void
  }

  export default class g2svg {
    public constructor(options?: Options)
    public convert(geojson: GeoJSON | any, options?: Options): string
  }
}

Zoom in to geojson

Hi,

I have a small route around a town that I am trying to convert to an SVG. How would I expand this to fix the viewport. It is currently a tiny spec.

Thanks,
Rob

defualt viewport size

Set default viewportSize as 256x256.
This will help in aligning the svg map with tile maps that generally have the tile size 256.
Right now viewportSize is must parameter, after setting viewportSize's default value this parameter should move to options. Like shown here
old

var converter = geojson2svg(viewportSize,options)

new

var converter = geojson2svg({
   viewportSize: {width: 256, height: 256},    // this is default
   otherOption: 'value'
});

Add attributes from Geojson to SVG

Hello,

Can we add some attributes from Geojson to SVG, with providing which properties or geometries in Geojson we need to add in SVG, with "geojson2svg"?

render output on canvas

The output i.e. svg path coordinates can also be easily rendered on HTML5 canvas. Add an example for this also.

Dynamic attributes

Thanks for a handy lib! It would be really nice id it was possible to assign attributes depending on some geojson data, either by mapping json attrubites to SVG attributes, or by passing the relevant json attribute to the callback function, so that something like the following was possible:

{"type":"Feature","properties":{"ID":"foo"},"geometry":{"type":"MultiPolygon","coordinates":...

=>

<path data-id="foo" d="...

attributes again

hi @gagan-bansal,

Thanks a lot for the merge. I have one question, currently you allow either attributes by properties or by passing a json object, which mean I can't use both (in my case I need both), could this behavior change to something like

{
    "attributes": {
        static: {"class": "mapstyle"},
        dynamic: ["properties.foo", "properties.bar"]
    }
}

I'm sorry if I didn't mention this earlier, but the other branch used to read the property data and add its content as attributes, which allowed me to use both. I didn't read your source code yet, so I could be missing something.

Thanks!

Coordinate dimensions other than XY fails

It seems like the only coordinate dimensions that work are XY (not e.g. XYZ, XYM). Not sure this that is a bug or a feature not yet implemented. For XYZ- coordinates the script fails with the error TypeError: coordinates.map is not a function at /reproject/index.js:13:22

No possibility to convert Point as circle

It seems there is bug and even pointAsCircle: true returns always path instead of circle.

Problem is in instance.js in convertGeometry line 82 (return jsonToSvgElement(json,geom.type); doesnt call "opt" parameter, so in function jsonToSvgElement variable forcePath is always true.

Now converted result looks like:
<path cx="M611.5267122181064" cy="562.2759809701495 m-5" r="5" />

Expected result:
<circle cx="611.5267122181064" cy="562.2759809701495" r="5" />

default maps extent to web mercator

Change default map extent (mapExtent) to Web Mercator EPSG:3857. As this projection is used most.
mapExtent for this projection.

   {
      left: -20037508.342789244,
      right: 20037508.342789244,
      bottom: -20037508.342789244,
      top: 20037508.342789244
    }

How to input a geojson file

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);

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.