mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-12-06 10:34:13 +00:00
more national/regional imagery
This commit is contained in:
1 parent
22a269a6dc
commit
2365195bcb
23 files changed
+335
-27
No files matched your search
@@ -119,13 +119,124 @@ describe('planTile', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('leaves the islands of Portugal to the fallback', async () => {
|
||||
const { asked, tiles } = savedTiles();
|
||||
// Funchal, on Madeira
|
||||
assert.deepEqual(await plan(tile(-16.91, 32.65, 15), tiles), { parts: [], fallback: true });
|
||||
it('takes Slovenia, Slovakia and Estonia from their agencies', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
// Ljubljana
|
||||
assert.deepEqual(await plan(tile(14.506, 46.051, 16), tiles), {
|
||||
parts: ['SI:full'],
|
||||
fallback: false,
|
||||
});
|
||||
// Bad Radkersburg and Gornja Radgona, on the border of Austria and Slovenia
|
||||
assert.deepEqual(await plan(tile(15.99, 46.685, 13), tiles), {
|
||||
parts: ['AT:partial', 'SI:partial'],
|
||||
fallback: false,
|
||||
});
|
||||
// Bratislava, on the border of Austria
|
||||
assert.deepEqual(await plan(tile(17.05, 48.14, 13), tiles), {
|
||||
parts: ['AT:partial', 'SK:partial'],
|
||||
fallback: false,
|
||||
});
|
||||
// Valga, with Latvia, which is not in the patchwork, to the south
|
||||
assert.deepEqual(await plan(tile(26.03, 57.777, 13), tiles), {
|
||||
parts: ['EE:partial'],
|
||||
fallback: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('takes Liechtenstein from the agency of Switzerland, with it as one', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
// Vaduz
|
||||
assert.deepEqual(await plan(tile(9.5215, 47.141, 16), tiles), {
|
||||
parts: ['LI:full'],
|
||||
fallback: false,
|
||||
});
|
||||
// the Rhine, on the border of Switzerland
|
||||
const { parts, fallback } = await planTile(...tile(9.51, 47.141, 14), tiles);
|
||||
assert.deepEqual(
|
||||
parts.map((part) => part.relation),
|
||||
['full']
|
||||
);
|
||||
assert.equal(fallback, false);
|
||||
// near Schaanwald, on the border of Austria
|
||||
const border = await plan([14, 8628, 5748], tiles);
|
||||
assert.deepEqual(border, { parts: ['AT:partial', 'LI:partial'], fallback: false });
|
||||
});
|
||||
|
||||
it('takes Monaco from the agency of France, with it as one', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
// the Casino
|
||||
assert.deepEqual(await plan(tile(7.4281, 43.7392, 18), tiles), {
|
||||
parts: ['MC:full'],
|
||||
fallback: false,
|
||||
});
|
||||
// La Condamine, on the border of France
|
||||
const { parts, fallback } = await planTile(...tile(7.4165, 43.7365, 17), tiles);
|
||||
assert.deepEqual(
|
||||
parts.map((part) => part.relation),
|
||||
['full']
|
||||
);
|
||||
assert.equal(fallback, false);
|
||||
});
|
||||
|
||||
it('takes Madeira from its own agency, and leaves the Azores to the fallback', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
// Funchal
|
||||
assert.deepEqual(await plan(tile(-16.91, 32.65, 16), tiles), {
|
||||
parts: ['PT-30:full'],
|
||||
fallback: false,
|
||||
});
|
||||
const { asked, tiles: none } = savedTiles();
|
||||
// Ponta Delgada
|
||||
assert.deepEqual(await plan(tile(-25.67, 37.74, 15), none), { parts: [], fallback: true });
|
||||
assert.deepEqual(asked, []);
|
||||
});
|
||||
|
||||
it('takes the regions of Italy with imagery of the same year as one', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
const years = async (...at: [number, number, number]) => {
|
||||
const [z, x, y] = tile(...at);
|
||||
const { parts, fallback } = await planTile(z, x, y, tiles);
|
||||
return {
|
||||
parts: parts
|
||||
.map((p) => `${p.source.url(z, x, y).match(/AgEA_(\d+)/)?.[1]}:${p.relation}`)
|
||||
.sort(),
|
||||
fallback,
|
||||
};
|
||||
};
|
||||
// Orte, in Lazio, and the Umbrian side of the Tiber
|
||||
assert.deepEqual(await years(12.386, 42.46, 13), { parts: ['2023:full'], fallback: false });
|
||||
// the Vatican and Rome
|
||||
assert.deepEqual(await years(12.4534, 41.9022, 14), {
|
||||
parts: ['2023:full'],
|
||||
fallback: false,
|
||||
});
|
||||
// Piacenza, in Emilia-Romagna, and Lombardy, north of the Po
|
||||
assert.deepEqual(await years(9.69, 45.06, 13), {
|
||||
parts: ['2023:partial', '2024:partial'],
|
||||
fallback: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('takes Basilicata from its agency above the last zoom level of its imagery', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
// Potenza
|
||||
assert.deepEqual(await plan(tile(15.805, 40.64, 18), tiles), {
|
||||
parts: ['IT-77:full'],
|
||||
fallback: false,
|
||||
});
|
||||
// on the border of Campania, whose imagery is closer: as one only up to there
|
||||
const border = [15.53345, 40.57318] as const;
|
||||
const { parts } = await planTile(...tile(...border, 16), tiles);
|
||||
assert.deepEqual(
|
||||
parts.map((part) => part.relation),
|
||||
['full']
|
||||
);
|
||||
assert.deepEqual(await plan(tile(...border, 17), tiles), {
|
||||
parts: ['IT-72:partial', 'IT-77:partial'],
|
||||
fallback: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('takes New Zealand from its agency, on both sides of the 180th meridian', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
// New Plymouth, inland and on the coast, with the fallback at sea
|
||||
@@ -144,6 +255,39 @@ describe('planTile', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('takes Japan from its agency', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
// Matsumoto
|
||||
assert.deepEqual(await plan(tile(137.97, 36.235, 13), tiles), {
|
||||
parts: ['JP:full'],
|
||||
fallback: false,
|
||||
});
|
||||
// the Shiretoko peninsula, with the fallback at sea
|
||||
assert.deepEqual(await plan(tile(145.19, 44.02, 14), tiles), {
|
||||
parts: ['JP:partial'],
|
||||
fallback: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('takes Taiwan from its agency, without the islands that have no imagery', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
// Yushan
|
||||
assert.deepEqual(await plan(tile(120.957, 23.47, 14), tiles), {
|
||||
parts: ['TW:full'],
|
||||
fallback: false,
|
||||
});
|
||||
// Kinmen, with the fallback at sea
|
||||
assert.deepEqual(await plan(tile(118.29, 24.43, 13), tiles), {
|
||||
parts: ['TW:partial'],
|
||||
fallback: true,
|
||||
});
|
||||
// Matsu
|
||||
assert.deepEqual(await plan(tile(119.93, 26.155, 14), tiles), {
|
||||
parts: [],
|
||||
fallback: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('takes the states of the United States with the same imagery as one', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
// Kansas City, in Kansas and Missouri, both from the NAIP
|
||||
@@ -162,15 +306,35 @@ describe('planTile', () => {
|
||||
parts: ['US-DC:full'],
|
||||
fallback: false,
|
||||
});
|
||||
// Portland, and the Columbia, with Washington, which is not in the patchwork, to the north
|
||||
// Portland, and the Columbia, with Washington to the north
|
||||
assert.deepEqual(await plan(tile(-122.68, 45.59, 16), tiles), {
|
||||
parts: ['US-OR:full'],
|
||||
fallback: false,
|
||||
});
|
||||
assert.deepEqual(await plan([13, 1305, 2927], tiles), {
|
||||
parts: ['US-OR:partial'],
|
||||
parts: ['US-OR:partial', 'US-WA:partial'],
|
||||
fallback: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('takes the states missing from the server of the USDA from that of GeoPlatform', async () => {
|
||||
const { tiles } = savedTiles();
|
||||
// Honolulu, with the fallback at sea
|
||||
const honolulu = tile(-157.858, 21.307, 16);
|
||||
assert.deepEqual(await plan(honolulu, tiles), { parts: ['US-HI:full'], fallback: false });
|
||||
const [part] = (await planTile(...honolulu, tiles)).parts;
|
||||
assert.match(part.source.url(...honolulu), /^https:\/\/imagery\.geoplatform\.gov\//);
|
||||
assert.deepEqual(await plan(tile(-157.87, 21.29, 13), tiles), {
|
||||
parts: ['US-HI:partial'],
|
||||
fallback: true,
|
||||
});
|
||||
// Four Corners, with Arizona and Colorado from there, and New Mexico and Utah from the USDA
|
||||
const { parts, fallback } = await planTile(...tile(-109.0452, 36.999, 14), tiles);
|
||||
assert.deepEqual(
|
||||
parts.map((p) => p.relation),
|
||||
['partial', 'partial']
|
||||
);
|
||||
assert.equal(fallback, false);
|
||||
});
|
||||
|
||||
it('asks for a tile of the countries once for all the tiles of imagery inside it', async () => {
|
||||
|
||||
@@ -17,13 +17,15 @@ const OPEN_SATELLITE_PROTOCOL = 'opensat';
|
||||
type TileUrl = (z: number, x: number, y: number) => string;
|
||||
|
||||
type ImagerySource = {
|
||||
/** ISO code of the country, or of its state, in the tileset of the countries */
|
||||
/** ISO code of the country, or of its part, in the tileset of the countries */
|
||||
id: string;
|
||||
/** Its credit, shown while its imagery is in view. */
|
||||
attribution: string;
|
||||
url: TileUrl;
|
||||
/** Above it, the tile of this zoom level is scaled up. */
|
||||
maxzoom: number;
|
||||
/** Below it, the tiles of this zoom level are put together. */
|
||||
minzoom?: number;
|
||||
/**
|
||||
* Its server only answers pages on https: elsewhere, such as in the desktop app, the country
|
||||
* is left to the fallback.
|
||||
@@ -93,22 +95,63 @@ const naipStates = [
|
||||
'UT', 'VT', 'WI', 'WV', 'WY',
|
||||
];
|
||||
|
||||
/**
|
||||
* For the states missing from it, the NAIP from the Forest Service and GeoPlatform, which is
|
||||
* slower.
|
||||
*/
|
||||
const naipPlus = arcgis(
|
||||
'https://imagery.geoplatform.gov/iipp/rest/services/NAIP/NAIP_plus/ImageServer'
|
||||
);
|
||||
const naipPlusStates = ['AZ', 'CO', 'DE', 'HI', 'WA'];
|
||||
|
||||
/**
|
||||
* The regions of Italy, San Marino and the Vatican, by the year of their imagery from AGEA: each
|
||||
* is covered by a single one.
|
||||
*/
|
||||
// prettier-ignore
|
||||
const ageaRegions = {
|
||||
// Liguria, Tuscany, Marche, Abruzzo, Puglia, Sicily and Sardinia
|
||||
2022: ['IT-42', 'IT-52', 'IT-57', 'IT-65', 'IT-75', 'IT-82', 'IT-88'],
|
||||
// Trentino-South Tyrol, Friuli-Venezia Giulia, Emilia-Romagna, Umbria, Lazio, Campania and
|
||||
// Basilicata
|
||||
2023: ['IT-32', 'IT-36', 'IT-45', 'IT-55', 'IT-62', 'IT-72', 'IT-77', 'SM', 'VA'],
|
||||
// Piedmont, Aosta Valley, Lombardy, Veneto, Molise and Calabria
|
||||
2024: ['IT-21', 'IT-23', 'IT-25', 'IT-34', 'IT-67', 'IT-78'],
|
||||
};
|
||||
|
||||
const agea = Object.entries(ageaRegions).flatMap(([year, regions]): ImagerySource[] => {
|
||||
const url = xyz(
|
||||
`https://geoportale.agea.gov.it/image/rest/services/AgEA/Ortofoto_AgEA_${year}/ImageServer/tile/{z}/{y}/{x}`
|
||||
);
|
||||
return regions.map((id) => ({
|
||||
id,
|
||||
attribution:
|
||||
'© <a href="https://geoportale.agea.gov.it/legal-notes" target="_blank">AGEA CC BY 4.0</a>',
|
||||
url,
|
||||
// the images of Basilicata stop at zoom 16
|
||||
maxzoom: id === 'IT-77' ? 16 : 18,
|
||||
}));
|
||||
});
|
||||
|
||||
const swissimage = xyz(
|
||||
'https://wmts.geo.admin.ch/1.0.0/ch.swisstopo.swissimage/default/current/3857/{z}/{x}/{y}.jpeg'
|
||||
);
|
||||
|
||||
/** In order of priority, the first one covering a point is used. */
|
||||
const sources: ImagerySource[] = [
|
||||
{
|
||||
id: 'CH',
|
||||
// Liechtenstein is in the imagery of Switzerland
|
||||
...['CH', 'LI'].map((id) => ({
|
||||
id,
|
||||
attribution: '<a href="https://www.swisstopo.admin.ch/" target="_blank">swisstopo</a>',
|
||||
url: xyz(
|
||||
'https://wmts.geo.admin.ch/1.0.0/ch.swisstopo.swissimage/default/current/3857/{z}/{x}/{y}.jpeg'
|
||||
),
|
||||
url: swissimage,
|
||||
maxzoom: 20,
|
||||
},
|
||||
{
|
||||
id: 'FR',
|
||||
})),
|
||||
...['FR', 'MC'].map((id) => ({
|
||||
id,
|
||||
attribution: ignAttribution,
|
||||
url: ignOrthophotos,
|
||||
maxzoom: 19,
|
||||
},
|
||||
})),
|
||||
{
|
||||
id: 'ES',
|
||||
attribution: 'PNOA © <a href="https://www.ign.es/" target="_blank">IGN España</a>',
|
||||
@@ -166,7 +209,7 @@ const sources: ImagerySource[] = [
|
||||
maxzoom: 19,
|
||||
},
|
||||
{
|
||||
// mainland Portugal only, as in the tileset of the countries
|
||||
// mainland Portugal only, without its islands
|
||||
id: 'PT',
|
||||
attribution: '<a href="https://www.dgterritorio.gov.pt/" target="_blank">DGT</a>',
|
||||
url: wms(
|
||||
@@ -176,6 +219,17 @@ const sources: ImagerySource[] = [
|
||||
),
|
||||
maxzoom: 19,
|
||||
},
|
||||
{
|
||||
// Madeira
|
||||
id: 'PT-30',
|
||||
attribution:
|
||||
'<a href="https://irig.madeira.gov.pt/" target="_blank">DROTE, iRIG-Madeira</a>',
|
||||
url: wms(
|
||||
'https://irig-sig.madeira.gov.pt/ows/pg/qwc_config/DIR_orto_mosaico?LAYERS=Ortos&FORMAT=image/jpeg'
|
||||
),
|
||||
maxzoom: 20,
|
||||
},
|
||||
...agea,
|
||||
{
|
||||
id: 'DK',
|
||||
attribution:
|
||||
@@ -185,6 +239,33 @@ const sources: ImagerySource[] = [
|
||||
),
|
||||
maxzoom: 20,
|
||||
},
|
||||
{
|
||||
id: 'SI',
|
||||
attribution:
|
||||
'<a href="https://www.e-prostor.gov.si/" target="_blank">Geodetska uprava Republike Slovenije</a>',
|
||||
url: wms(
|
||||
'https://ipi.eprostor.gov.si/wms-si-gurs-dts/ows?LAYERS=SI.GURS.ZPDZ:DOF025_3857&FORMAT=image/jpeg'
|
||||
),
|
||||
maxzoom: 19,
|
||||
},
|
||||
{
|
||||
id: 'SK',
|
||||
attribution: '© <a href="https://www.geoportal.sk/" target="_blank">GKÚ, NLC</a>',
|
||||
url: wms(
|
||||
'https://zbgisws.skgeodesy.sk/zbgis_ortofoto_wms/service.svc/get?LAYERS=1&FORMAT=image/jpeg'
|
||||
),
|
||||
maxzoom: 19,
|
||||
httpsOnly: true,
|
||||
},
|
||||
{
|
||||
id: 'EE',
|
||||
attribution:
|
||||
'<a href="https://geoportaal.maaamet.ee/" target="_blank">Republic of Estonia Land and Spatial Development Board</a>',
|
||||
// its rows are counted from the south
|
||||
url: (z, x, y) =>
|
||||
`https://tiles.maaamet.ee/tm/tms/1.0.0/foto@GMC/${z}/${x}/${2 ** z - 1 - y}.png`,
|
||||
maxzoom: 18,
|
||||
},
|
||||
{
|
||||
id: 'NZ',
|
||||
attribution:
|
||||
@@ -194,6 +275,24 @@ const sources: ImagerySource[] = [
|
||||
),
|
||||
maxzoom: 20,
|
||||
},
|
||||
{
|
||||
id: 'JP',
|
||||
attribution:
|
||||
'<a href="https://maps.gsi.go.jp/development/ichiran.html" target="_blank">国土地理院</a>',
|
||||
url: xyz('https://cyberjapandata.gsi.go.jp/xyz/seamlessphoto/{z}/{x}/{y}.jpg'),
|
||||
// satellite images below
|
||||
minzoom: 14,
|
||||
maxzoom: 18,
|
||||
},
|
||||
{
|
||||
id: 'TW',
|
||||
attribution:
|
||||
'© <a href="https://maps.nlsc.gov.tw/" target="_blank">內政部國土測繪中心 (NLSC)</a>',
|
||||
url: xyz('https://wmts.nlsc.gov.tw/wmts/PHOTO2/default/GoogleMapsCompatible/{z}/{y}/{x}'),
|
||||
// satellite images with clouds below
|
||||
minzoom: 14,
|
||||
maxzoom: 19,
|
||||
},
|
||||
// Germany, by state: Baden-Württemberg is left to the fallback, its services often give blank
|
||||
// tiles
|
||||
{
|
||||
@@ -323,13 +422,12 @@ const sources: ImagerySource[] = [
|
||||
),
|
||||
maxzoom: 19,
|
||||
},
|
||||
// The United States, by state: Alaska, Arizona, Colorado, Delaware, Hawaii and Washington are
|
||||
// left to the fallback. The NAIP has none of Maryland and the District of Columbia, and blurred
|
||||
// images of Oregon and Virginia.
|
||||
...naipStates.map((state) => ({
|
||||
// The United States, by state: Alaska is left to the fallback. The USDA's server has none of
|
||||
// Maryland and the District of Columbia, and blurred images of Oregon and Virginia.
|
||||
...[...naipStates, ...naipPlusStates].map((state) => ({
|
||||
id: `US-${state}`,
|
||||
attribution: '<a href="https://naip-usdaonline.hub.arcgis.com/" target="_blank">USDA</a>',
|
||||
url: naip,
|
||||
url: naipPlusStates.includes(state) ? naipPlus : naip,
|
||||
maxzoom: 18,
|
||||
holes: true,
|
||||
})),
|
||||
@@ -509,7 +607,12 @@ function countriesInTile(
|
||||
const area = rings.reduce((sum, ring) => sum + signedArea(ring), 0);
|
||||
// less than a pixel: a polygon of the tile of the countries outside this one
|
||||
if (area < 1) continue;
|
||||
const same = countries.find((country) => country.source.url === source.url);
|
||||
const same = countries.find(
|
||||
(country) =>
|
||||
country.source.url === source.url &&
|
||||
// Basilicata has the imagery of its neighbours, but not as close
|
||||
Math.min(country.source.maxzoom, z) === Math.min(source.maxzoom, z)
|
||||
);
|
||||
if (same) {
|
||||
same.rings.push(...rings);
|
||||
same.area += area;
|
||||
@@ -567,19 +670,59 @@ function isPng(bytes: ArrayBuffer) {
|
||||
return new Uint8Array(bytes, 0, 1)[0] === 0x89;
|
||||
}
|
||||
|
||||
/** The image of the tile, or of the part of its ancestor at the max zoom of the source. */
|
||||
/**
|
||||
* The image of the tile, or of the part of its ancestor at the max zoom of the source, or of its
|
||||
* descendants at the min zoom.
|
||||
*/
|
||||
async function fetchImage(
|
||||
{ url, maxzoom, holes }: Pick<ImagerySource, 'url' | 'maxzoom' | 'holes'>,
|
||||
source: Omit<ImagerySource, 'id' | 'attribution'>,
|
||||
z: number,
|
||||
x: number,
|
||||
y: number,
|
||||
signal: AbortSignal
|
||||
): Promise<TileImage | null> {
|
||||
const { url, maxzoom, minzoom = 0, holes } = source;
|
||||
if (z < minzoom) return fetchDescendants(source, minzoom - z, z, x, y, signal);
|
||||
const d = Math.max(0, z - maxzoom);
|
||||
const bytes = await fetchBytes(url(z - d, x >> d, y >> d), signal);
|
||||
return bytes && decodeImage(bytes, d, x, y, !!holes && isPng(bytes));
|
||||
}
|
||||
|
||||
/** The tiles `d` zoom levels above that cover the tile, put together, with holes for those missing. */
|
||||
async function fetchDescendants(
|
||||
source: Omit<ImagerySource, 'id' | 'attribution'>,
|
||||
d: number,
|
||||
z: number,
|
||||
x: number,
|
||||
y: number,
|
||||
signal: AbortSignal
|
||||
): Promise<TileImage | null> {
|
||||
const n = 2 ** d;
|
||||
const tiles = await Promise.all(
|
||||
Array.from({ length: n * n }, (_, i) =>
|
||||
fetchImage(source, z + d, x * n + (i % n), y * n + Math.floor(i / n), signal)
|
||||
)
|
||||
);
|
||||
if (tiles.every((tile) => !tile)) return null;
|
||||
const canvas = new OffscreenCanvas(TILE_SIZE * n, TILE_SIZE * n);
|
||||
const context = canvas.getContext('2d')!;
|
||||
tiles.forEach((tile, i) => {
|
||||
if (!tile) return;
|
||||
context.save();
|
||||
context.translate((i % n) * TILE_SIZE, Math.floor(i / n) * TILE_SIZE);
|
||||
drawImage(context, tile);
|
||||
context.restore();
|
||||
tile.image.close();
|
||||
});
|
||||
return {
|
||||
image: canvas.transferToImageBitmap(),
|
||||
sx: 0,
|
||||
sy: 0,
|
||||
size: canvas.width,
|
||||
holes: tiles.some((tile) => !tile || tile.holes),
|
||||
};
|
||||
}
|
||||
|
||||
async function decodeImage(
|
||||
bytes: ArrayBuffer,
|
||||
d: number,
|
||||
@@ -677,7 +820,8 @@ export async function loadTile(
|
||||
|
||||
let images: (TileImage | null)[];
|
||||
const { source, relation } = parts[0];
|
||||
if (parts.length === 1 && relation === 'full' && z <= source.maxzoom) {
|
||||
const ownTile = z >= (source.minzoom ?? 0) && z <= source.maxzoom;
|
||||
if (parts.length === 1 && relation === 'full' && ownTile) {
|
||||
const bytes = await fetchBytes(source.url(z, x, y), signal);
|
||||
const holes = !!bytes && !!source.holes && isPng(bytes);
|
||||
// a single tile as it is, without drawing it again
|
||||
|
||||
Reference in new issue
Block a user