Skip to content

Commit

Permalink
feat: support osm data type on reearth/core (#431)
Browse files Browse the repository at this point in the history
* feat: support osm data type

* fix: rename to osm-buildings
  • Loading branch information
keiya01 committed Feb 7, 2023
1 parent 72cd0da commit 0d4e0bf
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 12 deletions.
11 changes: 5 additions & 6 deletions src/core/engines/Cesium/Feature/Tileset/hooks.ts
Expand Up @@ -231,8 +231,7 @@ export const useHooks = ({
onFeatureDelete?: (feature: string[]) => void;
}) => {
const { viewer } = useCesium();
const { sourceType, tileset, styleUrl, edgeColor, edgeWidth, experimental_clipping } =
property ?? {};
const { tileset, styleUrl, edgeColor, edgeWidth, experimental_clipping } = property ?? {};
const {
width,
height,
Expand All @@ -246,7 +245,7 @@ export const useHooks = ({
} = experimental_clipping || {};
const { allowEnterGround } = sceneProperty?.default || {};
const [style, setStyle] = useState<Cesium3DTileStyle>();
const { url } = useData(layer);
const { url, type } = useData(layer);

const prevPlanes = useRef(_planes);
const planes = useMemo(() => {
Expand Down Expand Up @@ -402,12 +401,12 @@ export const useHooks = ({
}, [styleUrl]);

const tilesetUrl = useMemo(() => {
return sourceType === "osm" && isVisible
return type === "osm-buildings" && isVisible
? IonResource.fromAssetId(96188) // https://github.com/CesiumGS/cesium/blob/main/packages/engine/Source/Scene/createOsmBuildings.js#L53
: isVisible
: type === "3dtiles" && isVisible
? url ?? tileset
: null;
}, [isVisible, sourceType, tileset, url]);
}, [isVisible, tileset, url, type]);

return {
tilesetUrl,
Expand Down
3 changes: 2 additions & 1 deletion src/core/engines/Cesium/Feature/index.tsx
Expand Up @@ -39,7 +39,8 @@ const displayConfig: Record<DataType, (keyof typeof components)[] | "auto"> = {
kml: ["resource"],
wms: ["raster"],
mvt: ["raster"],
["3dtiles"]: ["3dtiles"],
"3dtiles": ["3dtiles"],
"osm-buildings": ["3dtiles"],
};

// Some layer that is delegated data is not computed when layer is updated.
Expand Down
2 changes: 1 addition & 1 deletion src/core/engines/Cesium/index.tsx
Expand Up @@ -189,5 +189,5 @@ export const engine: Engine = {
component: Component,
featureComponent: Feature,
clusterComponent: Cluster,
delegatedDataTypes: ["czml", "wms", "mvt", "3dtiles"],
delegatedDataTypes: ["czml", "wms", "mvt", "3dtiles", "osm-buildings"],
};
37 changes: 37 additions & 0 deletions src/core/mantle/compat/forward.test.ts
Expand Up @@ -417,6 +417,43 @@ test("model", () => {
});

test("3dtiles", () => {
// osm
expect(
convertLegacyLayer({
id: "x",
extensionId: "tileset",
propertyId: "p",
isVisible: true,
property: {
default: {
sourceType: "osm",
hoge: "red",
},
},
}),
).toEqual({
id: "x",
type: "simple",
visible: true,
data: {
type: "osm-buildings",
},
"3dtiles": {
hoge: "red",
},
compat: {
extensionId: "tileset",
propertyId: "p",
property: {
default: {
sourceType: "osm",
hoge: "red",
},
},
},
});

// tileset
expect(
convertLegacyLayer({
id: "x",
Expand Down
8 changes: 6 additions & 2 deletions src/core/mantle/compat/forward.ts
Expand Up @@ -185,8 +185,12 @@ function convertLegacyLayerItem(l: LegacyLayer): LayerSimple | undefined {
}
} else if (l.extensionId === "tileset") {
appearance = "3dtiles";
legacyPropertyKeys = ["tileset"];
if (l.property?.default?.tileset) {
legacyPropertyKeys = ["tileset", "sourceType"];
if (l.property?.default?.sourceType === "osm") {
data = {
type: "osm-buildings",
};
} else if (l.property?.default?.tileset) {
data = {
type: "3dtiles",
url: l.property.default.tileset,
Expand Down
1 change: 0 additions & 1 deletion src/core/mantle/types/appearance.ts
Expand Up @@ -108,7 +108,6 @@ export type ModelAppearance = {
};

export type Cesium3DTilesAppearance = {
sourceType?: "url" | "osm";
tileset?: string;
show?: boolean;
color?: string;
Expand Down
10 changes: 9 additions & 1 deletion src/core/mantle/types/index.ts
Expand Up @@ -78,7 +78,15 @@ export type DataRange = {
z: number;
};

export type DataType = "geojson" | "3dtiles" | "czml" | "csv" | "wms" | "mvt" | "kml";
export type DataType =
| "geojson"
| "3dtiles"
| "osm-buildings"
| "czml"
| "csv"
| "wms"
| "mvt"
| "kml";

// Feature
export type CommonFeature<T extends "feature" | "computedFeature"> = {
Expand Down

0 comments on commit 0d4e0bf

Please sign in to comment.