maps/lightning/src/components/BadassMap.tsx

95 lines
2.9 KiB
TypeScript
Raw Normal View History

2023-04-17 05:05:31 -04:00
import MapGL, { Viewport, Camera, Marker } from 'solid-map-gl';
2023-04-15 07:59:50 -04:00
import { createSignal, Show } from 'solid-js';
2023-04-15 01:21:33 -04:00
import * as maplibre from 'maplibre-gl';
2023-04-16 06:28:07 -04:00
import MapControls from './MapControls';
2023-04-17 05:05:31 -04:00
// deck.gl
import { unstable_clientOnly } from 'solid-start';
const MapScatLayer = unstable_clientOnly(() => import('~/components/MapScatLayer'));
const MapArcLayer = unstable_clientOnly(() => import('~/components/MapArcLayer'));
2023-04-15 07:59:50 -04:00
import type { JSX } from 'solid-js';
import type { MapOptions } from 'maplibre-gl';
2023-04-17 05:05:31 -04:00
import type { StyleSpecification } from 'maplibre-gl';
2023-04-15 07:59:50 -04:00
2023-04-15 01:21:33 -04:00
import 'maplibre-gl/dist/maplibre-gl.css';
2023-04-17 06:35:37 -04:00
import * as MAP_STYLE from '~/style.json'
2023-04-15 01:21:33 -04:00
2023-04-16 20:03:33 -04:00
// test data
const FANEUIL_HALL: number[] = [-71.05625, 42.36]
const GD_TAVERN: number[] = [-71.056922, 42.360919]
const BBC: number[] = [-71.103, 42.3145]
const GARDEN: number[] = [-71.062228, 42.366303]
const PR_HOUSE: number[] = [-71.053678, 42.363722]
const ARC_DATA = [
{ source: FANEUIL_HALL, target: GD_TAVERN },
{ source: FANEUIL_HALL, target: BBC },
{ source: FANEUIL_HALL, target: GARDEN },
{ source: FANEUIL_HALL, target: PR_HOUSE },
];
const SCAT_DATA = [
{ coordinates: FANEUIL_HALL },
{ coordinates: GD_TAVERN },
{ coordinates: BBC },
{ coordinates: GARDEN },
{ coordinates: PR_HOUSE },
];
2023-04-17 05:05:31 -04:00
const TILES_URL: string = 'https://api.maptiler.com/maps/024da34e-fa66-4cb3-8f5f-0466b51e972e/style.json?key=Ukl2QNcQUCPAwuelQOvM';
2023-04-16 04:49:13 -04:00
2023-04-17 05:05:31 -04:00
function BadassMap(): JSX.Element {
const MY_LOC = FANEUIL_HALL;
2023-04-15 07:59:50 -04:00
const options: MapOptions = {
2023-04-15 22:01:38 -04:00
container: 'solid-map-gl will override me',
2023-04-17 06:35:37 -04:00
style: MAP_STYLE,
2023-04-15 07:59:50 -04:00
maxPitch: 85,
antialias: true,
2023-04-17 06:35:37 -04:00
renderWorldCopies: false,
2023-04-16 04:49:13 -04:00
};
2023-04-17 05:05:31 -04:00
2023-04-17 06:35:37 -04:00
const [viewport, setViewport] = createSignal<Viewport>();
2023-04-16 04:49:13 -04:00
const [rotate, setRotate] = createSignal<boolean>(true);
const toggleRotate = () => setRotate<boolean>(!rotate());
2023-04-15 07:59:50 -04:00
2023-04-15 01:21:33 -04:00
return (
<MapGL
mapLib={maplibre}
2023-04-15 07:59:50 -04:00
options={options}
2023-04-15 01:21:33 -04:00
viewport={viewport()}
onViewportChange={(evt: Viewport) => setViewport(evt)}
2023-04-17 06:35:37 -04:00
onDrag={() => setRotate(false)}
onMouseDown={() => setRotate(false)}
onTouchStart={() => setRotate(false)}
2023-04-17 10:24:08 -04:00
onZoomStart={() => setRotate(false)}
2023-04-15 01:21:33 -04:00
>
2023-04-16 20:03:33 -04:00
<MapScatLayer data={SCAT_DATA} />
<MapArcLayer data={ARC_DATA} />
2023-04-16 08:18:32 -04:00
<Marker
2023-04-17 05:05:31 -04:00
lngLat={MY_LOC}
2023-04-16 08:18:32 -04:00
options={{ color: '#900' }}
2023-04-16 04:49:13 -04:00
>
2023-04-16 08:18:32 -04:00
hi
</Marker>
2023-04-16 19:07:30 -04:00
<Camera
rotateViewport={rotate()}
reverse={true}
/>
2023-04-17 05:05:31 -04:00
2023-04-16 19:07:30 -04:00
<Show
when={rotate()}
fallback={<button onClick={toggleRotate}> Rotation On </button>}
>
<button onClick={toggleRotate}> Rotation Off </button>
</Show>
<MapControls />
2023-04-16 04:49:13 -04:00
</MapGL >
2023-04-15 01:21:33 -04:00
);
};
2023-04-15 07:59:50 -04:00
export default BadassMap;