itowns
Version:
A JS/WebGL framework for 3D geospatial data visualization
89 lines (78 loc) • 4.04 kB
HTML
<!-- Update menu with colors layers really displayed in viewer -->
<html>
<head>
<title>Itowns - Color layers Visible</title>
<script type="importmap">
{
"imports": {
"itowns": "../dist/itowns.js",
"debug": "../dist/debug.js",
"dat": "https://unpkg.com/dat.gui@0.7.9/build/dat.gui.module.js",
"GuiTools": "./jsm/GUI/GuiTools.js",
"LoadingScreen": "./jsm/GUI/LoadingScreen.js",
"itowns_widgets": "../dist/itowns_widgets.js",
"three": "https://unpkg.com/three@0.170.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.170.0/examples/jsm/"
}
}
</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">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="viewerDiv"></div>
<script type="module">
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';
/* global itowns,document,GuiTools, setupLoadingScreen */
var placement = {
coord: new itowns.Coordinates('EPSG:4326', 2.351323, 48.856712),
range: 25000000,
}
// iTowns namespace defined here
var viewerDiv = document.getElementById('viewerDiv');
var view = new itowns.GlobeView(viewerDiv, placement);
var menuGlobe = new GuiTools('menuDiv', view);
setupLoadingScreen(viewerDiv, view);
function addColorLayerFromConfig(config) {
config.source = new itowns.WMTSSource(config.source);
var layer = new itowns.ColorLayer(config.id, config);
layer.visible = true;
view.addLayer(layer).then(menuGlobe.addLayerGUI.bind(menuGlobe));
}
function addElevationLayerFromConfig(config) {
config.source = new itowns.WMTSSource(config.source);
var layer = new itowns.ElevationLayer(config.id, config);
view.addLayer(layer).then(menuGlobe.addLayerGUI.bind(menuGlobe));
}
itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(addColorLayerFromConfig);
itowns.Fetcher.json('./layers/JSONLayers/Cada.json').then(addColorLayerFromConfig);
itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addElevationLayerFromConfig);
itowns.Fetcher.json('./layers/JSONLayers/WORLD_DTM.json').then(addElevationLayerFromConfig);
view.addEventListener(itowns.GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, function _() {
// eslint-disable-next-line no-console
console.info('Globe initialized');
// Open folder color
menuGlobe.colorGui.closed = false;
});
// Use frame requester to update menu before rendering
view.addFrameRequester(itowns.MAIN_LOOP_EVENTS.BEFORE_RENDER, function _() {
var displayedLayers = view.tileLayer.info.displayed.layers;
var allLayers = view.getLayers(function a(l) { return l.isColorLayer || l.isElevationLayer; });
allLayers.forEach(function b(layer) {
menuGlobe.colorLayerFolder(layer.id, displayedLayers.find(displayedLayer => displayedLayer.id == layer.id) ? 'rgb(57, 167, 57)' : 'rgb(255, 125, 125)');
});
});
window.view = view;
window.itowns = itowns;
window.THREE = THREE;
</script>
</body>
</html>