maps/lightning/src/components/BadassMap.tsx

82 lines
2.7 KiB
TypeScript
Raw Normal View History

2023-04-20 09:16:30 -04:00
import MapGL, { Viewport, Camera } from 'solid-map-gl';
2023-04-21 08:32:26 -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-21 08:32:26 -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-21 19:59:35 -04:00
import styleJson from '~/style/style.json';
2023-04-22 01:20:30 -04:00
import { arcData, scatData, viewport, setViewport, rotate, setRotate } from '~/root';
2023-04-21 08:32:26 -04:00
const MAP_STYLE: StyleSpecification = styleJson;
2023-04-20 02:51:55 -04:00
2023-04-20 09:16:30 -04:00
const TEST = {
2023-04-21 08:32:26 -04:00
FAN: { LngLatLike: { lng: -71.05625, lat: 42.36, }, coords: [-71.05625, 42.36] },
GDT: { LngLatLike: { lng: -71.056922, lat: 42.360919 }, coords: [-71.056922, 42.360919], },
BBC: { LngLatLike: { lng: -71.103, lat: 42.3145 }, coords: [-71.103, 42.3145], },
GAR: { LngLatLike: { lng: -71.062228, lat: 42.366303 }, coords: [-71.062228, 42.366303], },
PRH: { LngLatLike: { lng: -71.053678, lat: 42.363722 }, coords: [-71.053678, 42.363722], },
NSE: { LngLatLike: { lng: -74.0112660425065, lat: 40.70689167578798 }, coords: [-74.0112660425065, 40.70689167578798], },
2023-04-20 09:16:30 -04:00
};
const options: MapOptions = {
container: 'solid-map-gl will override me',
style: MAP_STYLE,
maxPitch: 85,
antialias: true,
renderWorldCopies: false,
2023-04-20 02:51:55 -04:00
};
2023-04-21 08:32:26 -04:00
function BadassMap(props: any): JSX.Element {
2023-04-17 05:05:31 -04:00
2023-04-21 08:32:26 -04:00
async function eventHandler(event: any) {
2023-04-20 02:51:55 -04:00
switch (event.type) {
case 'mousedown':
setRotate(false)
break;
case 'zoomstart':
setRotate(false)
break;
case 'touchstart':
setRotate(false)
break;
case 'drag':
setRotate(false)
break;
};
};
2023-04-15 01:21:33 -04:00
return (
2023-04-21 08:32:26 -04:00
<>
<MapGL
mapLib={maplibre}
options={options}
viewport={viewport()}
onViewportChange={(evt: Viewport) => setViewport(evt)}
onDrag={eventHandler}
onMouseDown={eventHandler}
onZoomStart={eventHandler}
onTouchStart={eventHandler}
transitionType="flyTo"
>
<MapScatLayer data={scatData()} />
<MapArcLayer data={arcData()} />
2023-04-16 08:18:32 -04:00
2023-04-21 08:32:26 -04:00
<Camera rotateViewport={rotate()} reverse={true} />
2023-04-16 08:18:32 -04:00
2023-04-21 08:32:26 -04:00
<MapControls />
</MapGL >
</>
) as JSX.Element;
2023-04-15 01:21:33 -04:00
};
2023-04-15 07:59:50 -04:00
export default BadassMap;