- Notifications
You must be signed in to change notification settings - Fork0
Demonstrations provided with UDSV
License
VCityTeam/UD-Viz-Template
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- How to create your ud-viz based application
- What you will get (for the impatient)
- Skills recommended for building your demo
- Prerequisites
- Basic (npm) project configuration
- Start providing the application JS code
- Create the code bundle by providing a
webpack.config.js
- Import the application bundle into the
index.html
and service the app - Define your application (CSS) style
- Serve your application and access it
- Further UD-Viz material
This repository provides the resulting files that this tutorial helps youto build step by step. You can examine those files and also run the resultingapplication with the following commands
git clone https://github.com/VCityTeam/UD-Viz-template.gitnpm install npx webpack --config webpack.config.jsnode ./bin/server.jsfirefox http://localhost:8000
In order to go through this tutorial you will need to be acquainted with:
git
(repository, branches, fork): refer tothis git gateway- the basics of JavaScript programming. Useful links :MDN docs (browser), andW3School tutorial (node.js).
- Make a quick survey of whatthe UD-Viz framework is about.
You will need to install the following tools
- npm (refer tohere for some quick guidelines)
First setup your npmenvironnement, that is a set of configuration filesassembled together to form/define your application
Create a new directory folder (for example named
my-demo
), in order to holdall the files constituting your new web application:mkdir my-demo
Connect to that directory
cd my-demo
Initialize your npm project with the help of the
npm init
scaffolding command. You should obtain a defaultpackage.json
file:npm init -y
Install (still with the help of the'npm' command) thewebpack andwebpack-cliutilities. The
--save-dev
flags will update your newly createdpackage.json
with adevDependencies
entry. This goesnpm install webpack webpack-cli --save-dev
Edit the
package.json
file and- remove the"main"entry
- instead add a"private": trueentry
Create an
index.html
(blank template) file with the following content<!DOCTYPE html><html><head><metacharset="UTF-8"><title>Title of the document</title></head><body>Content of the document......</body></html>
Create a
src
sub-directory as placeholder for your JavaScript code.mkdir my-demo/src
Provide JS code to the
src
sub-directory. For this you can startconstructing your own code by taking some inspiration out of theud-viz examplesprovided with theud-viz
library.In the following we shall extract the bare content out of theud-viz/examples/point_cloud_visualizer.html.
You should first create an empty
index.js
file within thesrc
sub-directory. Then copy the content of the<script type="text/javascript">
section out of theud-viz/examples/point_cloud_visualizer.html file and paste it to the newlycreated index.js` file.Modify
index.js
in the following manner:- Suppress the
udviz
variable: this is because theudviz
variable is onlyuseful when ud-viz is imported as a bundle in the context of the libraryexample. You then need to further edit theindex.js
file in order toremove all theudviz.
prefixes occurrences.For example the initialudviz.loadMultipleJSON(...)
should simply becomeloadMultipleJSON(...)
andudviz.itowns.Extent(...)
should becomeitowns.Extent(...)
. - Because many function or classes were previously imported by the ud-vizbundle, you must now import those function or classes through the standardES6 Module. You should do this for all the following function classes:
- loadMultipleJSON
- proj4
- PointCloudVisualizer
- LayerChoice
- Bookmark
- ColoLayer, Extent, WMSSource, ElevationLayer, STRATEGY_DICHOTOMY
You should obtain an
index.js
looking like this.- Suppress the
A couple remarks about the content of the resulting
index.js
:import xxx from 'xxx'
is used to import modules (=code, assets ...). The notion of module is very important in Javascript I advise you to readthe MDN doc guide.document
is a variable that is part of your browser's web API, it allows you to add / retrieve / delete / create (html elements) in yourDOM.To see the contents of this variable go to your browser's console on the web page of your choice and typedocument
.The
document.body
contains theHTML body element of your DOM. It corresponds to the<body>
tag of theindex.html.The function takes as parameters:FIXME LIGNE 16 a config in the form of ajavascript object
FIXEME LIGNE 57
app.itownsView
, aniTowns.View
provided by iTowns, creates the html element that contains the 3D scene (camera, renderer...). Seeitowns doc.FIXME LIGNE 22 an
itowns.Extent
. The geographical boundaries. Seeitowns doc.You may notice that you don't have to create the
PlanarView
andExtent
since they are already built into yourapp
instance FIXME LIGNE 32 of thePointCloudVisualizer
class. You might want to check out the source ofPointCloudVisualizer
in order to get a better understanding of what is implicitly provided under the hood.
Retrieve all the configuration files loaded by the call to
loadMultipleJSON(...)
, that are located in theexamples/assets/config/
subdirectory and place their respective copy inmy-demo/assets/
.This boils down to the following commands:git clone https://github.com/VCityTeam/UD-Viz.gitexport UDVIZ_SRC=`pwd`/UD-Vizmkdir -p my-demo/assets/config/layercd my-demo/assetscp$(UDVIZ_SRC)/examples/assets/config/extents.json.cp$(UDVIZ_SRC)/examples/assets/config/crs.json.cp$(UDVIZ_SRC)/examples/assets/config/layer/elevation.json config/layer/cp$(UDVIZ_SRC)/examples/assets/config/layer/base_maps.json config/layer/cp$(UDVIZ_SRC)/examples/assets/config/layer/3DTiles_point_cloud.json config/layer/
Don't forget to
npm install --save
your npm package dependencies. Forexample if you considered theud-viz/examples/point_cloud_visualizer.htmlas base example (that isdeployed here) then you will need tonpm install @ud-viz/point_cloud_visualizernpm install @ud-viz/widget_layer_choicenpm install @ud-viz/widget_bookmark
The above instructions should add new entries in the
dependencies
sectionof yourpackage.json.
- Note that
itowns
andproj4
should be provided automatically as peer dependencies (for example see thepoint cloud visualizer package.json) and do not need to be installed through npm.
Troubleshooting the above dependencies installation: when the installationof the dependencies do error, you might consider
- clearing your npm cache with
npm cache clean --force
, - removing any previous package installations with
rm -fr node_modules
- removing the pinned package versions with
rm package-lock.json
.
- Note that
Create first
webpack.config.js
with the following basic content:constpath=require('path');module.exports={entry:'./src/index.js',output:{filename:'bundle.js',path:path.resolve(__dirname,'dist'),},};
Because of an erroneous package resolution (refer tothis note together withthat note),manually install the
buffer
packagenpm install buffer
As explained below, the point-cloud-visualizer example code imports a(CSS) style. For webpack to be able todeal with that style
- do install the following loaders
npm install style-loader css-loader --save-dev
- Inform
webpack.config.js
of the existence of those loaders by addingamodule
entry[...]module.exports={[...]output:{[...]},module:{rules:[{test:/\.css/,use:['style-loader','css-loader'],},],},};
- do install the following loaders
Eventually create the code bundle with the command
npx webpack --config webpack.config.js
The resulting bundle should now exist in the form of themy-demo/dist/bundle.js
file.
Create a<script>
section in yourindex.html
file in order to allow forthe bundle importation:
[...]</head><scriptsrc='./dist/bundle.js'></script>[...]<body>[...]
You now need to provide a(CSS) style toyour application.
For this you can
- copy the style related entries of the original example
ud-viz/examples/point_cloud_visualizer.html
, that is the linesin order to paste them into the[...]<head> [...]<linkrel="stylesheet"href="./assets/css/examples.css"/><linkrel="stylesheet"href="./assets/css/point_cloud_visualizer.css"/><linkrel="stylesheet"href="./assets/css/widget_layer_choice.css"/><linkrel="stylesheet"href="./assets/css/widget_bookmark.css"/><linkrel="stylesheet"href="./assets/css/loading_screen.css"/> [...]</head>
<head>
section of newly createdindex.html
file. - you then need to copy the corresponding
css
files out ofexamples/assets/cssof the ud-viz examples, which can be done with the following commandscd my-democp$(UDVIZ_SRC)/examples/assets/css/examples.css assets/css/cp$(UDVIZ_SRC)/examples/assets/css/point_cloud_visualizer.css assets/css/cp$(UDVIZ_SRC)/examples/assets/css/widget_layer_choice.css assets/css/cp$(UDVIZ_SRC)/examples/assets/css/widget_bookmark.css assets/css/cp$(UDVIZ_SRC)/examples/assets/css/loading_screen.css assets/css/
Create an http server that will serve themy-demo
which be done e.g. withexpress.
To do this create a file called./bin/server.js
and add the following content to it:
// Code adapted from https://www.npmjs.com/package/expressconstpath=require('path');constexpress=require('express')constapp=express()app.use(express.static(path.resolve(__dirname,'../')));app.listen(8000)
Install express
npm install express --save-dev
To start an express server using this script, run the following code:
node ./bin/server.js
You can now access your web application by web-browsing the URL returned by theabove command (http://localhost:8000
).
In order to quickly learn more about of what you can achieve with UD-Viz,you might wish to ead the differentexamples together withthe developers documentation and try to transpose tools, widgets, code snippet to your application.
About
Demonstrations provided with UDSV