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