A customizable and extendable KML 2.2.0 parser framework
For the time being, kml.js has to be built from source and installed into your project manually.
Future plans include to publish kml.js on npm
.
# Build and pack kml.js to a .tgz archive
npm pack
# Copy .tgz into your project
cp ./bioroxx-kmljs.tgz /path-to-your-project/lib/
# Install in your project
npm install ./lib/bioroxx-kmljs.tgz
import {KMLParser} from '@bioroxx/kmljs';
import {readFileSync} from 'fs';
const kmlFileString = readFileSync('./my-kml-file.kml', 'utf-8');
const kmlParser = new KMLParser();
const kml = kmlParser.parse(kmlFileString);
Because kmljs is built with customization in mind, you can pass your own KMLFactory implementation
to the KMLParser
as a constructor argument. This especially makes sense, if you want the
KMLParser
to create your own KML objects.
import {KMLFactory, PlacemarkType, Placemark, KMLParser} from '@bioroxx/kmljs';
import {readFileSync} from 'fs';
class MyPlacemark extends Placemark {
constructor(placemarkType: PlacemarkType) {
super(placemarkType);
}
render(): void {
// Your rendering code...
}
}
class CustomKMLFactory extends KMLFactory {
override createPlacemark(placemarkType: PlacemarkType): PlacemarkType {
return new MyPlacemark(placemarkType);
}
}
const kmlFileString = readFileSync('./my-kml-file.kml', 'utf-8');
const customKMLFactory = new CustomKMLFactory();
const kmlParser = new KMLParser(customKMLFactory);
const kml = kmlParser.parse(kmlFileString);
- Parsing
-
kml
namespace elements -
atom
namespace elements -
xal
namespace elements
-
- Serialization