Skip to content

Commit

Permalink
fix: add bounds and center when they don't exist
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Calcutt <[email protected]>
  • Loading branch information
acalcutt committed Oct 12, 2023
1 parent a5cc667 commit 81e4011
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/pmtiles_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,26 @@ export const GetPMtilesInfo = async (pmtiles) => {
const metadata = await pmtiles.getMetadata();

//Add missing metadata from header
const bounds = [header.minLon, header.minLat, header.maxLon, header.maxLat];
const center = [header.centerLon, header.centerLat, header.centerZoom];

metadata['bounds'] = bounds;
metadata['center'] = center;
metadata['format'] = GetPmtilesTileType(header.tileType).type;
metadata['minzoom'] = header.minZoom;
metadata['maxzoom'] = header.maxZoom;
metadata['format'] = GetPmtilesTileType(header.tileType).type;
console.log('maxzoom:' + header.maxZoom)

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (90% of all statements in
the enclosing function
have an explicit semicolon).

if(header.minLon && header.minLat && header.maxLon && header.maxLat) {
metadata['bounds'] = [header.minLon, header.minLat, header.maxLon, header.maxLat];
} else {
metadata['bounds'] = [-180, -85.05112877980659, 180, 85.0511287798066];
}

if(header.centerLon && header.centerLat && header.centerZoom) {
metadata['center'] = [header.centerLon, header.centerLat, header.centerZoom];
} else {
metadata['center'] = [
(parseInt(metadata['bounds'][0]) + parseInt(metadata['bounds'][2])) / 2,
(parseInt(metadata['bounds'][1]) + parseInt(metadata['bounds'][3])) / 2,
parseInt(metadata['maxzoom']) / 2,
];
}

return metadata;
};
Expand Down

0 comments on commit 81e4011

Please sign in to comment.