Skip to content

Commit

Permalink
Add tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcth committed May 9, 2024
1 parent 90abf03 commit c1e8e46
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/map/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import { Protocol } from "pmtiles";
import { useEffect } from "react";
import { createRoot } from "react-dom/client";
import { Map, MapProvider } from "react-map-gl";
import { GeoJsonLayer } from "deck.gl/typed";

import DataTileLayer from "../layers/datatile-layer.tsx";
import { MenuState, SearchView } from "../types.tsx";
import { useMenuStore } from "./Store.tsx";

import { PickingInfo } from "@deck.gl/core";
import { useCallback } from "react";

const INITIAL_VIEW_STATE = {
latitude: 62.5,
longitude: 16,
Expand Down Expand Up @@ -179,14 +183,42 @@ export function App() {
}),
);

layers.push(
new GeoJsonLayer<BlockProperties>({
id: "geojson",
data: "http://localhost:5173/Kommun_Sweref99TM.geojson",
opacity: 0.8,
stroked: true,
filled: true,
getFillColor: [100, 100, 100, 50],
getLineColor: [255, 255, 255, 255],
getLineWidth: 2,
lineWidthMinPixels: 1,
pickable: true,
}),
);

return layers;
});

const getTooltip = useCallback(({ object }: PickingInfo<DataType>) => {
console.log(object);
return (
object && {
html: `<h2>Message:</h2> <div>${object.properties.KnNamn}</div>`,
style: {
backgroundColor: "#000",
fontSize: "0.8em",
},
}
);
}, []);

return (
<DeckGL
initialViewState={searchView}
layers={layers2}
controller={{ inertia: 500, scrollZoom: { speed: 0.2, smooth: false } }}
controller={{ inertia: 500, scrollZoom: { speed: 0.01, smooth: false } }}
ContextProvider={MapProvider}
onViewStateChange={({ viewState }) => {
setZoom(viewState.zoom);
Expand All @@ -195,6 +227,7 @@ export function App() {
...viewState,
};
}}
getTooltip={getTooltip}
>
<Map
style={{ width: "100vw", height: "100vh", margin: "0 auto" }}
Expand Down

0 comments on commit c1e8e46

Please sign in to comment.