Skip to content

Commit

Permalink
Merge branch 'master' into feat/force-fqdn-s3
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha authored Apr 17, 2024
2 parents bcd26cc + b8d56cd commit f6a0f67
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 25 deletions.
3 changes: 0 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ RUN npm install [email protected]
# Install the landing assets
COPY ./basemaps-landing*.tgz /app/
COPY ./basemaps-cogify*.tgz /app/
COPY ./basemaps-smoke*.tgz /app/

RUN npm install ./basemaps-landing*.tgz ./basemaps-cogify*.tgz
RUN npm install ./basemaps-landing*.tgz ./basemaps-cogify*.tgz ./basemaps-smoke*.tgz

COPY dist/index.cjs /app/

Expand Down
9 changes: 6 additions & 3 deletions packages/cli/src/cli/config/config.diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ export function getVectorChanges(newLayer: StacLink | undefined, existingLayer:
if (newLayer != null && existingLayer != null) {
const featureChange = Number(newLayer['lds:feature_count']) - Number(existingLayer['lds:feature_count']);

if (newLayer['lds:version'] === existingLayer['lds:version'] && featureChange !== 0) {
if (newLayer['lds:version'] === existingLayer['lds:version']) {
// Alert if feature changed with no version bump.
return `🟥🟥🟥🟥 Feature Change Detected ${newLayer['lds:name']} - version: ${newLayer['lds:version']} features: ${newLayer['lds:feature_count']} (+${featureChange}) 🟥🟥🟥🟥`;
if (featureChange !== 0) {
return `🟥🟥🟥🟥 Feature Change Detected ${newLayer['lds:name']} - version: ${newLayer['lds:version']} features: ${newLayer['lds:feature_count']} (+${featureChange}) 🟥🟥🟥🟥`;
}
return null;
}

if (featureChange >= 0) {
Expand Down Expand Up @@ -141,7 +144,7 @@ export async function diffVectorUpdate(
// Find layer updates
for (const l of ldsLayers) {
const existingLayer = existingLdsLayers.get(l['lds:id']);
const change = getVectorChanges(l, undefined);
const change = getVectorChanges(l, existingLayer);
if (change != null) changes.push(change);
if (existingLayer != null) existingLdsLayers.delete(l['lds:id']);
}
Expand Down
85 changes: 83 additions & 2 deletions packages/lambda-tiler/src/__tests__/wmts.capability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,86 @@ describe('WmtsCapabilities', () => {
);
});

it('should limit a bounding box to the tileMatrix extent WebMercatorQuad', () => {
const wmts = new WmtsCapabilities({ httpBase: 'https://basemaps.test', apiKey });

const bigImagery = new Map();
bigImagery.set(Imagery3857.id, {
...Imagery3857,
bounds: {
// These bounds are slightly outside the extent bounds of 3857 (approx 0.3m offset)
// expected bounds: {x: -20037508.34 y:-20037508.34, width: 40075016.6855784 , height: 40075016.6855784 }
x: -20037508.6276,
y: -20037508.6276,
width: 40075016.9626,
height: 40075014.197799996,
},
});

wmts.fromParams({
provider: Provider,
tileMatrix: [GoogleTms],
tileSet: TileSetAerial,
imagery: bigImagery,
formats: ['png'],
});
const raw = wmts.toVNode();

const wgs84 = raw.find('Contents', 'Layer', 'ows:WGS84BoundingBox');
const epsg3857 = raw.find('Contents', 'Layer', 'ows:BoundingBox');

assert.equal(
epsg3857?.find('ows:LowerCorner')?.toString(),
`<ows:LowerCorner>-20037508.3428 -20037508.3428</ows:LowerCorner>`,
);
assert.equal(
epsg3857?.find('ows:UpperCorner')?.toString(),
`<ows:UpperCorner>20037508.3428 20037508.3428</ows:UpperCorner>`,
);

assert.equal(wgs84?.find('ows:LowerCorner')?.toString(), '<ows:LowerCorner>-180 -85.051129</ows:LowerCorner>');
assert.equal(wgs84?.find('ows:UpperCorner')?.toString(), '<ows:UpperCorner>180 85.051129</ows:UpperCorner>');
});

it('should limit a bounding box to the tileMatrix extent NZTM2000Quad', () => {
const wmts = new WmtsCapabilities({ httpBase: 'https://basemaps.test', apiKey });
const bigImagery = new Map();

bigImagery.set(Imagery2193.id, {
...Imagery2193,
bounds: {
// These bounds are slightly outside the extent bounds of NZTM2000Quad (approx 0.3m offset)
x: -3260586.9214,
y: 419435.7552,
width: 10018754.086099999,
height: 10018754.086099999,
},
});

wmts.fromParams({
provider: Provider,
tileMatrix: [Nztm2000QuadTms],
tileSet: TileSetAerial,
imagery: bigImagery,
formats: ['png'],
});
const raw = wmts.toVNode();

const wgs84 = raw.find('Contents', 'Layer', 'ows:WGS84BoundingBox');
const crsBounds = raw.find('Contents', 'Layer', 'ows:BoundingBox');
assert.equal(
crsBounds?.find('ows:LowerCorner')?.toString(),
`<ows:LowerCorner>419435.9938 -3260586.7284</ows:LowerCorner>`,
);
assert.equal(
crsBounds?.find('ows:UpperCorner')?.toString(),
`<ows:UpperCorner>10438190.1652 6758167.443</ows:UpperCorner>`,
);

assert.equal(wgs84?.find('ows:LowerCorner')?.toString(), '<ows:LowerCorner>-180 -49.929855</ows:LowerCorner>');
assert.equal(wgs84?.find('ows:UpperCorner')?.toString(), '<ows:UpperCorner>180 2.938603</ows:UpperCorner>');
});

it('should include output the correct TileMatrix', () => {
const wmts = new WmtsCapabilities({
httpBase: 'https://basemaps.test',
Expand Down Expand Up @@ -512,11 +592,12 @@ describe('WmtsCapabilities', () => {
.split('\n')
.map((c) => c.trim()),
);

assert.deepEqual(boundingBox[0][1], '<ows:LowerCorner>-180 -85.0511</ows:LowerCorner>');
assert.equal(boundingBox[0][2], '<ows:UpperCorner>180 0</ows:UpperCorner>');
assert.equal(boundingBox[0][2], '<ows:UpperCorner>180 85.0511</ows:UpperCorner>');

assert.deepEqual(boundingBox[1][1], '<ows:LowerCorner>-180 -85.0511</ows:LowerCorner>');
assert.equal(boundingBox[1][2], '<ows:UpperCorner>180 0</ows:UpperCorner>');
assert.equal(boundingBox[1][2], '<ows:UpperCorner>180 85.0511</ows:UpperCorner>');
});

it('should work with NZTM2000Quad', () => {
Expand Down
23 changes: 17 additions & 6 deletions packages/lambda-tiler/src/wmts.capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,25 @@ export class WmtsBuilder {
}

buildWgs84BoundingBox(tms: TileMatrixSet, layers: Bounds[]): VNodeElement {
let bbox: BBox;
let bbox: BBox | null = null;

if (layers.length > 0) {
let bounds = layers[0];
for (let i = 1; i < layers.length; i++) {
bounds = bounds.union(layers[i]);
}
bbox = wgs84Extent(tms, bounds.toJson());
} else {
// No layers provided assume extent is the size of the tile matrix set :shrug: ?
bbox = wgs84Extent(tms, tms.extent);

// If imagery is outside of the bounds of the tileMatrix, fall back to the tileMatrix extent for the bounds
if (!tms.extent.containsBounds(bounds)) {
bbox = wgs84Extent(tms, tms.extent);
} else {
bbox = wgs84Extent(tms, bounds);
}
}

// No layers provided assume extent is the size of the tile matrix set :shrug: ?
if (bbox == null) bbox = wgs84Extent(tms, tms.extent);

// If east is less than west, then this has crossed the anti meridian, so cover the entire globe
if (bbox[2] < bbox[0]) {
bbox[0] = -180;
Expand All @@ -120,7 +127,7 @@ export class WmtsBuilder {

/** Combine all the bounds of the imagery inside the layers into a extent for the imagery set */
buildBoundingBoxFromImagery(tms: TileMatrixSet, layers: ConfigLayer[]): VNodeElement | null {
let bounds;
let bounds: Bounds | null = null;
for (const layer of layers) {
const imgId = layer[tms.projection.code];
if (imgId == null) continue;
Expand All @@ -131,7 +138,11 @@ export class WmtsBuilder {
}
if (bounds == null) return null;

// If imagery is outside of the bounds of the tileMatrix, fall back to the tileMatrix extent for the bounds
if (!tms.extent.containsBounds(bounds)) bounds = tms.extent;

const bbox = bounds.toBbox();

return V('ows:BoundingBox', { crs: tms.projection.toUrn() }, [
V('ows:LowerCorner', formatBbox(bbox[tms.indexX], bbox[tms.indexY], MeterPrecision)),
V('ows:UpperCorner', formatBbox(bbox[tms.indexX + 2], bbox[tms.indexY + 2], MeterPrecision)),
Expand Down
4 changes: 1 addition & 3 deletions packages/smoke/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,5 @@
"build/",
"bin/"
],
"dependencies": {
"@basemaps/shared": "^7.1.0"
}
"dependencies": {}
}
22 changes: 17 additions & 5 deletions packages/smoke/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import assert from 'node:assert';

import { LogConfig } from '@basemaps/shared';
import ulid from 'ulid';

const logger = LogConfig.get();
/** Fresh API Key to use */
const apiKey = 'c' + ulid.ulid().toLowerCase().slice(0, 22) + 'test';

Expand All @@ -27,14 +25,28 @@ if (!host.protocol.startsWith('http')) throw new Error(`Invalid host: ${host}`);
*/
async function req(path: string, opts?: RequestInit): Promise<Response> {
const target = new URL(path, host);
logger.trace({ path, url: target.href }, 'Fetch');

const startTime = performance.now();
const res = await fetch(target, opts);
logger.info({ url: target.href, status: res.status, ...opts, duration: performance.now() - startTime }, 'Fetch:Done');

// eslint-disable-next-line no-console
console.log(
// Create a fake log line approximating the pino log format
JSON.stringify({
pid: 0,
time: new Date().toISOString(),
level: 30,
msg: 'Fetch:Done',
url: target.href,
status: res.status,
...opts,
duration: performance.now() - startTime,
}),
);
return res;
}

export const ctx = { logger, host, Cors, apiKey, req };
export const ctx = { host, Cors, apiKey, req };

/** Validate that the response was not a cached response */
export function assertCacheMiss(res: Response): void {
Expand Down
14 changes: 12 additions & 2 deletions packages/smoke/src/wmts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,23 @@ test(`GET /v1/tiles/aerial/WebMercatorQuad/WMTSCapabilities.xml`, async () => {

assert.ok(
xml.includes(
`<ows:BoundingBox crs="urn:ogc:def:crs:EPSG::3857"><ows:LowerCorner>-20037508.3428 -20037508.3428</ows:LowerCorner><ows:UpperCorner>20037508.3428 20037508.3428</ows:UpperCorner></ows:BoundingBox>`,
[
`<ows:BoundingBox crs="urn:ogc:def:crs:EPSG::3857">`,
`<ows:LowerCorner>-20037508.3428 -20037508.3428</ows:LowerCorner>`,
`<ows:UpperCorner>20037508.3428 20037508.3428</ows:UpperCorner>`,
`</ows:BoundingBox>`,
].join(''),
),
);

assert.ok(
xml.includes(
`<ows:WGS84BoundingBox crs="urn:ogc:def:crs:OGC:2:84"><ows:LowerCorner>-180 -85.051129</ows:LowerCorner><ows:UpperCorner>180 85.051129</ows:UpperCorner></ows:WGS84BoundingBox>`,
[
`<ows:WGS84BoundingBox crs="urn:ogc:def:crs:OGC:2:84">`,
`<ows:LowerCorner>-180 -85.051129</ows:LowerCorner>`,
`<ows:UpperCorner>180 85.051129</ows:UpperCorner>`,
`</ows:WGS84BoundingBox>`,
].join(''),
),
);

Expand Down

0 comments on commit f6a0f67

Please sign in to comment.