1.1.1 • Published 2 years ago

kml-to-json v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

KML to JSON

About

KML to JSON is a library made with Typescript that contains tools for KML files conversion.

Installing

First, be sure to have Node.js installed.

Then, install it by running:

$ npm install --save kml-to-json

Usage

The library has 4 functions that may be used. They are:

  • kmlToJson

It converts a KML file to a JSON object, keeping all tags names, attributes, texts and children.

Receives a file of the type application/vnd.google-earth.kml+xml or with the extension kml.

It throws an error when the file type is incorrect.

Returns an object containing all KML data with this structure.

kmlToJson(file: File): Object
  • kmlToJsonString

It converts a KML file to a JSON string, representing all tags names, attributes, texts and children.

Receives a file of the type application/vnd.google-earth.kml+xml or with the extension kml.

It throws an error when the file type is incorrect.

Returns a string representing the KML data with this structure.

kmlToJsonString(file: File): string
  • jsonToKml

It converts a JSON object or string to a KML file.

Receives an object or string with this structure.

It throws an error when the given parameter is not from type object or string.

Returns a blob that represents the KML file. Its type is application/vnd.google-earth.kml+xml.

jsonToKml(json: Object | string): Blob
  • jsonToKmlString

It converts a JSON object or string to a structured KML string.

Receives an object or string with this structure.

It throws an error when the given parameter is not from type object or string.

Returns a string that represents the KML string structure.

jsonToKmlString(json: Object | string): string

JSON Structure

{
  "test-tag": {
    "attributes": {
      "attr1": null,
      "attr2": null,
      "class": "class-1",
      "id": "test-tag"
    },
    "children": {
      "child1": {
        "attributes": {},
        "order": 0,
        "children": {
          "child3": {
            "attributes": {
              "attr3": null
            },
            "children": {
              "text0": {
                "data": "Some text...",
                "order": 0
              }
            },
            "order": 0,
          }
        }
      },
      "child2": {
        "attributes": {},
        "order": 1,
        "children": {}
      }
    },
    "order": 0,
  }
}

License

The AsteroidsJS project is licensed under the MIT license.

1.1.1

2 years ago

1.0.2

2 years ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago