Skip to content

Commit

Permalink
examples(orthographic camera): add examples of PlanarView with an ort…
Browse files Browse the repository at this point in the history
…hographic camera
  • Loading branch information
mgermerie authored and gchoqueux committed Jan 18, 2021
1 parent 05fb79f commit d58c1b6
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 9 deletions.
3 changes: 2 additions & 1 deletion examples/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"misc_clamp_ground": "Clamp 3d object to ground",
"misc_camera_animation": "Camera animation",
"misc_compare_25d_3d": "Compare 2.5D and 3D maps",
"misc_georeferenced_images": "Georeferenced image"
"misc_georeferenced_images": "Georeferenced image",
"misc_orthographic_camera": "Orthographic camera"
},

"Plugins": {
Expand Down
98 changes: 98 additions & 0 deletions examples/misc_orthographic_camera.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>

<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="description">
Key bindings
<ul>
<li>Left-Click : camera translation (drag)</li>
<li>Spacebar / Wheel-Click : smart travel</li>
<li>Mouse Wheel : zoom in/out</li>
<li>Y : move camera to start position</li>
</ul>
</div>
<div id="viewerDiv"></div>
<span id="divScaleWidget"> Scale </span>

<script src="../dist/itowns.js"></script>
<script src="../dist/debug.js"></script>
<script src="js/GUI/LoadingScreen.js"></script>
<script src="js/GUI/GuiTools.js"></script>
<script src="js/Scale.js"></script>
<script type="text/javascript">
/* global itowns, setupLoadingScreen, GuiTools, debug */

itowns.proj4.defs(
'EPSG:3946',
'+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 ' +
'+towgs84=0,0,0,0,0,0,0 +units=m +no_defs'
);

// define geographic extent : CRS, min/max X, min/max Y
const extent = new itowns.Extent(
'EPSG:3946',
1837816.94334, 1847692.32501,
5170036.45870, 5178412.82698,
);

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

// instantiate PlanarView with an orthographic camera
const view = new itowns.PlanarView(viewerDiv, extent, {
cameraType: itowns.CAMERA_TYPE.ORTHOGRAPHIC,
});
setupLoadingScreen(viewerDiv, view);

// add a WMS imagery source
const wmsImagerySource = new itowns.WMSSource({
extent: extent,
name: 'Ortho2009_vue_ensemble_16cm_CC46',
url: 'https://download.data.grandlyon.com/wms/grandlyon',
version: '1.3.0',
crs: 'EPSG:3946',
format: 'image/jpeg',
});
// add a WMS imagery layer
const wmsImageryLayer = new itowns.ColorLayer('wms_imagery', {
source: wmsImagerySource,
});
view.addLayer(wmsImageryLayer);

// Initialize scale :
const initialScaleSize = 200; // in pixel
const divScaleWidget = document.getElementById('divScaleWidget');
function updateScaleWidget() {
let computedScale = roundPixelsFromMeters(view, initialScaleSize);
let format = getMetersUnit(computedScale.meters);
divScaleWidget.innerHTML = `${format.distance} ${format.unit}`;
divScaleWidget.style.width = `${computedScale.pixels}`;
}
// Updates scale when needed :
view.addEventListener(itowns.VIEW_EVENTS.INITIALIZED, function () {
// eslint-disable-next-line no-console
console.info('View initialized');
updateScaleWidget();
});
view.addEventListener(itowns.PLANAR_CONTROL_EVENT.MOVED, function () {
updateScaleWidget();
})
// request redraw
view.notifyChange();

// add `Controls` menu
if (view.isDebugMode) {
const menu = new GuiTools('menuDiv', view);
debug.createTileDebugUI(menu.gui, view);
}
</script>
</body>
</html>
11 changes: 3 additions & 8 deletions examples/view_2d_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,12 @@
// Instanciate PlanarView
// By default itowns' tiles geometry have a "skirt" (ie they have a height),
// but in case of orthographic we don't need this feature, so disable it
var view = new itowns.PlanarView(viewerDiv, extent, { disableSkirt: true, maxSubdivisionLevel: 10, placement: { tilt: 90 },
var view = new itowns.PlanarView(viewerDiv, extent, { disableSkirt: true, maxSubdivisionLevel: 10,
cameraType: itowns.CAMERA_TYPE.ORTHOGRAPHIC,
controls: {
// We do not want the user to zoom out too much
maxAltitude: 40000000,
// We want to keep the rotation disabled, to only have a view from the top
enableRotation: false,
// Faster zoom in/out speed
zoomInFactor: 0.5,
zoomInFactor: 1,
zoomOutFactor: 0.5,
// Don't zoom too much on smart zoom
smartZoomHeightMax: 100000,
},
});

Expand Down

0 comments on commit d58c1b6

Please sign in to comment.