Show the attributes of a clicked PLATEAU building¶
Listing the attributes of the clicked PLATEAU Taito building with viewer.pick and getFeatureProperties.
plateau_show_attributes.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Show the attributes of a clicked PLATEAU building</title>
<meta property="og:description" content="Listing the attributes of the clicked PLATEAU Taito building with viewer.pick and getFeatureProperties." />
<script src="./v0.10.7/mapray.min.js"></script>
<script src="./v0.10.7/maprayui.min.js"></script>
<link rel="stylesheet" href="./v0.10.7/mapray.css">
<style>
body {margin: 0; padding: 0;}
html, body, div#mapray-container { height: 100%; }
.map-overlay {
font: 12px/20px "Robot", sans-serif;
position: absolute;
width: 300px;
top: 0;
left: 0;
padding: 10px;
}
.map-overlay .map-overlay-inner {
background-color: #fff;
color: #000;
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
border-radius: 3px;
padding: 10px;
margin-bottom: 10px;
}
.map-overlay-inner fieldset {
border: none;
padding: 0;
margin: 0 0 10px;
}
.map-overlay-inner fieldset:last-child {
margin: 0;
}
.map-overlay-inner label {
display: block;
font-weight: bold;
margin: 0 0 5px;
}
.map-overlay-inner select, .map-overlay-inner input[type=range] {
width: 100%;
}
.attribute_table {
max-height: 50vh;
overflow-y: auto;
word-break: break-all;
}
.attribute_table td {
vertical-align: top;
padding: 0 4px 0 0;
}
.attribute_table td:first-child {
color: #666;
width: 45%;
}
</style>
</head>
<body>
<div id="mapray-container"></div>
<div class="map-overlay top">
<div class="map-overlay-inner">
<fieldset>
<label>Picked building</label>
<div id="attribute_table" class="attribute_table">Click a building</div>
</fieldset>
</div>
</div>
</body>
</html>
<script>
// Lists the attributes of the clicked Taito building. Highlighting a feature is a separate sample.
// The attribute whose value is a long JSON text, and the internal ones that start with an underscore, are left out.
function showAttributes( properties ) {
const container = document.getElementById( 'attribute_table' );
container.innerHTML = "";
if ( !properties ) {
container.textContent = "Nothing was picked";
return;
}
const table = document.createElement( "table" );
for ( const key of Object.keys( properties ).sort() ) {
const value = properties[key];
if ( key.startsWith( "_" ) || key === "attributes" || value === undefined || value === null ) continue;
const row = table.insertRow();
row.insertCell().textContent = key;
row.insertCell().textContent = typeof value === "object" ? JSON.stringify( value ) : String( value );
}
container.appendChild( table );
}
// StandardUIViewer subclass that shows the attributes of the clicked building.
class Tiles3DAttributeViewer extends maprayui.StandardUIViewer {
onMouseUp( point, event ) {
super.onMouseUp( point, event );
const pick_result = this.viewer.pick( point );
if ( !pick_result || pick_result.category !== mapray.Viewer.Category.TILES_3D ||
!pick_result.tile_content || pick_result.tile_feature_id === undefined ) {
showAttributes( null );
return;
}
const content = pick_result.tile_content;
showAttributes( content.getFeatureProperties( pick_result.tile_feature_id ) ?? null );
}
}
const cloudApi = new mapray.cloud.CloudApiV2({
tokenType: mapray.cloud.CloudApi.TokenType.ACCESS_TOKEN,
token: "<YOUR_MAPRAY_ACCESS_TOKEN>"
});
// The StandardUIView in the ui package includes mouse-based camera manipulation.
const uiviewer = new Tiles3DAttributeViewer( "mapray-container", {
dem_provider: new mapray.StandardDemProvider( cloudApi.getDefaultDemAsResource() )
} );
// Around Asakusa in Tokyo JP
uiviewer.setCameraPosition({
longitude: 139.7955,
latitude: 35.7085,
height: 500
});
// Senso-ji
uiviewer.setLookAtPosition({
longitude: 139.7967,
latitude: 35.7148,
height: 30
});
// PLATEAU Taito-ku buildings, LOD2 without textures (OGC 3D Tiles 1.1: glTF content with EXT_structural_metadata)
const provider = new mapray.StandardTiles3DProvider({
url: "https://assets.cms.plateau.reearth.io/assets/89/471b74-c5ca-4673-afaa-c194d18b5c8c/13106_taito-ku_city_2025_citygml_1_op_bldg_3dtiles_lod2_no_texture/tileset.json"
}, {
// PLATEAU tiles carry no copyright string, so credit the dataset as the PLATEAU terms of use require (Public Data License 1.0, compatible with CC BY 4.0).
attributions: [ "出典:「3D都市モデル(Project PLATEAU)台東区(2025年度)」(国土交通省)" ]
});
uiviewer.viewer.b3d_collection.createTiles3DScene(provider, {
show_attributions: true,
vertical_offset: -37 // ellipsoidal height to elevation (geoid undulation around Tokyo)
});
</script>
Info
このサンプルコードは、<YOUR_MAPRAY_ACCESS_TOKEN>を、あなたのMapray CloudのアカウントのOrganization Tokenに置き換えるまで、期待通りに動作しません。