This commit is contained in:
Adam 2023-04-16 08:18:32 -04:00
parent 24b6324ed6
commit b781a564ea

View file

@ -1,14 +1,8 @@
import { createSignal, Show } from 'solid-js'; import { createSignal, Show } from 'solid-js';
import * as maplibre from 'maplibre-gl'; import * as maplibre from 'maplibre-gl';
import MapGL, { import MapGL, { Viewport, Camera, Layer, Popup, Marker } from 'solid-map-gl';
Viewport, import { MapboxLayer } from '@deck.gl/mapbox/typed';
Light, import { ArcLayer, ScatterplotLayer } from '@deck.gl/layers/typed';
Camera,
Source,
Layer,
} from 'solid-map-gl';
import { MapboxLayer } from '@deck.gl/mapbox';
import { ArcLayer } from '@deck.gl/layers';
import MapControls from './MapControls'; import MapControls from './MapControls';
@ -19,29 +13,9 @@ import 'maplibre-gl/dist/maplibre-gl.css';
function BadassMap(): JSX.Element { function BadassMap(): JSX.Element {
// data stuff
const FANEUIL_HALL: number[] = [-71.05625, 42.36] const FANEUIL_HALL: number[] = [-71.05625, 42.36]
const GD_TAVERN: number[] = [-71.056922, 42.360919] const GD_TAVERN: number[] = [-71.056922, 42.360919]
const FAKE_GJSON = {
type: 'geojson',
data: {
"type": "FeatureCollection", "features": [
{ "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
const TILES_URL: string = 'https://api.maptiler.com/maps/024da34e-fa66-4cb3-8f5f-0466b51e972e/style.json?key=Ukl2QNcQUCPAwuelQOvM' const TILES_URL: string = 'https://api.maptiler.com/maps/024da34e-fa66-4cb3-8f5f-0466b51e972e/style.json?key=Ukl2QNcQUCPAwuelQOvM'
const options: MapOptions = { const options: MapOptions = {
container: 'solid-map-gl will override me', container: 'solid-map-gl will override me',
@ -59,7 +33,7 @@ function BadassMap(): JSX.Element {
const [rotate, setRotate] = createSignal<boolean>(true); const [rotate, setRotate] = createSignal<boolean>(true);
const toggleRotate = () => setRotate<boolean>(!rotate()); const toggleRotate = () => setRotate<boolean>(!rotate());
const myDeckLayer = new MapboxLayer({ const arcLayer = new MapboxLayer({
id: 'deckgl-arc', id: 'deckgl-arc',
type: ArcLayer, type: ArcLayer,
data: [ data: [
@ -72,6 +46,19 @@ function BadassMap(): JSX.Element {
getWidth: 8, getWidth: 8,
}); });
const scatterplotLayer = new MapboxLayer({
id: 'deckgl-scatterplot',
type: ScatterplotLayer,
data: [
{ coordinates: FANEUIL_HALL },
{ coordinates: GD_TAVERN },
],
getPosition: (d: any) => d.coordinates,
getRadius: 30,
getFillColor: [255, 140, 0],
getLineColor: [0, 0, 0,]
});
return ( return (
<MapGL <MapGL
mapLib={maplibre} mapLib={maplibre}
@ -79,20 +66,21 @@ function BadassMap(): JSX.Element {
viewport={viewport()} viewport={viewport()}
onViewportChange={(evt: Viewport) => setViewport(evt)} onViewportChange={(evt: Viewport) => setViewport(evt)}
> >
<Source source={FAKE_GJSON} > <Layer customLayer={arcLayer} />
<Layer style={RED_DOT} /> <Layer customLayer={scatterplotLayer} />
</Source>
<Layer customLayer={myDeckLayer} /> <Marker
lngLat={FANEUIL_HALL}
options={{ color: '#900' }}
>
hi
</Marker>
<MapControls /> <MapControls />
<Camera <Camera
rotateViewport={rotate()} rotateViewport={rotate()}
reverse={true} reverse={true}
/> />
<Light style={{
anchor: 'viewport',
color: 'white',
intensity: 0.9,
}} />
<Show <Show
when={rotate()} when={rotate()}
fallback={<button onClick={toggleRotate}> Rotation On </button>} fallback={<button onClick={toggleRotate}> Rotation On </button>}