-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples(orthographic camera): add examples of PlanarView with an ort…
…hographic camera
- Loading branch information
Showing
3 changed files
with
103 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters