Blend the style color with the texture of PLATEAU buildings¶
Comparing HIGHLIGHT, MIX and REPLACE, which combine the Tiles3DStyle color with the texture of PLATEAU Taito buildings.
plateau_blend_modes.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Blend the style color with the texture of PLATEAU buildings</title>
<meta property="og:description" content="Comparing HIGHLIGHT, MIX and REPLACE, which combine the Tiles3DStyle color with the texture of PLATEAU Taito buildings." />
<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%;
}
</style>
</head>
<body>
<div id="mapray-container"></div>
<div class="map-overlay top">
<div class="map-overlay-inner">
<fieldset>
<label>Blend mode</label>
<label style="font-weight: normal"><input type="radio" name="mode" value="HIGHLIGHT" checked> HIGHLIGHT (multiply the texture)</label>
<label style="font-weight: normal"><input type="radio" name="mode" value="MIX"> MIX (blend with the texture)</label>
<label style="font-weight: normal"><input type="radio" name="mode" value="REPLACE"> REPLACE (ignore the texture)</label>
</fieldset>
<fieldset>
<label>MIX amount: <span id="amount_value"></span></label>
<input id="amount_slider" type="range" min="0" max="1" step="0.05" value="0.5">
</fieldset>
</div>
</div>
</body>
</html>
<script>
// Colors the Taito buildings that are 30 m or taller red, and compares the three ways of combining that color with the texture.
const HEIGHT = "bldg:measuredHeight";
// A missing attribute is undefined in 3D Tiles 1.1 and null in 3D Tiles 1.0, and a comparison with either is a type error.
const present = key => "${" + key + "} !== undefined && ${" + key + "} !== null";
const STYLE = {
color: { conditions: [
[ present( HEIGHT ) + " && ${" + HEIGHT + "} >= 30", "color('#ff3030')" ],
[ "true", "color('#ffffff')" ],
] },
};
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 maprayui.StandardUIViewer( "mapray-container", {
dem_provider: new mapray.StandardDemProvider( cloudApi.getDefaultDemAsResource() ),
atmosphere: new mapray.Atmosphere()
} );
// 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 with 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/75/76c6bc-df54-4bf4-a869-b513526b5bd2/13106_taito-ku_city_2025_citygml_1_op_bldg_3dtiles_lod2/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年度)」(国土交通省)" ]
});
const scene = uiviewer.viewer.b3d_collection.createTiles3DScene(provider, {
show_attributions: true,
vertical_offset: -37 // ellipsoidal height to elevation (geoid undulation around Tokyo)
});
scene.setStyle( mapray.Tiles3DStyle.fromJson( STYLE ) );
const amount_slider = document.getElementById( 'amount_slider' );
function applyMode() {
const mode = document.querySelector( 'input[name="mode"]:checked' ).value;
scene.setStyleColorBlendMode( mapray.Tiles3DScene.StyleColorBlendMode[mode] );
// The amount is used by MIX only: 0 keeps the original color and 1 is the style color.
scene.setStyleColorBlendAmount( Number( amount_slider.value ) );
document.getElementById( 'amount_value' ).textContent = amount_slider.value;
amount_slider.disabled = mode !== "MIX";
}
for ( const radio of document.querySelectorAll( 'input[name="mode"]' ) ) {
radio.addEventListener( 'change', applyMode );
}
amount_slider.addEventListener( 'input', applyMode );
applyMode();
</script>
Info
このサンプルコードは、<YOUR_MAPRAY_ACCESS_TOKEN>を、あなたのMapray CloudのアカウントのOrganization Tokenに置き換えるまで、期待通りに動作しません。