dwayneparton / geojson-to-gpx Goto Github PK
View Code? Open in Web Editor NEWA browser library for turning GeoJson into a GPX XMLDocument
Home Page: https://www.npmjs.com/package/@dwayneparton/geojson-to-gpx
A browser library for turning GeoJson into a GPX XMLDocument
Home Page: https://www.npmjs.com/package/@dwayneparton/geojson-to-gpx
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)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));
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()
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.