mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
prettier formatting
This commit is contained in:
@@ -101,7 +101,9 @@ function App() {
|
||||
return (
|
||||
<div>
|
||||
<Header>
|
||||
<Title href="/" onClick={clear}>PMTiles Viewer</Title>
|
||||
<Title href="/" onClick={clear}>
|
||||
PMTiles Viewer
|
||||
</Title>
|
||||
<GithubLink>
|
||||
<GithubA href="https://github.com/protomaps/PMTiles" target="_blank">
|
||||
<GitHubLogoIcon /> {GIT_SHA}
|
||||
|
||||
@@ -88,11 +88,15 @@ interface LayerVisibility {
|
||||
visible: boolean;
|
||||
}
|
||||
|
||||
const LayersVisibilityController = (props: { layers: LayerVisibility[], onChange: (layers: LayerVisibility[]) => void }) => {
|
||||
const LayersVisibilityController = (props: {
|
||||
layers: LayerVisibility[];
|
||||
onChange: (layers: LayerVisibility[]) => void;
|
||||
}) => {
|
||||
const { layers, onChange } = props;
|
||||
const allLayersCheckboxRef = useRef<HTMLInputElement>(null);
|
||||
const visibleLayersCount = layers.filter(l => l.visible).length;
|
||||
const indeterminate = visibleLayersCount > 0 && visibleLayersCount !== layers.length;
|
||||
const visibleLayersCount = layers.filter((l) => l.visible).length;
|
||||
const indeterminate =
|
||||
visibleLayersCount > 0 && visibleLayersCount !== layers.length;
|
||||
|
||||
useEffect(() => {
|
||||
if (allLayersCheckboxRef.current) {
|
||||
@@ -110,13 +114,17 @@ const LayersVisibilityController = (props: { layers: LayerVisibility[], onChange
|
||||
}
|
||||
|
||||
const toggleAllLayers = () => {
|
||||
const someLayersAreHidden = visibleLayersCount !== layers.length;
|
||||
onChange(layers.map(l => ({...l, visible: someLayersAreHidden})));
|
||||
const visible = visibleLayersCount !== layers.length;
|
||||
const newLayersVisibility = layers.map((l) => ({ ...l, visible }));
|
||||
onChange(newLayersVisibility);
|
||||
};
|
||||
|
||||
const toggleLayer = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const layerId = event.target.getAttribute("data-layer-id");
|
||||
onChange(layers.map(l => (l.id === layerId ? {...l, visible: !l.visible} : l)));
|
||||
const newLayersVisibility = layers.map((l) =>
|
||||
l.id === layerId ? { ...l, visible: !l.visible } : l
|
||||
);
|
||||
onChange(newLayersVisibility);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -284,7 +292,10 @@ const vectorStyle = async (file: PMTiles): Promise<any> => {
|
||||
glyphs: "https://cdn.protomaps.com/fonts/pbf/{fontstack}/{range}.pbf",
|
||||
layers: layers,
|
||||
},
|
||||
layersVisibility: vector_layers.map((l: any) => ({id: l.id, visible: true})),
|
||||
layersVisibility: vector_layers.map((l: any) => ({
|
||||
id: l.id,
|
||||
visible: true,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -309,7 +320,9 @@ function MaplibreMap(props: { file: PMTiles }) {
|
||||
|
||||
const toggleShowAttributes = () => {
|
||||
setShowAttributes(!showAttributes);
|
||||
mapRef.current!.getCanvas().style.cursor = !showAttributes ? "crosshair" : "";
|
||||
mapRef.current!.getCanvas().style.cursor = !showAttributes
|
||||
? "crosshair"
|
||||
: "";
|
||||
};
|
||||
|
||||
const toggleShowTileBoundaries = () => {
|
||||
@@ -317,14 +330,18 @@ function MaplibreMap(props: { file: PMTiles }) {
|
||||
mapRef.current!.showTileBoundaries = !showTileBoundaries;
|
||||
};
|
||||
|
||||
const handleLayersVisibilityChange = (layersVisibility: LayerVisibility[]) => {
|
||||
const handleLayersVisibilityChange = (
|
||||
layersVisibility: LayerVisibility[]
|
||||
) => {
|
||||
setLayersVisibility(layersVisibility);
|
||||
const map = mapRef.current!;
|
||||
for (const { id, visible } of layersVisibility) {
|
||||
mapRef.current!.setLayoutProperty(`${id}_fill`, "visibility", visible ? "visible" : "none");
|
||||
mapRef.current!.setLayoutProperty(`${id}_stroke`, "visibility", visible ? "visible" : "none");
|
||||
mapRef.current!.setLayoutProperty(`${id}_point`, "visibility", visible ? "visible" : "none");
|
||||
}
|
||||
const visibility = visible ? "visible" : "none";
|
||||
map.setLayoutProperty(`${id}_fill`, "visibility", visibility);
|
||||
map.setLayoutProperty(`${id}_stroke`, "visibility", visibility);
|
||||
map.setLayoutProperty(`${id}_point`, "visibility", visibility);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let protocol = new Protocol();
|
||||
@@ -366,7 +383,10 @@ function MaplibreMap(props: { file: PMTiles }) {
|
||||
|
||||
const { x, y } = e.point;
|
||||
const r = 2; // radius around the point
|
||||
var features = map.queryRenderedFeatures([[x-r, y-r], [x+r,y+r]]);
|
||||
var features = map.queryRenderedFeatures([
|
||||
[x - r, y - r],
|
||||
[x + r, y + r],
|
||||
]);
|
||||
|
||||
// ignore the basemap
|
||||
features = features.filter((feature) => feature.source === "source");
|
||||
|
||||
Reference in New Issue
Block a user