react-three-map 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/maplibre/types/core/coords-to-matrix.d.ts +8 -0
- package/dist/maplibre/types/core/create-events.d.ts +3 -0
- package/dist/maplibre/types/core/generic-map.d.ts +47 -0
- package/{src/core/state-ref.ts → dist/maplibre/types/core/state-ref.d.ts} +4 -5
- package/dist/maplibre/types/core/use-canvas.d.ts +13 -0
- package/dist/maplibre/types/core/use-function.d.ts +1 -0
- package/dist/maplibre/types/core/use-on-add.d.ts +8 -0
- package/dist/maplibre/types/core/use-render.d.ts +3 -0
- package/dist/maplibre/types/maplibre/canvas.d.ts +10 -0
- package/dist/maplibre/types/maplibre.index.d.ts +1 -0
- package/dist/types/core/coords-to-matrix.d.ts +8 -0
- package/dist/types/core/create-events.d.ts +3 -0
- package/dist/types/core/generic-map.d.ts +47 -0
- package/dist/types/core/state-ref.d.ts +8 -0
- package/dist/types/core/use-canvas.d.ts +13 -0
- package/dist/types/core/use-function.d.ts +1 -0
- package/dist/types/core/use-on-add.d.ts +8 -0
- package/dist/types/core/use-render.d.ts +3 -0
- package/dist/types/mapbox/canvas.d.ts +10 -0
- package/dist/types/mapbox.index.d.ts +1 -0
- package/maplibre/package.json +1 -1
- package/package.json +4 -3
- package/docs/basic-app.gif +0 -0
- package/example-mapbox/package.json +0 -29
- package/example-mapbox/sandbox.config.json +0 -3
- package/example-mapbox/src/canvas.basic.stories.tsx +0 -84
- package/example-mapbox/src/comparison.stories.tsx +0 -37
- package/example-mapbox/src/html-on-top.stories.tsx +0 -24
- package/example-mapbox/src/my-scene.tsx +0 -89
- package/example-mapbox/src/render-on-demand.stories.tsx +0 -32
- package/example-mapbox/src/story-map.tsx +0 -61
- package/example-mapbox/src/vite-env.d.ts +0 -1
- package/example-mapbox/tsconfig.json +0 -27
- package/example-mapbox/tsconfig.node.json +0 -10
- package/example-mapbox/yarn.lock +0 -4154
- package/example-maplibre/package.json +0 -29
- package/example-maplibre/sandbox.config.json +0 -3
- package/example-maplibre/src/canvas.basic.stories.tsx +0 -61
- package/example-maplibre/src/comparison.stories.tsx +0 -35
- package/example-maplibre/src/html-on-top.stories.tsx +0 -24
- package/example-maplibre/src/my-scene.tsx +0 -89
- package/example-maplibre/src/render-on-demand.stories.tsx +0 -32
- package/example-maplibre/src/story-map.tsx +0 -38
- package/example-maplibre/src/vite-env.d.ts +0 -1
- package/example-maplibre/tsconfig.json +0 -25
- package/example-maplibre/tsconfig.node.json +0 -10
- package/example-maplibre/yarn.lock +0 -4181
- package/src/core/coords-to-matrix.ts +0 -20
- package/src/core/create-events.ts +0 -73
- package/src/core/generic-map.test.ts +0 -2
- package/src/core/generic-map.ts +0 -57
- package/src/core/use-canvas.tsx +0 -31
- package/src/core/use-function.ts +0 -10
- package/src/core/use-on-add.ts +0 -90
- package/src/core/use-render.ts +0 -25
- package/src/mapbox/canvas.tsx +0 -38
- package/src/mapbox/index.ts +0 -1
- package/src/maplibre/canvas.tsx +0 -38
- package/src/maplibre/index.ts +0 -1
- package/src/stories/comparison.stories.tsx +0 -38
- package/src/stories/html-on-top.stories.tsx +0 -21
- package/src/stories/mapbox/story-mapbox.tsx +0 -58
- package/src/stories/mapbox-example.stories.tsx +0 -84
- package/src/stories/maplibre/story-maplibre.tsx +0 -32
- package/src/stories/maplibre-example.stories.tsx +0 -61
- package/src/stories/my-scene.tsx +0 -88
- package/src/stories/render-on-demand.stories.tsx +0 -34
- package/src/stories/story-map.tsx +0 -35
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.json +0 -30
- package/tsconfig.node.json +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FromLngLat } from "./generic-map";
|
|
2
|
+
/** calculate Matrix4 from coordinates */
|
|
3
|
+
export declare function coordsToMatrix({ longitude, latitude, altitude, fromLngLat }: {
|
|
4
|
+
longitude: number;
|
|
5
|
+
latitude: number;
|
|
6
|
+
altitude: number;
|
|
7
|
+
fromLngLat: FromLngLat;
|
|
8
|
+
}): import("three").Matrix4Tuple;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Generic interface of Mapbox/Maplibre `LayerProps` */
|
|
2
|
+
export interface LayerProps {
|
|
3
|
+
id: string;
|
|
4
|
+
type: 'custom';
|
|
5
|
+
renderingMode: '3d';
|
|
6
|
+
onRemove?(map: MapInstance, gl: WebGLRenderingContext): void;
|
|
7
|
+
onAdd?(map: MapInstance, gl: WebGLRenderingContext): void;
|
|
8
|
+
prerender?(gl: WebGLRenderingContext, matrix: number[]): void;
|
|
9
|
+
render(gl: WebGLRenderingContext, matrix: number[]): void;
|
|
10
|
+
}
|
|
11
|
+
/** Generic interface of Mapbox/Maplibre `LngLatLike` */
|
|
12
|
+
export type LngLatLike = {
|
|
13
|
+
lng: number;
|
|
14
|
+
lat: number;
|
|
15
|
+
} | {
|
|
16
|
+
lon: number;
|
|
17
|
+
lat: number;
|
|
18
|
+
} | [
|
|
19
|
+
number,
|
|
20
|
+
number
|
|
21
|
+
];
|
|
22
|
+
/** Generic interface of Mapbox/Maplibre `static MercatorCoordinate.fromLngLat` */
|
|
23
|
+
export type FromLngLat = (lngLatLike: LngLatLike, altitude?: number) => MercatorCoordinate;
|
|
24
|
+
/** Generic interface of Mapbox/Maplibre typeof `MercatorCoordinate` */
|
|
25
|
+
export interface MercatorCoordinate {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
z?: number;
|
|
29
|
+
meterInMercatorCoordinateUnits(): number;
|
|
30
|
+
}
|
|
31
|
+
/** Generic interface of Mapbox/Maplibre `Map` */
|
|
32
|
+
export interface MapInstance {
|
|
33
|
+
getCanvas(): HTMLCanvasElement;
|
|
34
|
+
triggerRepaint(): void;
|
|
35
|
+
on<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): this;
|
|
36
|
+
off<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): this;
|
|
37
|
+
}
|
|
38
|
+
/** Generic interface of Mapbox/Maplibre `MapEventType` */
|
|
39
|
+
export type MapEventType = {
|
|
40
|
+
resize: MapEvent;
|
|
41
|
+
};
|
|
42
|
+
/** Generic interface of `MapLibreEvent` or `MapBoxEvent` */
|
|
43
|
+
export interface MapEvent<TOrig = unknown> {
|
|
44
|
+
type: string;
|
|
45
|
+
target: MapInstance;
|
|
46
|
+
originalEvent: TOrig;
|
|
47
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ReconcilerRoot, RootState } from "@react-three/fiber";
|
|
2
2
|
import { MutableRefObject } from "react";
|
|
3
3
|
import { MapInstance } from "./generic-map";
|
|
4
|
-
|
|
5
4
|
export type StateRef = MutableRefObject<{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} | undefined
|
|
5
|
+
map: MapInstance;
|
|
6
|
+
root: ReconcilerRoot<HTMLCanvasElement>;
|
|
7
|
+
state?: RootState;
|
|
8
|
+
} | undefined>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RenderProps } from "@react-three/fiber";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
import { Matrix4Tuple } from "three";
|
|
4
|
+
export interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
|
|
5
|
+
frameloop: 'always' | 'demand';
|
|
6
|
+
m4: Matrix4Tuple;
|
|
7
|
+
}
|
|
8
|
+
export declare const useCanvas: ({ m4, children, frameloop, ...renderProps }: useCanvasProps) => {
|
|
9
|
+
id: string;
|
|
10
|
+
onAdd: (map: import("./generic-map").MapInstance, gl: WebGLRenderingContext) => void;
|
|
11
|
+
onRemove: (map: import("./generic-map").MapInstance) => void;
|
|
12
|
+
render: (_gl: WebGL2RenderingContext, matrix: number[]) => void;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useFunction: <T extends (...args: any[]) => any>(callback: T) => T;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RenderProps } from "@react-three/fiber";
|
|
2
|
+
import { MapInstance } from "./generic-map";
|
|
3
|
+
import { StateRef } from "./state-ref";
|
|
4
|
+
export declare function useOnAdd(ref: StateRef, { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>): {
|
|
5
|
+
onAdd: (map: MapInstance, gl: WebGLRenderingContext) => void;
|
|
6
|
+
onRemove: (map: MapInstance) => void;
|
|
7
|
+
mounted: boolean;
|
|
8
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RenderProps } from "@react-three/fiber";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
|
|
4
|
+
longitude: number;
|
|
5
|
+
latitude: number;
|
|
6
|
+
altitude?: number;
|
|
7
|
+
frameloop?: 'always' | 'demand';
|
|
8
|
+
}
|
|
9
|
+
/** react`-three-fiber` canvas inside `MapLibre` */
|
|
10
|
+
export declare const Canvas: import("react").NamedExoticComponent<CanvasProps>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './maplibre/canvas';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FromLngLat } from "./generic-map";
|
|
2
|
+
/** calculate Matrix4 from coordinates */
|
|
3
|
+
export declare function coordsToMatrix({ longitude, latitude, altitude, fromLngLat }: {
|
|
4
|
+
longitude: number;
|
|
5
|
+
latitude: number;
|
|
6
|
+
altitude: number;
|
|
7
|
+
fromLngLat: FromLngLat;
|
|
8
|
+
}): import("three").Matrix4Tuple;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Generic interface of Mapbox/Maplibre `LayerProps` */
|
|
2
|
+
export interface LayerProps {
|
|
3
|
+
id: string;
|
|
4
|
+
type: 'custom';
|
|
5
|
+
renderingMode: '3d';
|
|
6
|
+
onRemove?(map: MapInstance, gl: WebGLRenderingContext): void;
|
|
7
|
+
onAdd?(map: MapInstance, gl: WebGLRenderingContext): void;
|
|
8
|
+
prerender?(gl: WebGLRenderingContext, matrix: number[]): void;
|
|
9
|
+
render(gl: WebGLRenderingContext, matrix: number[]): void;
|
|
10
|
+
}
|
|
11
|
+
/** Generic interface of Mapbox/Maplibre `LngLatLike` */
|
|
12
|
+
export type LngLatLike = {
|
|
13
|
+
lng: number;
|
|
14
|
+
lat: number;
|
|
15
|
+
} | {
|
|
16
|
+
lon: number;
|
|
17
|
+
lat: number;
|
|
18
|
+
} | [
|
|
19
|
+
number,
|
|
20
|
+
number
|
|
21
|
+
];
|
|
22
|
+
/** Generic interface of Mapbox/Maplibre `static MercatorCoordinate.fromLngLat` */
|
|
23
|
+
export type FromLngLat = (lngLatLike: LngLatLike, altitude?: number) => MercatorCoordinate;
|
|
24
|
+
/** Generic interface of Mapbox/Maplibre typeof `MercatorCoordinate` */
|
|
25
|
+
export interface MercatorCoordinate {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
z?: number;
|
|
29
|
+
meterInMercatorCoordinateUnits(): number;
|
|
30
|
+
}
|
|
31
|
+
/** Generic interface of Mapbox/Maplibre `Map` */
|
|
32
|
+
export interface MapInstance {
|
|
33
|
+
getCanvas(): HTMLCanvasElement;
|
|
34
|
+
triggerRepaint(): void;
|
|
35
|
+
on<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): this;
|
|
36
|
+
off<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): this;
|
|
37
|
+
}
|
|
38
|
+
/** Generic interface of Mapbox/Maplibre `MapEventType` */
|
|
39
|
+
export type MapEventType = {
|
|
40
|
+
resize: MapEvent;
|
|
41
|
+
};
|
|
42
|
+
/** Generic interface of `MapLibreEvent` or `MapBoxEvent` */
|
|
43
|
+
export interface MapEvent<TOrig = unknown> {
|
|
44
|
+
type: string;
|
|
45
|
+
target: MapInstance;
|
|
46
|
+
originalEvent: TOrig;
|
|
47
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReconcilerRoot, RootState } from "@react-three/fiber";
|
|
2
|
+
import { MutableRefObject } from "react";
|
|
3
|
+
import { MapInstance } from "./generic-map";
|
|
4
|
+
export type StateRef = MutableRefObject<{
|
|
5
|
+
map: MapInstance;
|
|
6
|
+
root: ReconcilerRoot<HTMLCanvasElement>;
|
|
7
|
+
state?: RootState;
|
|
8
|
+
} | undefined>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RenderProps } from "@react-three/fiber";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
import { Matrix4Tuple } from "three";
|
|
4
|
+
export interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
|
|
5
|
+
frameloop: 'always' | 'demand';
|
|
6
|
+
m4: Matrix4Tuple;
|
|
7
|
+
}
|
|
8
|
+
export declare const useCanvas: ({ m4, children, frameloop, ...renderProps }: useCanvasProps) => {
|
|
9
|
+
id: string;
|
|
10
|
+
onAdd: (map: import("./generic-map").MapInstance, gl: WebGLRenderingContext) => void;
|
|
11
|
+
onRemove: (map: import("./generic-map").MapInstance) => void;
|
|
12
|
+
render: (_gl: WebGL2RenderingContext, matrix: number[]) => void;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useFunction: <T extends (...args: any[]) => any>(callback: T) => T;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RenderProps } from "@react-three/fiber";
|
|
2
|
+
import { MapInstance } from "./generic-map";
|
|
3
|
+
import { StateRef } from "./state-ref";
|
|
4
|
+
export declare function useOnAdd(ref: StateRef, { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>): {
|
|
5
|
+
onAdd: (map: MapInstance, gl: WebGLRenderingContext) => void;
|
|
6
|
+
onRemove: (map: MapInstance) => void;
|
|
7
|
+
mounted: boolean;
|
|
8
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RenderProps } from "@react-three/fiber";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
|
|
4
|
+
longitude: number;
|
|
5
|
+
latitude: number;
|
|
6
|
+
altitude?: number;
|
|
7
|
+
frameloop?: 'always' | 'demand';
|
|
8
|
+
}
|
|
9
|
+
/** react`-three-fiber` canvas inside `MapLibre` */
|
|
10
|
+
export declare const Canvas: import("react").NamedExoticComponent<CanvasProps>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mapbox/canvas';
|
package/maplibre/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-three-map",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Use react-three-fiber inside MapLibre and Mapbox",
|
|
5
5
|
"main": "dist/cjs/main.js",
|
|
6
6
|
"module": "dist/es/main.mjs",
|
|
7
|
-
"types": "
|
|
7
|
+
"types": "dist/types/maplibre.index.d.ts",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"repository": "https://github.com/RodrigoHamuy/react-three-map",
|
|
10
10
|
"homepage": "https://github.com/RodrigoHamuy/react-three-map",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"author": "RodrigoHamuy",
|
|
16
16
|
"scripts": {
|
|
17
|
-
"prebuild": "tsc",
|
|
17
|
+
"prebuild": "tsc --project tsconfig.mapbox.json && tsc --project tsconfig.maplibre.json",
|
|
18
18
|
"build": "yarn build:maplibre && yarn build:mapbox",
|
|
19
19
|
"build:maplibre": "cross-env LIB_MODE=1 MAP_MODE=0 vite build",
|
|
20
20
|
"postbuild:maplibre": "cross-env LIB_MODE=2 MAP_MODE=0 vite build",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"lint": "eslint src example-maplibre/src example-mapbox/src --ext ts,tsx --fix",
|
|
25
25
|
"preview": "vite preview",
|
|
26
26
|
"ts": "tsc -w",
|
|
27
|
+
"ts:check": "tsc",
|
|
27
28
|
"stories": "yarn ladle serve",
|
|
28
29
|
"build:stories": "yarn ladle build"
|
|
29
30
|
},
|
package/docs/basic-app.gif
DELETED
|
Binary file
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "example-mapbox",
|
|
3
|
-
"version": "0.0.0",
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"dev": "yarn ladle serve",
|
|
7
|
-
"ts": "tsc -w"
|
|
8
|
-
},
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"@ladle/react": "^2.15.0",
|
|
11
|
-
"@react-three/drei": "^9.77.10",
|
|
12
|
-
"@react-three/fiber": "^8.13.4",
|
|
13
|
-
"leva": "^0.9.35",
|
|
14
|
-
"mapbox-gl": "^2.15.0",
|
|
15
|
-
"react": "^18.2.0",
|
|
16
|
-
"react-dom": "^18.2.0",
|
|
17
|
-
"react-map-gl": "^7.1.0",
|
|
18
|
-
"react-three-map": "^0.2.1",
|
|
19
|
-
"three": "~0.153.0",
|
|
20
|
-
"three-stdlib": "^2.23.10"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@types/react": "^18.2.14",
|
|
24
|
-
"@types/react-dom": "^18.2.6",
|
|
25
|
-
"@types/three": "^0.152.1",
|
|
26
|
-
"typescript": "^5.1.6",
|
|
27
|
-
"vite": "^4.3.9"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { useFrame, Vector3 } from "@react-three/fiber";
|
|
2
|
-
import { useControls } from "leva";
|
|
3
|
-
import Mapbox from "mapbox-gl";
|
|
4
|
-
import 'mapbox-gl/dist/mapbox-gl.css';
|
|
5
|
-
import { FC, PropsWithChildren, useRef, useState } from "react";
|
|
6
|
-
import Map from 'react-map-gl';
|
|
7
|
-
import { Canvas } from "react-three-map";
|
|
8
|
-
import { Mesh } from "three";
|
|
9
|
-
|
|
10
|
-
export default { title: 'Canvas' }
|
|
11
|
-
|
|
12
|
-
const Box: FC<{ position: Vector3 }> = (props) => {
|
|
13
|
-
// This reference gives us direct access to the THREE.Mesh object
|
|
14
|
-
const ref = useRef<Mesh>(null)
|
|
15
|
-
// Hold state for hovered and clicked events
|
|
16
|
-
const [hovered, hover] = useState(false)
|
|
17
|
-
const [clicked, click] = useState(false)
|
|
18
|
-
// Subscribe this component to the render-loop, rotate the mesh every frame
|
|
19
|
-
useFrame((_state, delta) => {
|
|
20
|
-
if (!ref.current) return;
|
|
21
|
-
ref.current.rotation.x += delta;
|
|
22
|
-
ref.current.rotation.z -= delta;
|
|
23
|
-
})
|
|
24
|
-
// Return the view, these are regular Threejs elements expressed in JSX
|
|
25
|
-
return (
|
|
26
|
-
<mesh
|
|
27
|
-
{...props}
|
|
28
|
-
ref={ref}
|
|
29
|
-
scale={clicked ? 1.5 : 1}
|
|
30
|
-
onClick={() => click(!clicked)}
|
|
31
|
-
onPointerOver={() => hover(true)}
|
|
32
|
-
onPointerOut={() => hover(false)}>
|
|
33
|
-
<boxGeometry args={[1, 1, 1]} />
|
|
34
|
-
<meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
|
|
35
|
-
</mesh>
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function BasicExample() {
|
|
40
|
-
|
|
41
|
-
const { mapboxToken } = useControls({
|
|
42
|
-
mapboxToken: {
|
|
43
|
-
value: import.meta.env.VITE_MAPBOX_TOKEN || '',
|
|
44
|
-
label: 'mapbox token',
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
Mapbox.accessToken = mapboxToken;
|
|
49
|
-
|
|
50
|
-
return <div style={{ height: '100vh' }}>
|
|
51
|
-
{!mapboxToken && <Center>Add a mapbox token to load this component</Center>}
|
|
52
|
-
{mapboxToken && <Map
|
|
53
|
-
antialias
|
|
54
|
-
initialViewState={{
|
|
55
|
-
latitude: 51,
|
|
56
|
-
longitude: 0,
|
|
57
|
-
zoom: 13,
|
|
58
|
-
pitch: 60,
|
|
59
|
-
}}
|
|
60
|
-
mapStyle="mapbox://styles/mapbox/streets-v12"
|
|
61
|
-
>
|
|
62
|
-
<Canvas latitude={51} longitude={0}>
|
|
63
|
-
<hemisphereLight
|
|
64
|
-
args={["#ffffff", "#60666C"]}
|
|
65
|
-
position={[1, 4.5, 3]}
|
|
66
|
-
/>
|
|
67
|
-
<object3D scale={500}>
|
|
68
|
-
<Box position={[-1.2, 1, 0]} />
|
|
69
|
-
<Box position={[1.2, 1, 0]} />
|
|
70
|
-
</object3D>
|
|
71
|
-
</Canvas>
|
|
72
|
-
</Map>}
|
|
73
|
-
</div>
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const Center = ({ children }: PropsWithChildren) => (
|
|
77
|
-
<div style={{
|
|
78
|
-
display: 'flex',
|
|
79
|
-
height: '100%',
|
|
80
|
-
width: '100%',
|
|
81
|
-
alignItems: 'center',
|
|
82
|
-
justifyContent: 'center',
|
|
83
|
-
}}>{children}</div>
|
|
84
|
-
)
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { MapControls } from "@react-three/drei";
|
|
2
|
-
import { Canvas as FiberCanvas } from "@react-three/fiber";
|
|
3
|
-
import { Canvas } from "react-three-map";
|
|
4
|
-
import { MyScene } from "./my-scene";
|
|
5
|
-
import { StoryMap } from "./story-map";
|
|
6
|
-
import { useControls } from "leva";
|
|
7
|
-
|
|
8
|
-
export function WithMap() {
|
|
9
|
-
const showCamHelper = useShowCamHelper()
|
|
10
|
-
return <div style={{ height: '100vh' }}>
|
|
11
|
-
<StoryMap latitude={51.5073218} longitude={-0.1276473} zoom={18}>
|
|
12
|
-
<Canvas latitude={51.5073218} longitude={-0.1276473} shadows="variance">
|
|
13
|
-
<MyScene showCamHelper={showCamHelper} />
|
|
14
|
-
</Canvas>
|
|
15
|
-
</StoryMap>
|
|
16
|
-
</div>
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const WithoutMap = () => {
|
|
20
|
-
const showCamHelper = useShowCamHelper()
|
|
21
|
-
return <div style={{ height: '100vh' }}>
|
|
22
|
-
<FiberCanvas camera={{ position: [100, 100, 100] }} shadows="variance">
|
|
23
|
-
<MyScene showCamHelper={showCamHelper} />
|
|
24
|
-
<MapControls makeDefault />
|
|
25
|
-
</FiberCanvas>
|
|
26
|
-
</div>
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const useShowCamHelper = () => {
|
|
30
|
-
const { showCamHelper } = useControls({
|
|
31
|
-
showCamHelper: {
|
|
32
|
-
value: false,
|
|
33
|
-
label: 'show camera helper'
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return showCamHelper
|
|
37
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Box, Html } from "@react-three/drei";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { Canvas } from "react-three-map";
|
|
4
|
-
import { MathUtils } from "three";
|
|
5
|
-
import { StoryMap } from "./story-map";
|
|
6
|
-
|
|
7
|
-
export function Default() {
|
|
8
|
-
|
|
9
|
-
const [hovered, hover] = useState(false);
|
|
10
|
-
|
|
11
|
-
return <StoryMap latitude={51} longitude={0} zoom={13}>
|
|
12
|
-
<Canvas latitude={51} longitude={0} frameloop="demand">
|
|
13
|
-
<Html center position={[0, 250, 0]} style={{ textAlign: 'center', fontSize: '2em', width: '10em', lineHeight: '1.5em' }}><i>Some</i> <b>HTML</b><br />content!</Html>
|
|
14
|
-
<Box
|
|
15
|
-
args={[500, 500, 500]}
|
|
16
|
-
position={[0, 250, 0]}
|
|
17
|
-
rotation={[0, 45 * MathUtils.DEG2RAD, 0]}
|
|
18
|
-
onPointerOver={() => hover(true)}
|
|
19
|
-
onPointerOut={() => hover(false)}
|
|
20
|
-
material-color={hovered ? 'purple' : 'orange'}
|
|
21
|
-
/>
|
|
22
|
-
</Canvas>
|
|
23
|
-
</StoryMap>
|
|
24
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Box, Plane, useHelper } from "@react-three/drei";
|
|
2
|
-
import { MeshProps, useFrame, useThree } from '@react-three/fiber';
|
|
3
|
-
import { useCallback, useRef, useState } from 'react';
|
|
4
|
-
import { CameraHelper, MathUtils, Mesh, OrthographicCamera } from "three";
|
|
5
|
-
|
|
6
|
-
export function MyScene({ showCamHelper }: { showCamHelper?: boolean }) {
|
|
7
|
-
return <>
|
|
8
|
-
<Lights showCamHelper={showCamHelper} />
|
|
9
|
-
<Floor />
|
|
10
|
-
<MyBox position={[-8 * 3, 8 * 1.5, 0]} />
|
|
11
|
-
<MyBox position={[8 * 3, 8 * 1.5, 0]} />
|
|
12
|
-
</>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function MyBox(props: MeshProps) {
|
|
17
|
-
const [hovered, hover] = useState(false);
|
|
18
|
-
const mesh = useRef<Mesh>(null)
|
|
19
|
-
const invalidate = useThree(st => st.invalidate);
|
|
20
|
-
|
|
21
|
-
const onOver = useCallback(() => {
|
|
22
|
-
hover(true);
|
|
23
|
-
}, [])
|
|
24
|
-
|
|
25
|
-
const onOut = useCallback(() => {
|
|
26
|
-
hover(false);
|
|
27
|
-
}, [])
|
|
28
|
-
|
|
29
|
-
useFrame((_st, dt) => {
|
|
30
|
-
if (!mesh.current) return;
|
|
31
|
-
mesh.current.rotateY(dt);
|
|
32
|
-
invalidate();
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<Box
|
|
37
|
-
{...props}
|
|
38
|
-
ref={mesh}
|
|
39
|
-
args={[16, 16, 16]}
|
|
40
|
-
receiveShadow
|
|
41
|
-
castShadow
|
|
42
|
-
onClick={onOver}
|
|
43
|
-
onPointerOver={onOver}
|
|
44
|
-
onPointerOut={onOut}
|
|
45
|
-
>
|
|
46
|
-
<meshStandardMaterial
|
|
47
|
-
color={hovered ? "red" : "orange"}
|
|
48
|
-
metalness={.75}
|
|
49
|
-
roughness={.5}
|
|
50
|
-
/>
|
|
51
|
-
</Box>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
function Lights({ showCamHelper }: { showCamHelper?: boolean }) {
|
|
55
|
-
const cam = useRef<OrthographicCamera>(null);
|
|
56
|
-
const noCam = useRef<OrthographicCamera>(null);
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
-
useHelper((showCamHelper ? cam : noCam) as any, CameraHelper)
|
|
59
|
-
const camSize = 100;
|
|
60
|
-
return <>
|
|
61
|
-
<ambientLight intensity={0.5} />
|
|
62
|
-
<directionalLight
|
|
63
|
-
castShadow
|
|
64
|
-
position={[2.5, 50, 5]}
|
|
65
|
-
intensity={1.5}
|
|
66
|
-
shadow-mapSize={1024}
|
|
67
|
-
>
|
|
68
|
-
<orthographicCamera
|
|
69
|
-
ref={cam}
|
|
70
|
-
attach="shadow-camera"
|
|
71
|
-
args={[-camSize, camSize, -camSize, camSize, 0.1, 100]}
|
|
72
|
-
rotation={[0, 90 * MathUtils.DEG2RAD, 0]}
|
|
73
|
-
/>
|
|
74
|
-
</directionalLight>
|
|
75
|
-
<pointLight position={[-10, 0, -20]} color="white" intensity={1} />
|
|
76
|
-
<pointLight position={[0, -10, 0]} intensity={1} />
|
|
77
|
-
</>
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function Floor() {
|
|
81
|
-
return <Plane
|
|
82
|
-
args={[200, 200]}
|
|
83
|
-
position={[0, 0, 0]}
|
|
84
|
-
rotation={[-90 * MathUtils.DEG2RAD, 0, 0]}
|
|
85
|
-
receiveShadow
|
|
86
|
-
>
|
|
87
|
-
<shadowMaterial opacity={.5} />
|
|
88
|
-
</Plane>
|
|
89
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Box, Stats } from "@react-three/drei";
|
|
2
|
-
import { useRef, useState } from "react";
|
|
3
|
-
import { Canvas } from "react-three-map";
|
|
4
|
-
import { MathUtils } from "three";
|
|
5
|
-
import { StoryMap } from "./story-map";
|
|
6
|
-
|
|
7
|
-
export function Default() {
|
|
8
|
-
|
|
9
|
-
const [hovered, hover] = useState(false);
|
|
10
|
-
|
|
11
|
-
const ref = useRef<HTMLDivElement>(null)
|
|
12
|
-
|
|
13
|
-
return <div style={{ height: '100vh', position: 'relative' }}>
|
|
14
|
-
<style>{`.stats{position:absolute !important}`}</style>
|
|
15
|
-
<StoryMap latitude={51} longitude={0} zoom={13}>
|
|
16
|
-
<Canvas latitude={51} longitude={0} frameloop="demand">
|
|
17
|
-
<Box
|
|
18
|
-
args={[500, 500, 500]}
|
|
19
|
-
position={[0, 250, 0]}
|
|
20
|
-
rotation={[0, 45 * MathUtils.DEG2RAD, 0]}
|
|
21
|
-
onPointerOver={() => hover(true)}
|
|
22
|
-
onPointerOut={() => hover(false)}
|
|
23
|
-
material-color={hovered ? 'purple' : 'orange'}
|
|
24
|
-
/>
|
|
25
|
-
<Stats className="stats" parent={ref} />
|
|
26
|
-
</Canvas>
|
|
27
|
-
</StoryMap>
|
|
28
|
-
<div style={{ position: 'absolute', bottom: 0, right: 0, left: 0, background: '#ffffffc2', padding: '15px 20px 40px' }}>
|
|
29
|
-
Hover over the box, it will only render once to change colour, or when you move the camera. Look at the stats to confirm.
|
|
30
|
-
</div>
|
|
31
|
-
</div>
|
|
32
|
-
}
|