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

Commit

Permalink
Merge branch 'main' of https://github.com/reearth/reearth-web into cu…
Browse files Browse the repository at this point in the history
…rrent-location
  • Loading branch information
nina992 committed Dec 11, 2022
2 parents b2b258d + 8d0a65e commit 5d16692
Show file tree
Hide file tree
Showing 23 changed files with 366 additions and 159 deletions.
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
# Changelog
All notable changes to this project will be documented in this file.

## 0.13.0 - 2022-12-06

### 🚀 Features

- Support Cesium Ion terrain ([#331](https://github.com/reearth/reearth-web/pull/331)) [`e0b99a`](https://github.com/reearth/reearth-web/commit/e0b99a)
- Set Cesium Ion default access token via config ([#365](https://github.com/reearth/reearth-web/pull/365)) [`a257b1`](https://github.com/reearth/reearth-web/commit/a257b1)
- Display policy name on workspace title ([#362](https://github.com/reearth/reearth-web/pull/362)) [`c1c632`](https://github.com/reearth/reearth-web/commit/c1c632)
- Editable box ([#357](https://github.com/reearth/reearth-web/pull/357)) [`92a159`](https://github.com/reearth/reearth-web/commit/92a159)
- Extend plugin API supports move widget ([#346](https://github.com/reearth/reearth-web/pull/346)) [`c82825`](https://github.com/reearth/reearth-web/commit/c82825)
- Extend plugin API supports close widget ([#355](https://github.com/reearth/reearth-web/pull/355)) [`d02578`](https://github.com/reearth/reearth-web/commit/d02578)
- Extend plugin API supports get scene inEditor ([#351](https://github.com/reearth/reearth-web/pull/351)) [`ec0b81`](https://github.com/reearth/reearth-web/commit/ec0b81)
- Add clipping box ([#338](https://github.com/reearth/reearth-web/pull/338)) [`af55f1`](https://github.com/reearth/reearth-web/commit/af55f1)
- Extend plugin API event with modalclose popupclose ([#354](https://github.com/reearth/reearth-web/pull/354)) [`9be75a`](https://github.com/reearth/reearth-web/commit/9be75a)
- Extend plugin API supports get location from screen position ([#350](https://github.com/reearth/reearth-web/pull/350)) [`9a826f`](https://github.com/reearth/reearth-web/commit/9a826f)
- Extend plugin API supports get viewport&[#39](https://github.com/reearth/reearth-web/pull/39);s size ([#342](https://github.com/reearth/reearth-web/pull/342)) [`7b268b`](https://github.com/reearth/reearth-web/commit/7b268b)
- Add Re:Earth favicon ([#349](https://github.com/reearth/reearth-web/pull/349)) [`0395d2`](https://github.com/reearth/reearth-web/commit/0395d2)
- Support acquiring locations with terrain ([#343](https://github.com/reearth/reearth-web/pull/343)) [`596543`](https://github.com/reearth/reearth-web/commit/596543)

### 🔧 Bug Fixes

- Policy messages not aligning with policy ([#368](https://github.com/reearth/reearth-web/pull/368)) [`2871ed`](https://github.com/reearth/reearth-web/commit/2871ed)
- Widget align system alignment issue with installed widgets [`e302cc`](https://github.com/reearth/reearth-web/commit/e302cc)
- Rename animation option to withoutAnimation in lookAt ([#361](https://github.com/reearth/reearth-web/pull/361)) [`846a6e`](https://github.com/reearth/reearth-web/commit/846a6e)
- Post message queue doesn&[#39](https://github.com/reearth/reearth-web/pull/39);t work for modal/popup ([#359](https://github.com/reearth/reearth-web/pull/359)) [`abb4ed`](https://github.com/reearth/reearth-web/commit/abb4ed)
- Correct flyToGround destination camera ([#356](https://github.com/reearth/reearth-web/pull/356)) [`225758`](https://github.com/reearth/reearth-web/commit/225758)
- Navigator styles ([#353](https://github.com/reearth/reearth-web/pull/353)) [`971323`](https://github.com/reearth/reearth-web/commit/971323)
- Timeline styles ([#352](https://github.com/reearth/reearth-web/pull/352)) [`c76d36`](https://github.com/reearth/reearth-web/commit/c76d36)
- Alignment issues in Widget Align System ([#344](https://github.com/reearth/reearth-web/pull/344)) [`0e12ea`](https://github.com/reearth/reearth-web/commit/0e12ea)
- Cannot input camera altitude less than 500 with camera pane ([#339](https://github.com/reearth/reearth-web/pull/339)) [`76a169`](https://github.com/reearth/reearth-web/commit/76a169)
- Type error from apollo-client [`7dd2b3`](https://github.com/reearth/reearth-web/commit/7dd2b3)
- Fix the camera offset when keep press on zoom to layer ([#335](https://github.com/reearth/reearth-web/pull/335)) [`ccec33`](https://github.com/reearth/reearth-web/commit/ccec33)

### ⚡️ Performance

- Use lodash-es rather than lodash [`731e54`](https://github.com/reearth/reearth-web/commit/731e54)

### 🧪 Testing

- Gql func to e2e reearth page [`593780`](https://github.com/reearth/reearth-web/commit/593780)
- Introduce playwright to run e2e tests ([#336](https://github.com/reearth/reearth-web/pull/336)) [`3af520`](https://github.com/reearth/reearth-web/commit/3af520)

### Miscellaneous Tasks

- Suppress errors output to the console by Icon [`bd9dc5`](https://github.com/reearth/reearth-web/commit/bd9dc5)
- Upgrade cesium to v1.100.0 [`ec05a0`](https://github.com/reearth/reearth-web/commit/ec05a0)
- Upgrade cesium to v1.99 [`be5b22`](https://github.com/reearth/reearth-web/commit/be5b22)
- Upgrade dependencies ([#345](https://github.com/reearth/reearth-web/pull/345)) [`1efe8c`](https://github.com/reearth/reearth-web/commit/1efe8c)
- Remove eslint-plugin-graphql, add eslint-plugin-playwright, refresh yarn.lock [`28c846`](https://github.com/reearth/reearth-web/commit/28c846)
- Use node 16 to avoid storybook build error with node 18 [`64819e`](https://github.com/reearth/reearth-web/commit/64819e)

## 0.12.0 - 2022-10-26

### Miscellaneous Tasks
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reearth-web",
"version": "0.12.0",
"version": "0.13.0",
"description": "",
"repository": "[email protected]:reearth/reearth-web.git",
"author": "reearth",
Expand Down
14 changes: 10 additions & 4 deletions src/components/atoms/Icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type Props = {
style?: CSSProperties;
role?: AriaRole;
notransition?: boolean;
transitionDuration?: string;
onClick?: () => void;
} & AriaAttributes;

Expand All @@ -32,6 +33,7 @@ const Icon: React.FC<Props> = ({
size,
role,
notransition,
transitionDuration,
onClick,
...props
}) => {
Expand Down Expand Up @@ -63,13 +65,19 @@ const Icon: React.FC<Props> = ({
<StyledSvg
className={className}
src={src}
style={style}
role={role}
color={color}
stroke={stroke}
size={sizeStr}
notransition={notransition}
onClick={onClick}
style={{
...style,
// To prevent annoying errors from being output to the console, specify transitions without Emotion.
transitionDuration:
!notransition && !style?.transitionDuration
? transitionDuration || "0.3s"
: style?.transitionDuration,
}}
{...aria}
/>
);
Expand All @@ -85,7 +93,6 @@ const StyledSvg = styled(SVG)<{
color?: string;
stroke?: string;
size?: string;
notransition?: boolean;
}>`
font-size: 0;
display: inline-block;
Expand All @@ -94,7 +101,6 @@ const StyledSvg = styled(SVG)<{
color: ${({ color }) => color};
${({ stroke }) => `stroke: ${stroke};`}
transition-property: color, background;
${({ notransition }) => (!notransition ? "transition-duration: 0.3s;" : undefined)}
`;

export default memo(Icon);
113 changes: 113 additions & 0 deletions src/components/molecules/Visualizer/Engine/Cesium/core/Globe.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import {
ArcGISTiledElevationTerrainProvider,
CesiumTerrainProvider,
EllipsoidTerrainProvider,
IonResource,
TerrainProvider,
} from "cesium";
import { pick } from "lodash-es";
import { useMemo } from "react";
import { Globe as CesiumGlobe } from "resium";

import { objKeys } from "@reearth/util/util";

import type { SceneProperty, TerrainProperty } from "../../ref";

export type Props = {
property?: SceneProperty;
cesiumIonAccessToken?: string;
};

export default function Globe({ property, cesiumIonAccessToken }: Props): JSX.Element | null {
const terrainProperty = useMemo(
(): TerrainProperty => ({
...property?.terrain,
...pick(property?.default, terrainPropertyKeys),
}),
[property?.terrain, property?.default],
);

const terrainProvider = useMemo((): TerrainProvider | undefined => {
const opts = {
terrain: terrainProperty?.terrain,
terrainType: terrainProperty?.terrainType,
terrainCesiumIonAccessToken:
terrainProperty?.terrainCesiumIonAccessToken || cesiumIonAccessToken,
terrainCesiumIonAsset: terrainProperty?.terrainCesiumIonAsset,
terrainCesiumIonUrl: terrainProperty?.terrainCesiumIonUrl,
};
const provider = opts.terrain ? terrainProviders[opts.terrainType || "cesium"] : undefined;
return (typeof provider === "function" ? provider(opts) : provider) ?? defaultTerrainProvider;
}, [
terrainProperty?.terrain,
terrainProperty?.terrainType,
terrainProperty?.terrainCesiumIonAccessToken,
terrainProperty?.terrainCesiumIonAsset,
terrainProperty?.terrainCesiumIonUrl,
cesiumIonAccessToken,
]);

return (
<CesiumGlobe
enableLighting={!!property?.atmosphere?.enable_lighting}
showGroundAtmosphere={property?.atmosphere?.ground_atmosphere ?? true}
atmosphereSaturationShift={property?.atmosphere?.surturation_shift}
atmosphereHueShift={property?.atmosphere?.hue_shift}
atmosphereBrightnessShift={property?.atmosphere?.brightness_shift}
terrainProvider={terrainProvider}
depthTestAgainstTerrain={!!terrainProperty.depthTestAgainstTerrain}
terrainExaggerationRelativeHeight={terrainProperty.terrainExaggerationRelativeHeight}
terrainExaggeration={terrainProperty.terrainExaggeration}
/>
);
}

const terrainPropertyKeys = objKeys<TerrainProperty>({
terrain: 0,
terrainType: 0,
terrainExaggeration: 0,
terrainExaggerationRelativeHeight: 0,
depthTestAgainstTerrain: 0,
terrainCesiumIonAsset: 0,
terrainCesiumIonAccessToken: 0,
terrainCesiumIonUrl: 0,
terrainUrl: 0,
});

const defaultTerrainProvider = new EllipsoidTerrainProvider();

const terrainProviders: {
[k in NonNullable<TerrainProperty["terrainType"]>]:
| TerrainProvider
| ((
opts: Pick<
TerrainProperty,
"terrainCesiumIonAccessToken" | "terrainCesiumIonAsset" | "terrainCesiumIonUrl"
>,
) => TerrainProvider | null);
} = {
cesium: ({ terrainCesiumIonAccessToken }) =>
// https://github.com/CesiumGS/cesium/blob/main/Source/Core/createWorldTerrain.js
new CesiumTerrainProvider({
url: IonResource.fromAssetId(1, {
accessToken: terrainCesiumIonAccessToken,
}),
requestVertexNormals: false,
requestWaterMask: false,
}),
arcgis: () =>
new ArcGISTiledElevationTerrainProvider({
url: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer",
}),
cesiumion: ({ terrainCesiumIonAccessToken, terrainCesiumIonAsset, terrainCesiumIonUrl }) =>
terrainCesiumIonAsset
? new CesiumTerrainProvider({
url:
terrainCesiumIonUrl ||
IonResource.fromAssetId(parseInt(terrainCesiumIonAsset, 10), {
accessToken: terrainCesiumIonAccessToken,
}),
requestVertexNormals: true,
})
: null,
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { expect, test, vi } from "vitest";
import { type Tile, useImageryProviders } from "./Imagery";

test("useImageryProviders", () => {
const provider = vi.fn((url?: string): any => ({ hoge: url }));
const provider2 = vi.fn((url?: string): any => ({ hoge2: url }));
const provider = vi.fn(({ url }: { url?: string } = {}): any => ({ hoge: url }));
const provider2 = vi.fn(({ url }: { url?: string } = {}): any => ({ hoge2: url }));
const presets = { default: provider, foobar: provider2 };
const { result, rerender } = renderHook(
({ tiles, cesiumIonAccessToken }: { tiles: Tile[]; cesiumIonAccessToken?: string }) =>
Expand Down Expand Up @@ -37,7 +37,7 @@ test("useImageryProviders", () => {
expect(result.current.providers["1"][2]).not.toBe(prevImageryProvider);
expect(result.current.updated).toBe(true);
expect(provider).toBeCalledTimes(2);
expect(provider).toBeCalledWith("a");
expect(provider).toBeCalledWith({ url: "a" });
const prevImageryProvider2 = result.current.providers["1"][2];

// add a tile with URL
Expand Down
23 changes: 13 additions & 10 deletions src/components/molecules/Visualizer/Engine/Cesium/core/Imagery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,26 @@ export function useImageryProviders({
tiles?: Tile[];
cesiumIonAccessToken?: string;
presets: {
[key: string]: (url?: string) => ImageryProvider | null;
[key: string]: (opts?: {
url?: string;
cesiumIonAccessToken?: string;
}) => ImageryProvider | null;
};
}): { providers: Providers; updated: boolean } {
const newTile = useCallback(
(t: Tile) =>
t.tile_url && t.tile_type
? presets[t.tile_type](t.tile_url)
: presets[t.tile_type || "default"](),
(t: Tile, ciat?: string) =>
presets[t.tile_type || "default"]({ url: t.tile_url, cesiumIonAccessToken: ciat }),
[presets],
);

const prevCesiumIonAccessToken = useRef(cesiumIonAccessToken);
const tileKeys = tiles.map(t => t.id);
const tileKeys = tiles.map(t => t.id).join(",");
const prevTileKeys = useRef(tileKeys);
const prevProviders = useRef<Providers>({});

// Manage TileProviders so that TileProvider does not need to be recreated each time tiles are updated.
const { providers, updated } = useMemo(() => {
const updatedCesiumAccessToken = prevCesiumIonAccessToken.current !== cesiumIonAccessToken;
const isCesiumAccessTokenUpdated = prevCesiumIonAccessToken.current !== cesiumIonAccessToken;
const prevProvidersKeys = Object.keys(prevProviders.current);
const added = tiles.map(t => t.id).filter(t => t && !prevProvidersKeys.includes(t));

Expand Down Expand Up @@ -123,8 +125,8 @@ export function useImageryProviders({
added ||
prevType !== tile.tile_type ||
prevUrl !== tile.tile_url ||
(updatedCesiumAccessToken && (!tile.tile_type || tile.tile_type === "default"))
? [tile.tile_type, tile.tile_url, newTile(tile)]
(isCesiumAccessTokenUpdated && (!tile.tile_type || tile.tile_type === "default"))
? [tile.tile_type, tile.tile_url, newTile(tile, cesiumIonAccessToken)]
: [prevType, prevUrl, prevProvider],
],
)
Expand All @@ -136,13 +138,14 @@ export function useImageryProviders({

const updated =
!!added.length ||
!!updatedCesiumAccessToken ||
!!isCesiumAccessTokenUpdated ||
!isEqual(prevTileKeys.current, tileKeys) ||
rawProviders.some(
p => p.tile && (p.prevType !== p.tile.tile_type || p.prevUrl !== p.tile.tile_url),
);

prevTileKeys.current = tileKeys;
prevCesiumIonAccessToken.current = cesiumIonAccessToken;

return { providers, updated };
}, [cesiumIonAccessToken, tiles, tileKeys, newTile]);
Expand Down
23 changes: 12 additions & 11 deletions src/components/molecules/Visualizer/Engine/Cesium/core/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ import {
OpenStreetMapImageryProvider,
IonWorldImageryStyle,
UrlTemplateImageryProvider,
Ion,
} from "cesium";

export const tiles = {
default: () =>
default: ({ cesiumIonAccessToken } = {}) =>
new IonImageryProvider({
assetId: IonWorldImageryStyle.AERIAL,
accessToken: Ion.defaultAccessToken,
accessToken: cesiumIonAccessToken,
}),
default_label: () =>
default_label: ({ cesiumIonAccessToken } = {}) =>
new IonImageryProvider({
assetId: IonWorldImageryStyle.AERIAL_WITH_LABELS,
accessToken: Ion.defaultAccessToken,
accessToken: cesiumIonAccessToken,
}),
default_road: () =>
default_road: ({ cesiumIonAccessToken } = {}) =>
new IonImageryProvider({
assetId: IonWorldImageryStyle.ROAD,
accessToken: Ion.defaultAccessToken,
accessToken: cesiumIonAccessToken,
}),
stamen_watercolor: () =>
new OpenStreetMapImageryProvider({
Expand All @@ -47,11 +46,13 @@ export const tiles = {
"Copyright: Tiles © Esri — Esri, DeLorme, NAVTEQ, TomTom, Intermap, iPC, USGS, FAO, NPS, NRCAN, GeoBase, Kadaster NL, Ordnance Survey, Esri Japan, METI, Esri China (Hong Kong), and the GIS User Communit",
enablePickFeatures: false,
}),
black_marble: () =>
new IonImageryProvider({ assetId: 3812, accessToken: Ion.defaultAccessToken }),
black_marble: ({ cesiumIonAccessToken } = {}) =>
new IonImageryProvider({ assetId: 3812, accessToken: cesiumIonAccessToken }),
japan_gsi_standard: () =>
new OpenStreetMapImageryProvider({
url: "https://cyberjapandata.gsi.go.jp/xyz/std/",
}),
url: url => (url ? new UrlTemplateImageryProvider({ url }) : null),
} as { [key: string]: (url?: string) => ImageryProvider | null };
url: ({ url } = {}) => (url ? new UrlTemplateImageryProvider({ url }) : null),
} as {
[key: string]: (opts?: { url?: string; cesiumIonAccessToken?: string }) => ImageryProvider | null;
};
Loading

0 comments on commit 5d16692

Please sign in to comment.