|
| 1 | +<html> |
| 2 | + <head> |
| 3 | + <title>Itowns - Globe + color layers from vector data</title> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <link rel="stylesheet" type="text/css" href="css/example.css"> |
| 6 | + <link rel="stylesheet" type="text/css" href="css/LoadingScreen.css"> |
| 7 | + |
| 8 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 9 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script> |
| 10 | + </head> |
| 11 | + <body> |
| 12 | + <div id="viewerDiv" class="viewer"></div> |
| 13 | + <script src="js/GUI/GuiTools.js"></script> |
| 14 | + <script src="../dist/itowns.js"></script> |
| 15 | + <script src="../dist/debug.js"></script> |
| 16 | + <script src="js/GUI/LoadingScreen.js"></script> |
| 17 | + <script src="js/plugins/FeatureToolTip.js"></script> |
| 18 | + <script type="text/javascript"> |
| 19 | + // # Simple Globe viewer |
| 20 | + /* global itowns, setupLoadingScreen, GuiTools, ToolTip */ |
| 21 | + |
| 22 | + // Define initial camera position |
| 23 | + var placement = { |
| 24 | + coord: new itowns.Coordinates('EPSG:4326', 6.8, 45.9), |
| 25 | + } |
| 26 | + |
| 27 | + // `viewerDiv` will contain iTowns' rendering area (`<canvas>`) |
| 28 | + var viewerDiv = document.getElementById('viewerDiv'); |
| 29 | + |
| 30 | + // Instanciate iTowns GlobeView* |
| 31 | + var view = new itowns.GlobeView(viewerDiv, placement); |
| 32 | + var menuGlobe = new GuiTools('menuDiv', view); |
| 33 | + |
| 34 | + setupLoadingScreen(viewerDiv, view); |
| 35 | + FeatureToolTip.init(viewerDiv, view); |
| 36 | + |
| 37 | + // Add one imagery layer to the scene |
| 38 | + // This layer is defined in a json file but it could be defined as a plain js |
| 39 | + // object. See Layer* for more info. |
| 40 | + itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) { |
| 41 | + config.source = new itowns.WMTSSource(config.source); |
| 42 | + var layer = new itowns.ColorLayer('Ortho', config); |
| 43 | + view.addLayer(layer).then(function _() { |
| 44 | + menuGlobe.addLayerGUI.bind(menuGlobe); |
| 45 | + itowns.ColorLayersOrdering.moveLayerToIndex(view, 'Ortho', 0); |
| 46 | + }); |
| 47 | + }); |
| 48 | + // Add two elevation layers. |
| 49 | + // These will deform iTowns globe geometry to represent terrain elevation. |
| 50 | + function addElevationLayerFromConfig(config) { |
| 51 | + config.source = new itowns.WMTSSource(config.source); |
| 52 | + var layer = new itowns.ElevationLayer(config.id, config); |
| 53 | + view.addLayer(layer).then(menuGlobe.addLayerGUI.bind(menuGlobe)); |
| 54 | + } |
| 55 | + itowns.Fetcher.json('./layers/JSONLayers/WORLD_DTM.json').then(addElevationLayerFromConfig); |
| 56 | + itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addElevationLayerFromConfig); |
| 57 | + |
| 58 | + // Fetch, Parse and Convert by iTowns |
| 59 | + var kmlSource = new itowns.FileSource({ |
| 60 | + url: 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_month_depth.kml', |
| 61 | + crs: 'EPSG:4326', |
| 62 | + format: 'application/kml', |
| 63 | + }); |
| 64 | + |
| 65 | + function offset(properties) { |
| 66 | + const sizeIcon = 64; |
| 67 | + const scaleIcon = properties['icon-scale']; |
| 68 | + return [ 0, -0.5 * scaleIcon * sizeIcon ]; |
| 69 | + } |
| 70 | + |
| 71 | + var kmlStyle = new itowns.Style({ |
| 72 | + zoom: { min: 10, max: 20 }, |
| 73 | + text: { |
| 74 | + field: '{name}', |
| 75 | + haloColor: 'black', |
| 76 | + haloWidth: 1, |
| 77 | + color: 'white', |
| 78 | + offset: offset, |
| 79 | + anchor: 'bottom', |
| 80 | + }, |
| 81 | + }); |
| 82 | + |
| 83 | + var kmlLayer = new itowns.ColorLayer('Kml', { |
| 84 | + source: kmlSource, |
| 85 | + style: kmlStyle, |
| 86 | + addLabelLayer: true, |
| 87 | + }); |
| 88 | + |
| 89 | + debug.createTileDebugUI(menuGlobe.gui, view); |
| 90 | + |
| 91 | + view.addLayer(kmlLayer).then(FeatureToolTip.addLayer); |
| 92 | + </script> |
| 93 | + </body> |
| 94 | +</html> |
0 commit comments