Skip to content

Commit

Permalink
fix: visualizer on reearth/core (#395)
Browse files Browse the repository at this point in the history
* fix: visualizer on reearth/core

* fix: test
  • Loading branch information
keiya01 authored Jan 12, 2023
1 parent 07a6b4d commit 7ba0dbf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export { degreeToRadian, radianToDegree } from "./utils";
export type Props = {
theme?: Theme;
degree: number;
editing?: boolean;
/**
* Pass degree of circle as callback arguments.
* This event is invoked when mouse down on outer circle and mouse move.
Expand Down Expand Up @@ -42,6 +43,7 @@ export type Props = {
const NavigatorPresenter: React.FC<Props> = memo(function NavigatorPresenterMemo({
theme,
degree,
editing,
onRotate,
onStartOrbit,
onEndOrbit,
Expand All @@ -65,7 +67,7 @@ const NavigatorPresenter: React.FC<Props> = memo(function NavigatorPresenterMemo
return (
<Container>
<CompassContainer>
<Compass ref={compassRef}>
<Compass ref={compassRef} editing={!!editing}>
<CompassIcon onMouseDown={handleOnMouseDownCompass} publishedTheme={theme}>
<Icon
icon="compass"
Expand All @@ -83,7 +85,10 @@ const NavigatorPresenter: React.FC<Props> = memo(function NavigatorPresenterMemo
<Icon icon="compassFocus" color={theme?.select} alt="" size={30} />
</CompassFocusIcon>
)}
<AngleIcon onMouseDown={handleOnMouseDownAngle} publishedTheme={theme}>
<AngleIcon
onMouseDown={handleOnMouseDownAngle}
publishedTheme={theme}
editing={!!editing}>
<Icon icon="navigatorAngle" aria-label={t("aria-label-adjust-angle")} size={32} />
</AngleIcon>
</Compass>
Expand Down Expand Up @@ -127,14 +132,14 @@ const Help = styled.button`
user-select: none;
`;

const Compass = styled.div`
const Compass = styled.div<{ editing: boolean }>`
position: relative;
display: inline-grid;
place-items: center;
width: 64px;
height: 64px;
cursor: pointer;
z-index: 1;
${({ editing }) => (!editing ? "z-index: 1;" : "")}
`;

const CompassIcon = styled.div<{ publishedTheme?: Theme }>`
Expand All @@ -161,7 +166,7 @@ const CompassFocusIcon = styled.div`
height: 64px;
`;

const AngleIcon = styled.div<{ publishedTheme?: Theme }>`
const AngleIcon = styled.div<{ publishedTheme?: Theme; editing: boolean }>`
& circle {
fill: ${({ theme, publishedTheme }) => publishedTheme?.background || theme.main.deepBg};
}
Expand All @@ -171,7 +176,7 @@ const AngleIcon = styled.div<{ publishedTheme?: Theme }>`
display: inline-block;
height: 32px;
width: 32px;
z-index: 1;
${({ editing }) => (!editing ? "z-index: 1;" : "")}
`;

const Tool = styled.div<{ publishedTheme?: Theme }>`
Expand Down
3 changes: 2 additions & 1 deletion src/core/Crust/Widgets/Widget/Navigator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type Property = {};

const Navigator = ({
theme,
editing,
context: { camera, onCameraOrbit, onCameraRotateRight, onFlyTo, onZoomIn, onZoomOut } = {},
}: Props): JSX.Element | null => {
const { degree, events } = useHooks({
Expand All @@ -20,7 +21,7 @@ const Navigator = ({
onZoomOut,
});

return <NavigatorPresenter theme={theme} degree={degree} {...events} />;
return <NavigatorPresenter theme={theme} degree={degree} editing={!!editing} {...events} />;
};

export default Navigator;
2 changes: 1 addition & 1 deletion src/core/Crust/Widgets/Widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default function WidgetComponent({
style={{
pointerEvents: editing ? "none" : "auto",
}}>
<Builtin {...props} widget={w} />
<Builtin {...props} editing={editing} widget={w} />
</div>
) : (
<>{renderWidget?.(w)}</>
Expand Down
54 changes: 27 additions & 27 deletions src/core/Visualizer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,33 +143,6 @@ export default function Visualizer({

return (
<>
<Map
ref={mapRef}
isBuilt={isBuilt}
isEditable={isEditable}
sceneProperty={sceneProperty}
engine={engine}
layers={layers}
engines={engines}
camera={camera}
clock={clock}
clusters={clusters}
hiddenLayers={hiddenLayers}
isLayerDraggable={isLayerDraggable}
isLayerDragging={isLayerDragging}
meta={meta}
style={style}
// overrides={overrides} // not used for now
property={sceneProperty}
selectedLayerId={selectedLayerId}
small={small}
ready={ready}
onCameraChange={handleCameraChange}
onLayerDrag={onLayerDrag}
onLayerDrop={onLayerDrop}
onLayerSelect={handleLayerSelect}
onTick={handleTick}
/>
<Crust
isBuilt={isBuilt}
isEditable={isEditable}
Expand Down Expand Up @@ -197,6 +170,33 @@ export default function Visualizer({
onBlockInsert={onBlockInsert}
renderInfoboxInsertionPopup={renderInfoboxInsertionPopup}
/>
<Map
ref={mapRef}
isBuilt={isBuilt}
isEditable={isEditable}
sceneProperty={sceneProperty}
engine={engine}
layers={layers}
engines={engines}
camera={camera}
clock={clock}
clusters={clusters}
hiddenLayers={hiddenLayers}
isLayerDraggable={isLayerDraggable}
isLayerDragging={isLayerDragging}
meta={meta}
style={style}
// overrides={overrides} // not used for now
property={sceneProperty}
selectedLayerId={selectedLayerId}
small={small}
ready={ready}
onCameraChange={handleCameraChange}
onLayerDrag={onLayerDrag}
onLayerDrop={onLayerDrop}
onLayerSelect={handleLayerSelect}
onTick={handleTick}
/>
</>
);
}

0 comments on commit 7ba0dbf

Please sign in to comment.