three-kml-loader
v1.1.0
Published
Cross platform KML loader for three.js. Out of the box usable with react-three-fiber.
Downloads
4
Maintainers
Readme
three-kml-loader
three-kml-loader is a cross platform KML file loader for THREE.js. It takes URL of a KML file as an input and returns THREE.js Object3D entity. This library works out of the box with cross platform react-native and react-three-fiber as well.
Install
yarn add three-kml-loader three
or
npm i three-kml-loader three
Usage
import * as THREE from 'three'
import { KmlLoader } from 'three-kml-loader'
const loader = new KmlLoader();
loader.setColor(0xFF0000);
// loader.setTransform(new THREE.Matrix4());
const scene = new THREE.Scene();
onLoad = (data) => {
scene.add(data);
}
const onError = (error) => {
console.log(error);
}
const onProgress = (xhr) => {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
}
// url = 'http://to/my/kml/file.kml'
loader.load(url, onLoad, onProgress, onError);
API
load(url, onLoad, onProgress, onError)
Takes url of KML file as input and invokes onLoad
when Object3D entity is created. onProgress
and onError
are invokes as per the FileLoader documentation.
parse(kml)
If typeof kml
is string
, it will be parsed to XML DOM. If kml
instanceof XML Node
, reads the specified in-memory kml.
It yields Object3D entity.
parseToGeoJson(kml)
If typeof kml
is string
, it will be parsed to XML DOM. If kml
instanceof XML Node
, reads the specified in-memory kml.
It returns GeoJSON object.