itowns
Version:
A JS/WebGL framework for 3D geospatial data visualization
116 lines (101 loc) • 5.1 kB
HTML
<html>
<head>
<title>Itowns - Displaying Shapefile</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",
"FeatureToolTip": "./jsm/plugins/FeatureToolTip.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';
import FeatureToolTip from 'FeatureToolTip';
// Define initial camera position
var placement = {
coord: new itowns.Coordinates('EPSG:4326', 2.351323, 48.856712),
range: 25000,
}
// `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
var viewerDiv = document.getElementById('viewerDiv');
// Instantiate 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/OPENSM.json').then(function _(config) {
config.source = new itowns.TMSSource(config.source);
var layer = new itowns.ColorLayer('OPENSM', config);
view.addLayer(layer).then(menuGlobe.addLayerGUI.bind(menuGlobe));
});
// As there is no Shapefile fetcher directly bundled within iTowns, we need to specify a method to fetch data.
// We use here `multiple` fetcher, which can fetch multiple files within multiple formats.
itowns.Fetcher.multiple(
'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/shapefile/velib-disponibilite-en-temps-reel',
{
// fetch all files whose name match the `url` parameter value, and whose format is either `shp`,
// `dbf`, `shx` or `prj`.
arrayBuffer: ['shp', 'dbf', 'shx'],
text: ['prj'],
},
).then((fetched) => {
// Once our Shapefile data is fetched, we can parse it by running itowns built-in Shapefile parser.
return itowns.ShapefileParser.parse(fetched, {
// Options indicating how the features should be built from data.
out: {
// Specitfy the crs to convert the input coordinates to.
crs: view.tileLayer.extent.crs,
},
});
}).then((parsed) => {
// We can then instantiate a FileSource, passing the parsed data,
// and create a Layer bound to this source.
const velibSource = new itowns.FileSource({ features: parsed });
return view.addLayer(new itowns.ColorLayer('velib', {
source: velibSource,
style: {
zoom: { min: 10, max: 20 },
point: { color: 'white', line: 'green' },
text: {
field: '{name}\n(id: {station_id})',
size: 14,
haloColor: 'white',
haloWidth: 1,
font: ['monospace'],
}
},
addLabelLayer: true,
}));
}).then((layer => {
// Finally, we generate tooltip for when the mouse hovers the data displayed within our created layer.
FeatureToolTip.addLayer(layer, { filterAllProperties: false });
}));
window.view = view;
window.itowns = itowns;
window.THREE = THREE;
</script>
</body>
</html>