Skip to content

Commit fe4b16b

Browse files
authored
Merge pull request #264 from UW-Macrostrat/google-tiles
Google tiles
2 parents 833ce57 + 8ae5c8a commit fe4b16b

File tree

6 files changed

+148
-55
lines changed

6 files changed

+148
-55
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"authors": [
2626
"John Czaplewski <[email protected]>",
2727
"Daven Quinn <[email protected]>",
28-
"Casey Idzikowski <[email protected]>"
28+
"Casey Idzikowski <[email protected]>",
29+
"Amy Fromandi <[email protected]>"
2930
],
3031
"license": "MIT",
3132
"devDependencies": {
@@ -159,6 +160,10 @@
159160
"vite-plugin-inspect": "^0.8.4",
160161
"zustand": "^4.5.1"
161162
},
163+
"resolutions": {
164+
"cesium": "^1.123.1",
165+
"resium:": "1.17.1"
166+
},
162167
"prettier": {
163168
"proseWrap": "always"
164169
},

packages/globe-dev/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
"@macrostrat/hyper": "^2.0.1",
2121
"@macrostrat/mapbox-react": "workspace:*",
2222
"@macrostrat/mapbox-utils": "workspace:*",
23-
"cesium": "^1.109.0"
23+
"cesium": "^1.123.1"
2424
}
2525
}

packages/globe-dev/src/cesium-view.ts

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
// Import @types/cesium to use along with CesiumJS
22
//import VectorProvider from "@macrostrat/cesium-vector-provider";
33
import TerrainProvider from "@macrostrat/cesium-martini";
4-
import { useRef } from "react";
4+
import { useRef, useEffect } from "react";
55
import h from "@macrostrat/hyper";
66
import { ImageryLayer } from "resium";
77
import CesiumViewer, {
88
DisplayQuality,
99
MapboxLogo,
1010
SatelliteLayer,
11+
GeologyLayer,
1112
} from "@macrostrat/cesium-viewer";
13+
import { useCesium } from "resium";
14+
import {
15+
MapboxImageryProvider,
16+
createGooglePhotorealistic3DTileset,
17+
} from "cesium";
1218
import { MapboxImageryProvider } from "cesium";
1319
import { elevationLayerURL } from "@macrostrat-web/settings";
1420

@@ -35,8 +41,15 @@ function buildSatelliteLayer({ accessToken }) {
3541
return provider;
3642
}
3743

