Skip to content

Commit

Permalink
examples(FileSource): add exemples of FileSource instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
mgermerie authored and gchoqueux committed Dec 2, 2021
1 parent 21317b4 commit 7db9bcb
Show file tree
Hide file tree
Showing 5 changed files with 380 additions and 4 deletions.
18 changes: 14 additions & 4 deletions examples/config.json
Expand Up @@ -28,19 +28,29 @@
"vector_tile_dragndrop": "Drag and drop a style"
},

"Source / Stream": {
"WFS source": {
"source_stream_wfs_25d": "WFS to 2.5D objects",
"source_stream_wfs_3d": "WFS to 3D objects",
"source_stream_wfs_raster": "WFS to raster"
},

"Source / File": {
"Specific source options": {
"source_file_from_format": "format",
"source_file_from_methods": "fetcher and parser"
},

"FileSource": {
"source_file_geojson_raster": "GeoJSON to raster",
"source_file_geojson_3d": "GeoJSON to 3D objects",
"source_file_kml_raster": "KML to raster",
"source_file_gpx_raster": "GPX to raster",
"source_file_gpx_3d": "GPX to 3D objects",
"source_file_shapefile": "Shapefile to raster"
"source_file_gpx_3d": "GPX to 3D objects"
},

"Customize FileSource": {
"source_file_from_fetched_data": "Handle fetching step",
"source_file_from_parsed_data": "Handle parsing step",
"source_file_shapefile": "Shapefile case"
},

"Effects": {
Expand Down
90 changes: 90 additions & 0 deletions examples/source_file_from_fetched_data.html
@@ -0,0 +1,90 @@
<html>
<head>
<title>Itowns - FileSource - Handle fetching step</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">
/* global itowns, setupLoadingScreen, GuiTools, ToolTip */



// ---------- CREATE A GlobeView : ----------

// Define camera initial position
const placement = {
coord: new itowns.Coordinates('EPSG:4326', 3.05, 48.95),
range: 70000,
};

// `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
const viewerDiv = document.getElementById('viewerDiv');

// Instantiate iTowns GlobeView
const view = new itowns.GlobeView(viewerDiv, placement);

// Setup loading screen and debug menu
setupLoadingScreen(viewerDiv, view);
const debugMenu = new GuiTools('menuDiv', view);



// ---------- DISPLAY CONTEXTUAL DATA : ----------

// 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(debugMenu.addLayerGUI.bind(debugMenu));
});



// ---------- DEFINE DATA SOURCE FROM FETCHED DATA : ----------

// Handle fetching step.
// Should you implement a custom fetcher, it would need to be called here.
itowns.Fetcher.json(
'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/lyon-roads.geojson',
).then((fetched) => {
// Then, create a FileSource, passing it the data just fetched. We also need to specify the `format` or the
// `parser` parameter so that iTowns knows which parser it can use.
const sourceFromFetchedData = new itowns.FileSource({
fetchedData: fetched,
crs: 'EPSG:4326',
format: 'application/json',
});

view.addLayer(new itowns.ColorLayer('Roads', {
source: sourceFromFetchedData,
style: new itowns.Style({
stroke: { color: 'yellow' },
}),
})).then(debugMenu.addLayerGUI.bind(debugMenu));
});



view.addEventListener(itowns.GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, function () {
// Organize the order with which layers are superposing.
itowns.ColorLayersOrdering.moveLayerToIndex(view, 'Ortho', 0);
// Move the camera to visualize all data.
view.controls.lookAtCoordinate(view.getLayerById('Roads').source.extent, false);
});

</script>
</body>
</html>
85 changes: 85 additions & 0 deletions examples/source_file_from_format.html
@@ -0,0 +1,85 @@
<html>
<head>
<title>Itowns - Source - format</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">
/* global itowns, setupLoadingScreen, GuiTools, ToolTip */



// ---------- CREATE A GlobeView : ----------

// Define camera initial position
const placement = {
coord: new itowns.Coordinates('EPSG:4326', 3.05, 48.95),
range: 70000,
};

// `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
const viewerDiv = document.getElementById('viewerDiv');

// Instantiate iTowns GlobeView
const view = new itowns.GlobeView(viewerDiv, placement);

// Setup loading screen and debug menu
setupLoadingScreen(viewerDiv, view);
const debugMenu = new GuiTools('menuDiv', view);



// ---------- DISPLAY CONTEXTUAL DATA : ----------

// 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(debugMenu.addLayerGUI.bind(debugMenu));
});



// ---------- DEFINE DATA SOURCE SPECIFYING ITS FORMAT : ----------

const sourceFromFormat = new itowns.FileSource({
url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/lyon-ZU.geojson',
crs: 'EPSG:4326',
format: 'application/json',
});

view.addLayer(new itowns.ColorLayer('Urban Area', {
source: sourceFromFormat,
style: new itowns.Style({
fill: { color: 'red', opacity: 0.5 },
stroke: { color: 'red' },
}),
})).then(debugMenu.addLayerGUI.bind(debugMenu));



// ---------- REORDER ColorLayers AND MOVE CAMERA : ----------

view.addEventListener(itowns.GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, function () {
// Organize the order with which layers are superposing.
itowns.ColorLayersOrdering.moveLayerToIndex(view, 'Ortho', 0);
// Move the camera to visualize all data.
view.controls.lookAtCoordinate(sourceFromFormat.extent, false);
});

</script>
</body>
</html>
87 changes: 87 additions & 0 deletions examples/source_file_from_methods.html
@@ -0,0 +1,87 @@
<html>
<head>
<title>Itowns - Source - fetcher and parser</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">
/* global itowns, setupLoadingScreen, GuiTools, ToolTip */



// ---------- CREATE A GlobeView : ----------

// Define camera initial position
const placement = {
coord: new itowns.Coordinates('EPSG:4326', 3.05, 48.95),
range: 70000,
};

// `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
const viewerDiv = document.getElementById('viewerDiv');

// Instantiate iTowns GlobeView
const view = new itowns.GlobeView(viewerDiv, placement);

// Setup loading screen and debug menu
setupLoadingScreen(viewerDiv, view);
const debugMenu = new GuiTools('menuDiv', view);



// ---------- DISPLAY CONTEXTUAL DATA : ----------

// 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(debugMenu.addLayerGUI.bind(debugMenu));
});



// ---------- DEFINE DATA SOURCE SPECIFYING FETCHER AND PARSER METHODS : ----------

const sourceFromFetcherAndParser = new itowns.FileSource({
url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/lyon-hydro.geojson',
crs: 'EPSG:4326',
// Specify fetcher and parser methods. Should you implement some custom ones, they would need to be called here.
fetcher: itowns.Fetcher.json,
parser: itowns.GeoJsonParser.parse,
})

view.addLayer(new itowns.ColorLayer('Hydro', {
source: sourceFromFetcherAndParser,
style: new itowns.Style({
fill: { color: 'cyan', opacity: 0.5 },
stroke: { color: 'blue',},
}),
})).then(debugMenu.addLayerGUI.bind(debugMenu));



// ---------- REORDER ColorLayers AND MOVE CAMERA : ----------

view.addEventListener(itowns.GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, function () {
// Organize the order with which layers are superposing.
itowns.ColorLayersOrdering.moveLayerToIndex(view, 'Ortho', 0);
// Move the camera to visualize all data.
view.controls.lookAtCoordinate(sourceFromFetcherAndParser.extent, false);
});

</script>
</body>
</html>

0 comments on commit 7db9bcb

Please sign in to comment.