Add a water polygon with cloud api¶
Add a water polygon with Cloud API
add_water_polygon_with_cloud.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Add a water polygon with cloud api</title>
<meta property="og:description" content="Add a water polygon with Cloud API" />
<meta name="mapray-version" content="0.10.1">
<meta name="mapray-api-status" content="experimental">
<script src="./v0.10.6/mapray.min.js"></script>
<script src="./v0.10.6/maprayui.min.js"></script>
<link rel="stylesheet" href="./v0.10.6/mapray.css">
<style>
body {margin: 0; padding: 0;}
html, body, div#mapray-container { height: 100%; }
</style>
</head>
<body>
<div id="mapray-container"></div>
</body>
</html>
<script>
async function main() {
const cloudApi = new mapray.cloud.CloudApiV2({
tokenType: mapray.cloud.CloudApi.TokenType.ACCESS_TOKEN,
token: "<YOUR_MAPRAY_ACCESS_TOKEN>"
});
// Create viewer
const uiviewer = new maprayui.StandardUIViewer( "mapray-container", {
dem_provider: new mapray.StandardDemProvider( cloudApi.getDefaultDemAsResource() ),
atmosphere: new mapray.Atmosphere()
} );
// The default DEM stops at 0 m over the sea; the bay's bathymetry gives the water its depth.
await uiviewer.viewer.dem_layers.add(
new mapray.StandardDemProvider( cloudApi.getDemDatasetAsResource( "5136875538874368" ) ) );
// Setup camera position
uiviewer.setCameraPosition( {
longitude: 139.790512,
latitude: 35.577699,
height: 226.784263,
} );
uiviewer.setLookAtPosition( {
longitude: 139.767058,
latitude: 35.574366,
height: 8.173845,
} );
// Create WaterPolygonEntityVisualizer
const waterPolygonEntityVisualizer = new mapray.WaterPolygonEntityVisualizer();
// Define resources using the Mapray API.
var resource = cloudApi.getDatasetAsResource( "5157340395339776" );
// Load and Add WaterPolygonEntity
mapray.WaterPolygonEntity.loadWaterPolygonGeoJSON(
uiviewer.viewer.scene, [ resource ], {
// Water is always at an absolute height: its depth comes from the
// difference between the surface and whatever is behind it.
altitude_mode: mapray.AltitudeMode.ABSOLUTE,
height: 0,
visualizer: waterPolygonEntityVisualizer,
} );
}
main();
</script>
Info
このサンプルコードは、<YOUR_MAPRAY_ACCESS_TOKEN>を、あなたのMapray CloudのアカウントのOrganization Tokenに置き換えるまで、期待通りに動作しません。