Model attribute query
Click the floor model to display the model name and other related attributes.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Model attribute query</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"/>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
#floorName {
position: absolute;
top: 20px;
left: 20px;
color: #000000;
font-weight:bold;
}
</style>
<script src="https://delivery.mapmost.com/cdn/sdk/webgl/v9.16.0/mapmost-webgl-min.js"></script>
</head>
<body>
<div id="map"></div>
<div id="floorName"></div>
<script>
let map = new mapmost.Map({
container: 'map',
style: "<your style url>",
center: [120.69647280968667, 31.35628749488366],
zoom: 18,
pitch: 60,
bearing: -7.200086687507338,
userId: '***', // Authorization code
env3D: {
exposure: 2.0,
envMap: '../example_data/hdr/WhiteBG_Ref_1K.hdr'
}
});
let THREE = mapmost.THREE;
map.on('load', function () {
let modelLayer, selectedObj;
let models_obj = [{
type: 'glb',
url: "../example_data/house.glb"
}];
const center = [120.69647280968667, 31.35628749488366];
let options = {
id: 'model_id',
type: 'model',
callback: function (group, layer) {
modelLayer = layer;
// add house
layer.addModel(models_obj, center);
}
};
map.addLayer(options);
// click event
map.on('click', function (e) {
if (modelLayer) {
selectObj(e.point)
}
});
function selectObj(point) {
let intersect = modelLayer.selectModel(point)[0];
// Calculate the objects that intersect with the extraction ray
// If there is an intersection, highlight it.
if (intersect) {
let nearestObject = intersect.object;
// The selected layer is not the previously selected layer
if (!(selectedObj === nearestObject.parent)) {
_remove();
const floor = nearestObject.parent.name;
// Whether it is the selected layer
selectedObj = nearestObject.parent;
selectedObj.traverse(function (child) {
if (child instanceof THREE.Mesh) {
// Store the original material into custom properties
child.baseMaterial = child.material;
//Copy the original material and modify the color
child.material = child.material.clone();
child.material.color = new THREE.Color(0xffff00);
}
});
//Show floors here
const info = document.getElementById('floorName');
info.innerText = 'This is:' + floor;
info.style.display = 'block';
}
} else {
_remove();
}
}
function _remove() {
if (selectedObj) {
selectedObj.traverse(function (child) {
child.material = child.baseMaterial;
});
selectedObj = undefined;
}
const info = document.getElementById('floorName');
info.style.display = 'none';
}
})
</script>
</body>
</html>