Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

fix: disable default cesium mouse event #42

Merged
merged 4 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/components/molecules/Common/Cesium/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useDeepCompareEffect } from "react-use";
import { CesiumComponentRef } from "resium";
import {
Viewer as CesiumViewer,
ScreenSpaceEventType,
PerspectiveFrustum,
Math as CesiumMath,
ImageryProvider,
Expand Down Expand Up @@ -82,12 +81,6 @@ export default ({
cesium.current?.cesiumElement?.scene.requestRender();
});

useEffect(() => {
const v = cesium.current?.cesiumElement;
v?.screenSpaceEventHandler.removeInputAction(ScreenSpaceEventType.LEFT_CLICK);
v?.screenSpaceEventHandler.removeInputAction(ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
}, []);

useEffect(() => {
const viewer = cesium.current?.cesiumElement;
if (!viewer) return;
Expand Down Expand Up @@ -130,9 +123,8 @@ export default ({
}
}, [cameraState, onCameraChange]);

const [imageryLayers, setImageryLayers] = useState<
[string, ImageryProvider, number | undefined, number | undefined][]
>();
const [imageryLayers, setImageryLayers] =
useState<[string, ImageryProvider, number | undefined, number | undefined][]>();

useDeepCompareEffect(() => {
const newTiles = (property?.tiles?.length ? property.tiles : undefined)
Expand Down Expand Up @@ -226,9 +218,11 @@ const getCamera = (viewer: CesiumViewer) => {
if (!(camera.frustum instanceof PerspectiveFrustum)) return;

const ellipsoid = viewer.scene.globe.ellipsoid;
const { latitude, longitude, height: altitude } = ellipsoid.cartesianToCartographic(
camera.position,
);
const {
latitude,
longitude,
height: altitude,
} = ellipsoid.cartesianToCartographic(camera.position);
const lat = CesiumMath.toDegrees(latitude);
const lng = CesiumMath.toDegrees(longitude);
const { heading, pitch, roll } = camera;
Expand Down
10 changes: 9 additions & 1 deletion src/components/molecules/Common/Cesium/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import {
Scene,
CameraFlyTo,
SkyBox,
ScreenSpaceEventHandler,
ScreenSpaceEvent,
} from "resium";
import { ScreenSpaceEventType } from "cesium";

import { styled } from "@reearth/theme";
import { SceneProperty, Camera } from "@reearth/util/value";
import Loading from "@reearth/components/atoms/Loading";
import PluginPrimitive from "../plugin/PluginPrimitive";
import PluginWidget from "../plugin/PluginWidget";
import { Provider } from "./api";
import useHooks, { Ref as RefType } from "./hooks";
import Loading from "@reearth/components/atoms/Loading";

export type Layer = {
id: string;
Expand Down Expand Up @@ -118,6 +121,11 @@ const Cesium: React.ForwardRefRenderFunction<Ref, Props> = (
small={small}
onClick={selectViewerEntity}>
<Provider layers={layers} onEntitySelect={selectEntity}>
<ScreenSpaceEventHandler useDefault>
{/* Disable default events */}
<ScreenSpaceEvent type={ScreenSpaceEventType.LEFT_DOUBLE_CLICK} />
<ScreenSpaceEvent type={ScreenSpaceEventType.LEFT_CLICK} />
</ScreenSpaceEventHandler>
{cameraDest && cameraOrientation && (
<CameraFlyTo destination={cameraDest} orientation={cameraOrientation} duration={0} once />
)}
Expand Down