38-
function CesiumView({ style, accessToken, ...rest }) {
39-
const terrainProvider = useRef(
44+
function CesiumView({
45+
style,
46+
showGeology,
47+
accessToken,
48+
showGoogleTiles,
49+
googleMapsAPIKey,
50+
...rest
51+
}) {
52+
const terrainProvider: any = useRef(
4053
new TerrainProvider({
4154
hasVertexNormals: false,
4255
hasWaterMask: false,
@@ -48,8 +61,28 @@ function CesiumView({ style, accessToken, ...rest }) {
4861
})
4962
);
5063

51-
console.log("Access token", accessToken);
64+
if (showGoogleTiles) {
65+
// @ts-ignore
66+
return h(
67+
CesiumViewer,
68+
{
69+
terrainProvider: terrainProvider.current,
70+
displayQuality: DisplayQuality.High,
71+
fogDensity: 0.0002,
72+
//skyBox: true,
73+
showInspector: true,
74+
showIonLogo: false,
75+
...rest,
76+
},
77+
[
78+
h(GooglePhotorealistic3DTileset, {
79+
googleMapsAPIKey,
80+
}),
81+
]
82+
);
83+
}
5284

85+
// @ts-ignore
5386
return h(
5487
CesiumViewer,
5588
{
@@ -61,8 +94,36 @@ function CesiumView({ style, accessToken, ...rest }) {
6194
showIonLogo: false,
6295
...rest,
6396
},
64-
[h(SatelliteLayer, { accessToken }), h(MapboxLogo)]
97+
[
98+
h(SatelliteLayer, { accessToken, show: !showGoogleTiles }),
99+
h(GeologyLayer, { alpha: 0.3, show: showGeology && !showGoogleTiles }),
100+
h(MapboxLogo),
101+
// h(GooglePhotorealistic3DTileset, {
102+
// googleMapsAPIKey: import.meta.env.VITE_GOOGLE_MAPS_API_KEY,
103+
// show: showGoogleTiles,
104+
// }),
105+
]
65106
);
66107
}
67108

109+
// https://cesium.com/learn/cesiumjs-learn/cesiumjs-photorealistic-3d-tiles/
110+
function GooglePhotorealistic3DTileset({ googleMapsAPIKey }) {
111+
const viewer = useCesium();
112+
const tileset = useRef(null);
113+
useEffect(() => {
114+
if (tileset.current != null) {
115+
viewer.scene.primitives.add(tileset.current);
116+
} else {
117+
createGooglePhotorealistic3DTileset(googleMapsAPIKey).then((ts) => {
118+
tileset.current = ts;
119+
viewer.scene.primitives.add(ts);
120+
});
121+
}
122+
return () => {
123+
viewer.scene.primitives.remove(tileset.current);
124+
};
125+
}, [googleMapsAPIKey, viewer]);
126+
return null;
127+
}
128+
68129
export default CesiumView;

packages/globe-dev/src/index.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
DisplayQuality,
44
flyToParams,
55
translateCameraPosition,
6+
GeologyLayer,
67
} from "@macrostrat/cesium-viewer";
78
import hyper from "@macrostrat/hyper";
89
import { MapPosition } from "@macrostrat/mapbox-utils";
@@ -26,10 +27,9 @@ import Map from "./map-comparison";
2627

2728
const h = hyper.styled(styles);
2829

29-
function VisControl({ show, setShown, name }) {
30+
function VisControl({ show, setShown, name, children }) {
3031
const className = show ? "active" : "";
31-
return h(
32-
"li",
32+
return h("li.vis-control", [
3333
h(
3434
"a",
3535
{
@@ -39,8 +39,9 @@ function VisControl({ show, setShown, name }) {
3939
},
4040
},
4141
[show ? "Hide" : "Show", " ", name]
42-
)
43-
);
42+
),
43+
children,
44+
]);
4445
}
4546

4647
function getStartingPosition(): MapPosition {
@@ -74,15 +75,20 @@ function App({ accessToken }) {
7475
const style = "mapbox://styles/jczaplewski/cklb8aopu2cnv18mpxwfn7c9n";
7576
const [showWireframe, setShowWireframe] = useState(false);
7677
const [showInspector, setShowInspector] = useState(false);
78+
const [showGoogleTiles, setShowGoogleTiles] = useState(false);
7779
const [showMapbox, setShowMapbox] = useState(false);
80+
const [showGeology, setShowGeology] = useState(false);
7881
const [position, setPosition] = useState<MapPosition>(
7982
initialPosition.current
8083
);
8184

85+
const googleMapsAPIKey = import.meta.env.VITE_GOOGLE_MAPS_API_KEY;
86+
8287
const queryString = useRef<object>({});
8388

8489
useEffect(() => {
8590
let hashData = {};
91+
console.log("Updated position");
8692
applyMapPositionToHash(hashData, position);
8793
queryString.current = buildQueryString(hashData);
8894
setHashString(hashData);
@@ -102,6 +108,7 @@ function App({ accessToken }) {
102108
}
103109

104110
const onViewChange = useCallback((cpos: CameraParams) => {
111+
console.log("View changed");
105112
const { camera } = cpos;
106113
setPosition({
107114
camera: {
@@ -133,6 +140,16 @@ function App({ accessToken }) {
133140
show: showMapbox,
134141
setShown: setShowMapbox,
135142
}),
143+
h(VisControl, {
144+
name: "Google tiles",
145+
show: showGoogleTiles,
146+
setShown: setShowGoogleTiles,
147+
}),
148+
h(VisControl, {
149+
name: "geology",
150+
show: showGeology,
151+
setShown: setShowGeology,
152+
}),
136153
h(Link, { href: mapURL }, "Switch to map"),
137154
h(GoogleEarthLink, { position }, "Open in Google Earth"),
138155
]),
@@ -145,9 +162,12 @@ function App({ accessToken }) {
145162
flyTo,
146163
showWireframe,
147164
showInspector,
165+
showGeology,
166+
showGoogleTiles,
148167
highResolution: true,
149168
displayQuality: DisplayQuality.High,
150169
onViewChange,
170+
googleMapsAPIKey,
151171
}),
152172
]),
153173
h.if(showMapbox)("div.map-panel", [

0 commit comments

Comments
 (0)