Giter Club home page Giter Club logo

geojson-to-gpx's Introduction

Hi there ๐Ÿ‘‹

geojson-to-gpx's People

Contributors

bokolob avatar dwayneparton avatar github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

geojson-to-gpx's Issues

Adaptation to node & React Native

Readme.md says "Designed to be a browser library...", however given the lack of deps and straightforward code I tried to adapt this lib to also my React Native app (using @xmldom/xmldom) and with a little modification it worked. Therefore should work also with Node.js.

What I had to do was to change just a few things:

  • ...document.implementation.createDocument('http://www.topografix.com/GPX/1/1', '');to allow for DI of the DOMImplementation (from xmldom or browser depending on the runtime env)
  • Change 3 instances of xxx.append() to be xxx.appendChild()which xmldom supports. First change straightforward, the 2 latter in the form of wpts.forEach((wpt) => gpx.appendChild(wpt));

xlmns handling bug

GPX that is created has a bug, which is not bothering all parsers but some (e.g. Garmin Connect) which are more strict and refuse to parse it. The bug is because xlmns attribute is handled incorrectly and depending on browser (esp. Firefox) results in invalid GPX string after XML-serialization: either xlmns attribute is missing in gpx element and / or there is an extra xlmns="" attribute in other elements.

Ref old Firefox bug report that helped to find the root cause & fix: Bugzilla: xlmns dropped

Fix (I can prepare PR later if desired):

//const gpx = doc.createElement('gpx');
const gpx = createElementWithNS('gpx');
//gpx.setAttribute('xmlns', 'http://www.topografix.com/GPX/1/1');

function createElementWithNS(tagName: string): Element {
	return doc.createElementNS('http://www.topografix.com/GPX/1/1', tagName);
}

and replace all other occurrences of doc.createElement() in the code with createElementWithNS().

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.