mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
decompress vector tile preview correctly
This commit is contained in:
@@ -142,7 +142,7 @@ const StyledFeatureProperties = styled("div", {
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
backgroundColor: "$black",
|
||||
padding: "$1"
|
||||
padding: "$1",
|
||||
});
|
||||
|
||||
const FeatureProperties = (props: { feature: Feature }) => {
|
||||
@@ -168,13 +168,21 @@ const FeatureProperties = (props: { feature: Feature }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const VectorPreview = (props: { file: PMTiles; entry: Entry }) => {
|
||||
const VectorPreview = (props: {
|
||||
file: PMTiles;
|
||||
entry: Entry;
|
||||
tileType: TileType;
|
||||
}) => {
|
||||
let [layers, setLayers] = useState<Layer[]>([]);
|
||||
let [selectedFeature, setSelectedFeature] = useState<Feature | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let fn = async (entry: Entry) => {
|
||||
let view = await props.file.source.getBytes(entry.offset, entry.length);
|
||||
if (props.tileType == TileType.MVT_GZ) {
|
||||
view = new DataView(inflate(new Uint8Array(view.buffer)).buffer);
|
||||
}
|
||||
|
||||
let tile = new VectorTile(
|
||||
new Protobuf(
|
||||
new Uint8Array(view.buffer, view.byteOffset, view.byteLength)
|
||||
@@ -285,8 +293,14 @@ function Inspector(props: { file: PMTiles }) {
|
||||
|
||||
let tilePreview = <div></div>;
|
||||
if (selectedEntry && tileType) {
|
||||
if (tileType === TileType.MVT) {
|
||||
tilePreview = <VectorPreview file={props.file} entry={selectedEntry} />;
|
||||
if (tileType === TileType.MVT || tileType === TileType.MVT_GZ) {
|
||||
tilePreview = (
|
||||
<VectorPreview
|
||||
file={props.file}
|
||||
entry={selectedEntry}
|
||||
tileType={tileType}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
tilePreview = <RasterPreview file={props.file} entry={selectedEntry} />;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ function MaplibreMap(props: { file: PMTiles }) {
|
||||
let initStyle = async () => {
|
||||
if (map) {
|
||||
let metadata = await props.file.metadata();
|
||||
let bounds = metadata.bounds.split(',');
|
||||
let bounds = metadata.bounds.split(",");
|
||||
map.fitBounds([
|
||||
[+bounds[0], +bounds[1]],
|
||||
[+bounds[2], +bounds[3]],
|
||||
|
||||
Reference in New Issue
Block a user