Hello Guys,
Can you please guid me how I implement the 3D Building selection on next js.
Becouse I am using this code but this is not working
“use client”;
import React, { useEffect, useRef, useState } from “react”;
import {
Viewer,
Camera,
CameraFlyTo,
Cesium3DTileset,
} from “resium”;
import {
Cartesian3,
ScreenSpaceEventHandler,
ScreenSpaceEventType,
Color,
Cesium3DTileFeature,
} from “cesium”;
export default function CesiumFeaturePick() {
const viewerRef = useRef(null);
const [selectedFeature, setSelectedFeature] = useState(null);
const [tilesetReady, setTilesetReady] = useState(false);
useEffect(() => {
if (!tilesetReady || !viewerRef.current) return;
const handler = new ScreenSpaceEventHandler(viewerRef.current.scene.canvas);
handler.setInputAction((movement) => {
const picked = viewerRef.current.scene.pick(movement.position);
if (picked && picked.primitive && picked.primitive.getFeature) {
const feature: Cesium3DTileFeature = picked.primitive.getFeature(picked.instanceId);
// Reset previously selected feature color
if (selectedFeature && selectedFeature !== feature) {
selectedFeature.color = Color.WHITE; // Reset old selection
}
if (feature) {
feature.color = Color.YELLOW.withAlpha(0.6);
setSelectedFeature(feature);
}
}
}, ScreenSpaceEventType.LEFT_CLICK);
return () => {
handler.destroy();
};
}, [tilesetReady, selectedFeature]);
return (
<Viewer
full
ref={(e) => {
if (e && e.cesiumElement) viewerRef.current = e.cesiumElement;
}}
>
{/* Initial camera view */}
<Camera
view={{
destination: Cartesian3.fromDegrees(139.767052, 35.681167, 100),
}}
/>
{/* Smooth camera fly to position */}
<CameraFlyTo
destination={Cartesian3.fromDegrees(139.767052, 35.681167, 100)}
duration={3}
/>
{/* Load Cesium OSM buildings */}
<Cesium3DTileset
url="https://assets.cesium.com/96188/tileset.json"
onReady={(tileset) => {
setTilesetReady(true);
console.log("Tileset loaded", tileset);
}}
/>
</Viewer>
);
}