fix: put back mercator

Signed-off-by: Andrew Calcutt <acalcutt@techidiots.net>
This commit is contained in:
Andrew Calcutt 2024-01-29 01:10:56 -05:00
parent 6d741565c1
commit b224678db0

View file

@ -48,7 +48,7 @@ const PATH_PATTERN =
/^((fill|stroke|width)\:[^\|]+\|)*(enc:.+|-?\d+(\.\d*)?,-?\d+(\.\d*)?(\|-?\d+(\.\d*)?,-?\d+(\.\d*)?)+)/; /^((fill|stroke|width)\:[^\|]+\|)*(enc:.+|-?\d+(\.\d*)?,-?\d+(\.\d*)?(\|-?\d+(\.\d*)?,-?\d+(\.\d*)?)+)/;
const httpTester = /^(http(s)?:)?\/\//; const httpTester = /^(http(s)?:)?\/\//;
const mercator_256 = new SphericalMercator(); const mercator = new SphericalMercator();
const mercator_512 = new SphericalMercator({size: 512}); const mercator_512 = new SphericalMercator({size: 512});
const getScale = (scale) => (scale || '@1x').slice(1, 2) | 0; const getScale = (scale) => (scale || '@1x').slice(1, 2) | 0;
@ -349,8 +349,8 @@ const calcZForBBox = (bbox, w, h, query) => {
const padding = query.padding !== undefined ? parseFloat(query.padding) : 0.1; const padding = query.padding !== undefined ? parseFloat(query.padding) : 0.1;
const minCorner = mercator_256.px([bbox[0], bbox[3]], z); const minCorner = mercator.px([bbox[0], bbox[3]], z);
const maxCorner = mercator_256.px([bbox[2], bbox[1]], z); const maxCorner = mercator.px([bbox[2], bbox[1]], z);
const w_ = w / (1 + 2 * padding); const w_ = w / (1 + 2 * padding);
const h_ = h / (1 + 2 * padding); const h_ = h / (1 + 2 * padding);
@ -453,7 +453,7 @@ const respondImage = (
}); });
if (z > 0 && tileMargin > 0) { if (z > 0 && tileMargin > 0) {
const y = mercator_256.px(params.center, z)[1] const y = mercator.px(params.center, z)[1]
const yoffset = Math.max(Math.min(0, y - 128 - tileMargin), y + 128 + tileMargin - Math.pow(2, z + 8)); const yoffset = Math.max(Math.min(0, y - 128 - tileMargin), y + 128 + tileMargin - Math.pow(2, z + 8));
image.extract({ image.extract({
left: tileMargin * scale, left: tileMargin * scale,
@ -570,7 +570,7 @@ export const serve_rendered = {
if (tileSize === 512) { if (tileSize === 512) {
tileCenter = mercator_512.ll([((x + 0.5) / (1 << z)) * (tileSize << z),((y + 0.5) / (1 << z)) * (tileSize << z)],z); tileCenter = mercator_512.ll([((x + 0.5) / (1 << z)) * (tileSize << z),((y + 0.5) / (1 << z)) * (tileSize << z)],z);
} else { } else {
tileCenter = mercator_256.ll([((x + 0.5) / (1 << z)) * (tileSize << z),((y + 0.5) / (1 << z)) * (tileSize << z)],z); tileCenter = mercator.ll([((x + 0.5) / (1 << z)) * (tileSize << z),((y + 0.5) / (1 << z)) * (tileSize << z)],z);
} }
// prettier-ignore // prettier-ignore
@ -616,7 +616,7 @@ export const serve_rendered = {
} }
const transformer = raw const transformer = raw
? mercator_256.inverse.bind(mercator) ? mercator.inverse.bind(mercator)
: item.dataProjWGStoInternalWGS; : item.dataProjWGStoInternalWGS;
if (transformer) { if (transformer) {
@ -663,7 +663,7 @@ export const serve_rendered = {
let center = [(bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2]; let center = [(bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2];
const transformer = raw const transformer = raw
? mercator_256.inverse.bind(mercator) ? mercator.inverse.bind(mercator)
: item.dataProjWGStoInternalWGS; : item.dataProjWGStoInternalWGS;
if (transformer) { if (transformer) {
@ -759,7 +759,7 @@ export const serve_rendered = {
const format = req.params.format; const format = req.params.format;
const transformer = raw const transformer = raw
? mercator_256.inverse.bind(mercator) ? mercator.inverse.bind(mercator)
: item.dataProjWGStoInternalWGS; : item.dataProjWGStoInternalWGS;
const paths = extractPathsFromQuery(req.query, transformer); const paths = extractPathsFromQuery(req.query, transformer);
@ -791,8 +791,8 @@ export const serve_rendered = {
bbox[3] = Math.max(bbox[3], pair[1]); bbox[3] = Math.max(bbox[3], pair[1]);
} }
const bbox_ = mercator_256.convert(bbox, '900913'); const bbox_ = mercator.convert(bbox, '900913');
const center = mercator_256.inverse([ const center = mercator.inverse([
(bbox_[0] + bbox_[2]) / 2, (bbox_[0] + bbox_[2]) / 2,
(bbox_[1] + bbox_[3]) / 2, (bbox_[1] + bbox_[3]) / 2,
]); ]);