maps/lightning/src/components/BadassMap.tsx

107 lines
3 KiB
TypeScript
Raw Normal View History

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 MapGL, {
Viewport,
Light,
Camera,
Source,
Layer,
} from 'solid-map-gl';
import { MapboxLayer } from '@deck.gl/mapbox';
import { ArcLayer } from '@deck.gl/layers';
import MapControls from './MapControls';
2023-04-15 07:59:50 -04:00
import type { JSX } from 'solid-js';
import type { MapOptions } from 'maplibre-gl';
2023-04-15 01:21:33 -04:00
import 'maplibre-gl/dist/maplibre-gl.css';
2023-04-15 22:01:38 -04:00
2023-04-15 07:59:50 -04:00
function BadassMap(): JSX.Element {
2023-04-16 04:49:13 -04:00
// data stuff
const FANEUIL_HALL: number[] = [-71.05625, 42.36]
const GD_TAVERN: number[] = [-71.056922, 42.360919]
const FAKE_GJSON = {
type: 'geojson',
2023-04-16 06:28:07 -04:00
data: {
"type": "FeatureCollection", "features": [
2023-04-16 04:49:13 -04:00
{ "type": "Feature", "geometry": { "type": "Point", "coordinates": FANEUIL_HALL } },
{ "type": "Feature", "geometry": { "type": "Point", "coordinates": GD_TAVERN } },
],
}
};
// markers
const RED_DOT = {
type: 'circle',
paint: {
'circle-radius': 4,
'circle-color': 'red',
}
};
// map stuff
2023-04-15 22:05:53 -04:00
const TILES_URL: string = 'https://api.maptiler.com/maps/024da34e-fa66-4cb3-8f5f-0466b51e972e/style.json?key=Ukl2QNcQUCPAwuelQOvM'
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',
style: TILES_URL,
2023-04-15 07:59:50 -04:00
maxPitch: 85,
antialias: true,
2023-04-16 04:49:13 -04:00
};
2023-04-15 22:01:38 -04:00
const INITIAL_VIEW_STATE: Viewport = {
2023-04-16 04:49:13 -04:00
center: FANEUIL_HALL,
2023-04-15 01:21:33 -04:00
zoom: 15.5,
bearing: 160,
pitch: 60,
2023-04-16 04:49:13 -04:00
};
2023-04-15 22:01:38 -04:00
const [viewport, setViewport] = createSignal<Viewport>(INITIAL_VIEW_STATE);
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-16 06:28:07 -04:00
const myDeckLayer = new MapboxLayer({
id: 'deckgl-arc',
type: ArcLayer,
data: [
{ source: FANEUIL_HALL, target: GD_TAVERN },
],
getSourcePosition: (d: any) => d.source,
getTargetPosition: (d: any) => d.target,
getSourceColor: [255, 208, 0],
getTargetColor: [0, 128, 255],
getWidth: 8,
});
2023-04-15 05:34:42 -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-16 04:49:13 -04:00
<Source source={FAKE_GJSON} >
<Layer style={RED_DOT} />
</Source>
2023-04-16 06:28:07 -04:00
<Layer customLayer={myDeckLayer} />
2023-04-15 09:18:55 -04:00
<MapControls />
2023-04-16 04:49:13 -04:00
<Camera
rotateViewport={rotate()}
reverse={true}
/>
2023-04-15 01:21:33 -04:00
<Light style={{
anchor: 'viewport',
color: 'white',
intensity: 0.9,
}} />
2023-04-16 04:49:13 -04:00
<Show
when={rotate()}
fallback={<button onClick={toggleRotate}> Rotation On </button>}
>
<button onClick={toggleRotate}> Rotation Off </button>
</Show>
</MapGL >
2023-04-15 01:21:33 -04:00
);
};
2023-04-15 07:59:50 -04:00
export default BadassMap;