-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(Widgets): add a searchbar widget
- Loading branch information
Showing
7 changed files
with
473 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,8 @@ | |
"Widgets": [ | ||
"Navigation", | ||
"Minimap", | ||
"Scale" | ||
"Scale", | ||
"Searchbar" | ||
] | ||
}, | ||
"tutorialSections": { | ||
|
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
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,121 @@ | ||
<html> | ||
<head> | ||
<title>Itowns - Searchbar widget</title> | ||
|
||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<link rel="stylesheet" type="text/css" href="css/example.css"> | ||
<link rel="stylesheet" type="text/css" href="css/LoadingScreen.css"> | ||
|
||
<!-- Import stylesheet for itowns Widgets plugin --> | ||
<link rel="stylesheet" type="text/css" href="css/widgets.css"> | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script> | ||
</head> | ||
<body> | ||
<!-- Create a container for itowns viewer --> | ||
<div id="viewerDiv"></div> | ||
|
||
<!-- Import iTowns source code --> | ||
<script src="../dist/itowns.js"></script> | ||
<script src="../dist/debug.js"></script> | ||
<!-- Import iTowns Widgets plugin --> | ||
<script src="../dist/itowns_widgets.js"></script> | ||
<!-- Import iTowns LoadingScreen and GuiTools plugins --> | ||
<script src="js/GUI/LoadingScreen.js"></script> | ||
<script src="js/GUI/GuiTools.js"></script> | ||
|
||
|
||
<script type="text/javascript"> | ||
|
||
|
||
|
||
// ---------- CREATE A GlobeView FOR SUPPORTING DATA VISUALIZATION : ---------- | ||
|
||
// Define camera initial position | ||
const placement = { | ||
coord: new itowns.Coordinates('EPSG:4326', 2.351323, 48.856712), | ||
range: 6000, | ||
tilt: 50, | ||
} | ||
|
||
// `viewerDiv` contains iTowns' rendering area (`<canvas>`) | ||
const viewerDiv = document.getElementById('viewerDiv'); | ||
|
||
// Create a 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's properties are defined in a json file, but it could be | ||
// defined as a plain js object. See `Layer` documentation for more info. | ||
itowns.Fetcher.json('layers/JSONLayers/Ortho.json').then((config) => { | ||
config.source = new itowns.WMTSSource(config.source); | ||
view.addLayer( | ||
new itowns.ColorLayer(config.id, config), | ||
).then(debugMenu.addLayerGUI.bind(debugMenu)); | ||
}); | ||
|
||
// Add two elevation layers, each with a different level of detail. Here again, each layer's properties are | ||
// defined in a json file. | ||
function addElevationLayerFromConfig(config) { | ||
config.source = new itowns.WMTSSource(config.source); | ||
view.addLayer( | ||
new itowns.ElevationLayer(config.id, config), | ||
).then(debugMenu.addLayerGUI.bind(debugMenu)); | ||
} | ||
itowns.Fetcher.json('layers/JSONLayers/WORLD_DTM.json').then(addElevationLayerFromConfig); | ||
itowns.Fetcher.json('layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addElevationLayerFromConfig); | ||
|
||
|
||
|
||
// ---------- ADD SEARCH BAR WIDGET : ---------- | ||
|
||
// Function that should be called when clicking a location suggestion. | ||
function lookAtCoordinate(coordinates) { | ||
view.controls.lookAtCoordinate({ coord: coordinates, range: 20000, tilt: 45, heading: 0 }); | ||
} | ||
|
||
// Define options for geocoding service that should be used by the searchbar. | ||
const geocodingOptions = { | ||
url: new URL( | ||
'https://wxs.ign.fr/ayxvok72rcocdyn8xyvy32og/ols/apis/completion?text=&type=StreetAddress,' + | ||
'PositionOfInterest', | ||
), | ||
// As precised in the doc (http://www.itowns-project.org/itowns/docs/#api/Widgets/Searchbar), the parser | ||
// method must parse the geocoding service response into a Map object. For each item of this Map, the | ||
// key is a string that is displayed in the suggestions bellow the searchbar, and the value is whatever | ||
// the user wants. The value is the parameter that is passed to the `onSelected` method when a | ||
// suggestion is clicked. Here, we se the value as the `Coordinates` associated to the location. | ||
parser: (response) => { | ||
const map = new Map(); | ||
response.results.forEach(location => { | ||
map.set(location.fulltext, new itowns.Coordinates('EPSG:4326', location.x, location.y)); | ||
}); | ||
return map; | ||
}, | ||
onSelected: lookAtCoordinate, | ||
} | ||
|
||
// Create the searchbar | ||
const searchbar = new itowns_widgets.Searchbar(view, geocodingOptions, { | ||
// We want to display at maximum 15 location suggestions when typing the searchbar. | ||
maxSuggestionNumber: 15, | ||
}); | ||
|
||
|
||
|
||
// ---------- DEBUG TOOLS : ---------- | ||
|
||
debug.createTileDebugUI(debugMenu.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
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
Oops, something went wrong.