mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
inspector: improve type checks, map color scheme [#49]
This commit is contained in:
10
app/package-lock.json
generated
10
app/package-lock.json
generated
@@ -37,6 +37,7 @@
|
|||||||
"@types/pbf": "^3.0.2",
|
"@types/pbf": "^3.0.2",
|
||||||
"@types/react": "^18.0.0",
|
"@types/react": "^18.0.0",
|
||||||
"@types/react-dom": "^18.0.0",
|
"@types/react-dom": "^18.0.0",
|
||||||
|
"@types/react-svg-pan-zoom": "^3.3.5",
|
||||||
"@vitejs/plugin-react": "^1.3.0",
|
"@vitejs/plugin-react": "^1.3.0",
|
||||||
"typescript": "^4.6.3",
|
"typescript": "^4.6.3",
|
||||||
"vite": "^2.9.13"
|
"vite": "^2.9.13"
|
||||||
@@ -1433,6 +1434,15 @@
|
|||||||
"@types/react": "*"
|
"@types/react": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/react-svg-pan-zoom": {
|
||||||
|
"version": "3.3.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/react-svg-pan-zoom/-/react-svg-pan-zoom-3.3.5.tgz",
|
||||||
|
"integrity": "sha512-W8GRFCDy7raSDr5OXGjSyvX5KmdWlIQfv0NLa1jfAYVUO4ClVbgorWeAAom7nY3Pl+4h9blXE1Bnu2CW1iMEvQ==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/react": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/react-transition-group": {
|
"node_modules/@types/react-transition-group": {
|
||||||
"version": "4.4.5",
|
"version": "4.4.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.5.tgz",
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
"@types/pbf": "^3.0.2",
|
"@types/pbf": "^3.0.2",
|
||||||
"@types/react": "^18.0.0",
|
"@types/react": "^18.0.0",
|
||||||
"@types/react-dom": "^18.0.0",
|
"@types/react-dom": "^18.0.0",
|
||||||
|
"@types/react-svg-pan-zoom": "^3.3.5",
|
||||||
"@vitejs/plugin-react": "^1.3.0",
|
"@vitejs/plugin-react": "^1.3.0",
|
||||||
"typescript": "^4.6.3",
|
"typescript": "^4.6.3",
|
||||||
"vite": "^2.9.13"
|
"vite": "^2.9.13"
|
||||||
|
|||||||
@@ -9,12 +9,7 @@ import { schemeSet3 } from "d3-scale-chromatic";
|
|||||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||||
import { useMeasure } from "react-use";
|
import { useMeasure } from "react-use";
|
||||||
import {
|
import {
|
||||||
INITIAL_VALUE,
|
UncontrolledReactSVGPanZoom,
|
||||||
ReactSVGPanZoom,
|
|
||||||
TOOL_NONE,
|
|
||||||
fitSelection,
|
|
||||||
zoomOnViewerCenter,
|
|
||||||
fitToViewer,
|
|
||||||
} from "react-svg-pan-zoom";
|
} from "react-svg-pan-zoom";
|
||||||
|
|
||||||
const TableContainer = styled("div", {
|
const TableContainer = styled("div", {
|
||||||
@@ -40,6 +35,7 @@ const TableRow = styled(
|
|||||||
"tr",
|
"tr",
|
||||||
{
|
{
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
|
fontFamily: "monospace"
|
||||||
},
|
},
|
||||||
{ "&:hover": { color: "red" } }
|
{ "&:hover": { color: "red" } }
|
||||||
);
|
);
|
||||||
@@ -185,10 +181,12 @@ const VectorPreview = (props: {
|
|||||||
}) => {
|
}) => {
|
||||||
let [layers, setLayers] = useState<Layer[]>([]);
|
let [layers, setLayers] = useState<Layer[]>([]);
|
||||||
let [selectedFeature, setSelectedFeature] = useState<Feature | null>(null);
|
let [selectedFeature, setSelectedFeature] = useState<Feature | null>(null);
|
||||||
const Viewer = useRef(null);
|
const Viewer = useRef<UncontrolledReactSVGPanZoom>(null);
|
||||||
const [tool, setTool] = useState(TOOL_NONE);
|
const [ref, { width, height }] = useMeasure<HTMLDivElement>();
|
||||||
const [value, setValue] = useState(INITIAL_VALUE);
|
|
||||||
const [ref, { width, height }] = useMeasure();
|
useEffect(() => {
|
||||||
|
Viewer.current!.zoomOnViewerCenter(0.1);
|
||||||
|
},[]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let fn = async (entry: Entry) => {
|
let fn = async (entry: Entry) => {
|
||||||
@@ -251,21 +249,17 @@ const VectorPreview = (props: {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<SVGContainer ref={ref}>
|
<SVGContainer ref={ref}>
|
||||||
<ReactSVGPanZoom
|
<UncontrolledReactSVGPanZoom
|
||||||
ref={Viewer}
|
ref={Viewer}
|
||||||
width={width}
|
width={width}
|
||||||
height={height}
|
height={height}
|
||||||
tool={tool}
|
|
||||||
onChangeTool={setTool}
|
|
||||||
value={value}
|
|
||||||
onChangeValue={setValue}
|
|
||||||
detectAutoPan={false}
|
detectAutoPan={false}
|
||||||
onClick={(event) =>
|
onClick={(event) =>
|
||||||
console.log("click", event.x, event.y, event.originalEvent)
|
console.log("click", event.x, event.y, event.originalEvent)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<svg viewBox="0 0 4096 4096">{elems}</svg>
|
<svg viewBox="0 0 4096 4096">{elems}</svg>
|
||||||
</ReactSVGPanZoom>
|
</UncontrolledReactSVGPanZoom>
|
||||||
{selectedFeature ? <FeatureProperties feature={selectedFeature} /> : null}
|
{selectedFeature ? <FeatureProperties feature={selectedFeature} /> : null}
|
||||||
</SVGContainer>
|
</SVGContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { Protocol } from "../../js/adapters";
|
|||||||
import { styled } from "./stitches.config";
|
import { styled } from "./stitches.config";
|
||||||
import maplibregl from "maplibre-gl";
|
import maplibregl from "maplibre-gl";
|
||||||
import "maplibre-gl/dist/maplibre-gl.css";
|
import "maplibre-gl/dist/maplibre-gl.css";
|
||||||
|
import { schemeSet3 } from "d3-scale-chromatic";
|
||||||
|
|
||||||
const MapContainer = styled("div", {
|
const MapContainer = styled("div", {
|
||||||
height: "calc(100vh - $4 - $4)",
|
height: "calc(100vh - $4 - $4)",
|
||||||
@@ -46,14 +47,14 @@ const vectorStyle = async (file: PMTiles): Promise<any> => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (vector_layers) {
|
if (vector_layers) {
|
||||||
for (let layer of vector_layers) {
|
for (let [i,layer] of vector_layers.entries()) {
|
||||||
layers.push({
|
layers.push({
|
||||||
id: layer.id + "_fill",
|
id: layer.id + "_fill",
|
||||||
type: "fill",
|
type: "fill",
|
||||||
source: "source",
|
source: "source",
|
||||||
"source-layer": layer.id,
|
"source-layer": layer.id,
|
||||||
paint: {
|
paint: {
|
||||||
"fill-color": "white",
|
"fill-color": schemeSet3[i % 12],
|
||||||
"fill-opacity": 0.2,
|
"fill-opacity": 0.2,
|
||||||
},
|
},
|
||||||
filter: ["==", ["geometry-type"], "Polygon"],
|
filter: ["==", ["geometry-type"], "Polygon"],
|
||||||
@@ -64,7 +65,7 @@ const vectorStyle = async (file: PMTiles): Promise<any> => {
|
|||||||
source: "source",
|
source: "source",
|
||||||
"source-layer": layer.id,
|
"source-layer": layer.id,
|
||||||
paint: {
|
paint: {
|
||||||
"line-color": "steelblue",
|
"line-color": schemeSet3[i % 12],
|
||||||
"line-width": 0.5,
|
"line-width": 0.5,
|
||||||
},
|
},
|
||||||
filter: ["==", ["geometry-type"], "LineString"],
|
filter: ["==", ["geometry-type"], "LineString"],
|
||||||
@@ -75,13 +76,13 @@ const vectorStyle = async (file: PMTiles): Promise<any> => {
|
|||||||
source: "source",
|
source: "source",
|
||||||
"source-layer": layer.id,
|
"source-layer": layer.id,
|
||||||
paint: {
|
paint: {
|
||||||
"circle-color": "red",
|
"circle-color": schemeSet3[i % 12],
|
||||||
},
|
},
|
||||||
filter: ["==", ["geometry-type"], "Point"],
|
filter: ["==", ["geometry-type"], "Point"],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (tilestats) {
|
} else if (tilestats) {
|
||||||
for (let layer of tilestats.layers) {
|
for (let [i,layer] of tilestats.layers.entries()) {
|
||||||
if (layer.geometry === "Polygon") {
|
if (layer.geometry === "Polygon") {
|
||||||
layers.push({
|
layers.push({
|
||||||
id: layer.layer + "_fill",
|
id: layer.layer + "_fill",
|
||||||
@@ -89,7 +90,7 @@ const vectorStyle = async (file: PMTiles): Promise<any> => {
|
|||||||
source: "source",
|
source: "source",
|
||||||
"source-layer": layer.layer,
|
"source-layer": layer.layer,
|
||||||
paint: {
|
paint: {
|
||||||
"fill-color": "white",
|
"fill-color": schemeSet3[i % 12],
|
||||||
"fill-opacity": 0.2,
|
"fill-opacity": 0.2,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -100,7 +101,7 @@ const vectorStyle = async (file: PMTiles): Promise<any> => {
|
|||||||
source: "source",
|
source: "source",
|
||||||
"source-layer": layer.layer,
|
"source-layer": layer.layer,
|
||||||
paint: {
|
paint: {
|
||||||
"line-color": "steelblue",
|
"line-color": schemeSet3[i % 12],
|
||||||
"line-width": 0.5,
|
"line-width": 0.5,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -111,7 +112,7 @@ const vectorStyle = async (file: PMTiles): Promise<any> => {
|
|||||||
source: "source",
|
source: "source",
|
||||||
"source-layer": layer.layer,
|
"source-layer": layer.layer,
|
||||||
paint: {
|
paint: {
|
||||||
"circle-color": "red",
|
"circle-color": schemeSet3[i % 12],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,8 +55,6 @@ export const globalStyles = globalCss({
|
|||||||
margin: 0,
|
margin: 0,
|
||||||
padding: 0,
|
padding: 0,
|
||||||
border: 0,
|
border: 0,
|
||||||
fontFamily: "Inter, sans-serif",
|
|
||||||
},
|
},
|
||||||
body: { backgroundColor: "$black", color: "$white" },
|
body: { backgroundColor: "$black", color: "$white", fontFamily: "sans-serif" }
|
||||||
"@import": ["url('https://rsms.me/inter/inter.css')"],
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user