UNPKG

itowns

Version:

A JS/WebGL framework for 3D geospatial data visualization

152 lines (134 loc) 7.28 kB
<html> <head> <title>Itowns - Globe + color layers from vector data</title> <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"> <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script> </head> <body> <div id="viewerDiv" class="viewer"></div> <script src="js/GUI/GuiTools.js"></script> <script src="../dist/itowns.js"></script> <script src="../dist/debug.js"></script> <script src="js/GUI/LoadingScreen.js"></script> <script src="js/plugins/FeatureToolTip.js"></script> <script type="text/javascript"> // # Simple Globe viewer /* global itowns, setupLoadingScreen, GuiTools, ToolTip */ // Define initial camera position var placement = { coord: new itowns.Coordinates('EPSG:4326', 3.5, 44), range: 1000000, } // `viewerDiv` will contain iTowns' rendering area (`<canvas>`) var viewerDiv = document.getElementById('viewerDiv'); // Instanciate iTowns GlobeView* var view = new itowns.GlobeView(viewerDiv, placement); var menuGlobe = new GuiTools('menuDiv', view); setupLoadingScreen(viewerDiv, view); FeatureToolTip.init(viewerDiv, view); // Add one imagery layer to the scene // 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).then(function _() { menuGlobe.addLayerGUI.bind(menuGlobe); itowns.ColorLayersOrdering.moveLayerToIndex(view, 'Ortho', 0); }); }); // 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).then(menuGlobe.addLayerGUI.bind(menuGlobe)); } itowns.Fetcher.json('./layers/JSONLayers/WORLD_DTM.json').then(addElevationLayerFromConfig); itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addElevationLayerFromConfig); // Display the content of a GeoJSON on terrain with ColorLayer and FileSource. // The GeoJSON is loaded from url, set in FileSource // Declare the source for the data on Ariege area const ariegeSource = new itowns.FileSource({ url: 'https://raw.githubusercontent.com/gregoiredavid/france-geojson/master/departements/09-ariege/departement-09-ariege.geojson', crs: 'EPSG:4326', format: 'application/json', }); // Create a ColorLayer for the Ariege area const ariegeLayer = new itowns.ColorLayer('ariege', { name: 'ariege', transparent: true, source: ariegeSource, style: new itowns.Style({ fill: { color: 'orange', opacity: 0.5, }, stroke: { color: 'white', }, }), }); // Add the Ariege ColorLayer to the view and grant it a tooltip view.addLayer(ariegeLayer).then(FeatureToolTip.addLayer); // Display the content of a GeoJSON on terrain with ColorLayer and FileSource. // The GeoJSON content is fetched from the file, then parsed and finally passed into FileSource data. // The process is decomposed so that the fetching and parsing steps are visible. // Fetch data from the GeoJSON file. // Should you implement a custom fetcher, it would need to be called here. itowns.Fetcher.json( 'https://raw.githubusercontent.com/gregoiredavid/france-geojson/master/departements/66-pyrenees-orientales/departement-66-pyrenees-orientales.geojson' ).then(function _(geojson) { // Parses the fetched data into an itowns FeatureCollection. // See http://www.itowns-project.org/itowns/docs/#api/Base/FeatureCollection. // Should you implement a custom parser, it would need to be called here. // The second parameter of the `parse` method we use here defines options for the transformation from // data to FeatureCollection. return itowns.GeoJsonParser.parse(geojson, { // Information on the fetched data. // See http://www.itowns-project.org/itowns/docs/#api/Source/ParsingOptions. in: { crs: 'EPSG:4326', }, // Information on the FeatureCollection that should be created from the fetched data // Here, we pass a FeatureBuildingOptions (http://www.itowns-project.org/itowns/docs/#api/Base/FeatureBuildingOptions) out: { crs: view.tileLayer.extent.crs, buildExtent: true, mergeFeatures: true, structure: '2d', }, }); }).then(function _(features) { // Create a FileSource from the parsed FeatureCollection. var pyoSource = new itowns.FileSource({ features }); var pyoStyle = new itowns.Style({ fill: { pattern: 'images/cross.png', opacity: 0.8, }, stroke: { color:'IndianRed', }, }); // Create a ColorLayer to display the FeatureCollection. var pyoLayer = new itowns.ColorLayer('pyrenees-orientales', { name: 'pyrenees-orientales', transparent: true, source: pyoSource, style: pyoStyle, }); return view.addLayer(pyoLayer); }).then(FeatureToolTip.addLayer).then(() => { // Center the camera on the data extents const layersExtent = ariegeSource.extent.clone(); layersExtent.union(view.getLayerById('pyrenees-orientales').source.extent); view.controls.lookAtCoordinate(layersExtent, false); }); debug.createTileDebugUI(menuGlobe.gui, view); </script> </body> </html>