Git Product home page Git Product logo

gpx-parser-builder's Introduction

gpx-parser-builder

A simple gpx parser and builder between GPX string and JavaScript object. It is dependent on isomorphic-xml2js.

npm GitHub stars GitHub forks npm GitHub license

Requirements

gpx-parser-builder is written with ECMAScript 6. You can leverage Babel and Webpack to make all browsers available.

Installation

npm install gpx-parser-builder --save

Version

v1.0.0+ is a breaking change for v0.2.2-. v1.0.0+ fully supports gpx files including waypoints, routes, and tracks. Every gpx type is 1-1 corresponding to a JavaScript class.

Usage

import GPX from 'gpx-parser-builder';

// Parse gpx
const gpx = GPX.parse('GPX_STRING');

window.console.dir(gpx.metadata);
window.console.dir(gpx.wpt);
window.console.dir(gpx.trk);

// Build gpx
window.console.log(gpx.toString());

Get more details about usage with the unit tests.

GPX

The GPX JavaScript object.

constructor(object)

const gpx = new Gpx({$:{...}, metadat: {...}, wpt:[{...},{...}]}, trk: {...}, rte: {...})

Member Variables

$ the attributes for the gpx element. Default value:

{
    'version': '1.1',
    'creator': 'gpx-parser-builder',
    'xmlns': 'http://www.topografix.com/GPX/1/1',
    'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
    'xsi:schemaLocation': 'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd'
}

metadata the metadata for the gpx.

wpt array of waypoints. It is corresponded to <wpt>. The type of all elements in wpt is Waypoint;

rte array of routes. It is corresponded to <rte>. The type of all elements in rte is Route;

trk array of tracks. It is corresponded to <trk>. The type of all elements in trk is Track;

Static Methods

parse(gpxString) parse gpx string to Gpx object. return null if parsing failed.

Member Methods

toString(options) GPX object to gpx string. The options is for isomorphic-xml2js.

Save as GPX file in the frontend

You can leverage StreamSaver.js or FileSaver.js to save as GPX file. ⚠️Not all borwsers support the above file techniques. ⚠️️️

Author

Zheng-Xiang Ke, [email protected]

License

gpx-parser-builder is available under the MIT license. See the LICENSE file for more info.

gpx-parser-builder's People

Contributors

kf99916 avatar mschulz-716 avatar

Watchers

James Cloos avatar

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.