Skip to content

Commit 30624db

Browse files
committed
add Mapbox
1 parent e47e180 commit 30624db

12 files changed

+40
-22
lines changed

index.html

Lines changed: 0 additions & 13 deletions
This file was deleted.

public/vite.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/canvas/canvas-mapbox.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { RenderProps, extend } from "@react-three/fiber";
2+
import { PropsWithChildren, memo, useMemo } from "react";
3+
import * as THREE from "three";
4+
import { coordsToMatrix } from "./core/coords-to-matrix";
5+
import { InternalCanvas } from "./core/internal-canvas";
6+
import { MercatorCoordinate } from "mapbox-gl";
7+
8+
extend(THREE);
9+
10+
export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
11+
longitude: number,
12+
latitude: number,
13+
altitude?: number,
14+
frameloop?: 'always' | 'demand',
15+
}
16+
17+
/** react`-three-fiber` canvas inside `Mapbox` */
18+
export const Canvas = memo<CanvasProps>(({
19+
longitude, latitude, altitude = 0,
20+
frameloop = 'always', ...renderProps
21+
}) => {
22+
23+
const m4 = useMemo(() => coordsToMatrix({
24+
latitude, longitude, altitude, fromLngLat: MercatorCoordinate.fromLngLat,
25+
}), [latitude, longitude, altitude])
26+
27+
return <InternalCanvas
28+
frameloop={frameloop}
29+
m4={m4}
30+
{...renderProps}
31+
/>
32+
})
File renamed without changes.

src/canvas/core/generic-map.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// quick mock of functions used by Maplibre and Mapbox
1+
// mock of functions used by `react-three-map` from `Maplibre` or `Mapbox`
22

33
/** Generic interface of Mapbox/Maplibre `LngLatLike` */
44
export type LngLatLike = {
@@ -19,7 +19,7 @@ export type FromLngLat = (lngLatLike: LngLatLike, altitude?: number) => Mercator
1919
export interface MercatorCoordinate {
2020
x: number;
2121
y: number;
22-
z: number;
22+
z?: number;
2323
meterInMercatorCoordinateUnits(): number;
2424
}
2525

src/main-maplibre.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './canvas/canvas-maplibre';

src/main.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/stories/canvas.basic.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'maplibre-gl/dist/maplibre-gl.css';
33
import { FC, useRef, useState } from "react";
44
import Map from 'react-map-gl';
55
import { Mesh } from "three";
6-
import { Canvas } from "../canvas/canvas";
6+
import { Canvas } from "../canvas/canvas-maplibre";
77
import MapLibre from "maplibre-gl";
88

99
export default {title: 'Canvas'}

src/stories/comparison.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ThemeState, useLadleContext } from "@ladle/react";
22
import 'maplibre-gl/dist/maplibre-gl.css';
33
import Map from 'react-map-gl';
4-
import { Canvas } from "../canvas/canvas";
4+
import { Canvas } from "../canvas/canvas-maplibre";
55
import { Canvas as FiberCanvas } from "@react-three/fiber"
66
import { MyScene } from "./my-scene";
77
import { MapControls } from "@react-three/drei"

src/stories/html-on-top.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Box, Html, Stats } from "@react-three/drei";
22
import 'maplibre-gl/dist/maplibre-gl.css';
33
import { useState } from "react";
44
import { MathUtils } from "three";
5-
import { Canvas } from "../canvas/canvas";
5+
import { Canvas } from "../canvas/canvas-maplibre";
66
import { StoryMap } from "./story-map";
77

88
export function Default() {

0 commit comments

Comments
 (0)