itowns
Version:
A JS/WebGL framework for 3D geospatial data visualization
139 lines (114 loc) • 5.41 kB
HTML
<html>
<head>
<title>Itowns - Entwine 3D loader</title>
<script type="importmap">
{
"imports": {
"itowns": "../dist/itowns.js",
"debug": "../dist/debug.js",
"lil": "https://unpkg.com/lil-gui@0.20.0/dist/lil-gui.esm.js",
"GuiTools": "./jsm/GUI/GuiTools.js",
"LoadingScreen": "./jsm/GUI/LoadingScreen.js",
"itowns_widgets": "../dist/itowns_widgets.js",
"three": "https://unpkg.com/three@0.174.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.174.0/examples/jsm/",
"dat": "https://unpkg.com/dat.gui@0.7.9/build/dat.gui.module.js"
}
}
</script>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/example.css">
<link rel="stylesheet" type="text/css" href="css/LoadingScreen.css">
<style type="text/css">
#description {
z-index: 2;
left: 10px;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="description">Specify the URL of a Entwine Point Tree to load:
<input type="text" id="ept_url" />
<button id='readUrlButton'>Load</button>
<p>If your dataset is not displaying at the right location,
check that it has been converted in <code>EPSG:4978</code>.</p>
<div id="share"></div>
</div>
<div id="viewerDiv">
</div>
<script type="module">
// TODO rempa click
import lil from 'lil';
import GuiTools from 'GuiTools';
import setupLoadingScreen from 'LoadingScreen';
import * as THREE from 'three';
import * as itowns from 'itowns';
import * as debug from 'debug';
import * as itowns_widgets from 'itowns_widgets';
var debugGui = new lil();
var viewerDiv = document.getElementById('viewerDiv');
var view = new itowns.GlobeView(viewerDiv);
// Add one imagery layer to the scene and the miniView
// This layer is defined in a json file but it could be defined as a plain js
// object. See Layer* for more info.
itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) {
config.source = new itowns.WMTSSource(config.source);
var layer = new itowns.ColorLayer('Ortho', config);
view.addLayer(layer);
});
// Add two elevation layers.
// These will deform iTowns globe geometry to represent terrain elevation.
function addElevationLayerFromConfig(config) {
config.source = new itowns.WMTSSource(config.source);
var layer = new itowns.ElevationLayer(config.id, config);
view.addLayer(layer);
}
itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addElevationLayerFromConfig);
itowns.Fetcher.json('./layers/JSONLayers/WORLD_DTM.json').then(addElevationLayerFromConfig);
var eptLayer, eptSource;
function onLayerReady() {
var lookAt = new THREE.Vector3();
eptLayer.root.bbox.getCenter(lookAt);
var coordLookAt = new itowns.Coordinates(view.referenceCrs, lookAt);
var size = new THREE.Vector3();
eptLayer.root.bbox.getSize(size);
view.controls.lookAtCoordinate({
coord: coordLookAt,
range: 2 * size.length(),
}, false);
}
function readEPTURL() {
var url = document.getElementById('ept_url').value || new URL(location.href).searchParams.get('ept');
if (url) {
loadEPT(url);
document.getElementById('share').innerHTML = '<a href="' +
location.href.replace(location.search, '?ept=' + url) +
'" target="_blank">Link to share this view</a>';
document.getElementById('ept_url').value = url;
}
}
function loadEPT(url) {
eptSource = new itowns.EntwinePointTileSource({ url });
if (eptLayer) {
debugGui.removeFolder(eptLayer.debugUI);
view.removeLayer('Entwine Point Tile');
view.notifyChange();
eptLayer.delete();
}
eptLayer = new itowns.EntwinePointTileLayer('Entwine Point Tile', {
source: eptSource,
crs: view.referenceCrs,
});
itowns.View.prototype.addLayer.call(view, eptLayer).then(onLayerReady);
debug.PointCloudDebug.initTools(view, eptLayer, debugGui);
}
const readUrlButton = document.getElementById('readUrlButton');
readUrlButton.addEventListener('click', readEPTURL);
readEPTURL();
window.view = view;
window.itowns = itowns;
window.THREE = THREE;
</script>
</body>
</html>