mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-11-30 09:34:29 +00:00
uniform low zoom level imagery
This commit is contained in:
1 parent
2cf9a9f982
commit
5f46b08eda
2 files changed
+22
-24
No files matched your search
@@ -26,16 +26,21 @@ describe('planTile', () => {
|
|||||||
assert.deepEqual(await plan(21.01, 52.23, 16), { parts: ['pl:full'], fallback: false });
|
assert.deepEqual(await plan(21.01, 52.23, 16), { parts: ['pl:full'], fallback: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('takes every tile up to zoom 12 from the imagery of the whole world', async () => {
|
||||||
|
assert.deepEqual(await plan(2.35, 48.85, 12), { parts: [], fallback: true });
|
||||||
|
assert.deepEqual(await plan(7.589, 47.5895, 12), { parts: [], fallback: true });
|
||||||
|
});
|
||||||
|
|
||||||
it('takes a tile outside every country from the fallback', async () => {
|
it('takes a tile outside every country from the fallback', async () => {
|
||||||
assert.deepEqual(await plan(-0.12, 51.5, 14), { parts: [], fallback: true });
|
assert.deepEqual(await plan(-0.12, 51.5, 14), { parts: [], fallback: true });
|
||||||
// Germany, which is not in the patchwork
|
// Germany, which is not in the patchwork
|
||||||
assert.deepEqual(await plan(9.73, 52.37, 14), { parts: [], fallback: true });
|
assert.deepEqual(await plan(9.73, 52.37, 14), { parts: [], fallback: true });
|
||||||
assert.deepEqual(await plan(-30, 40, 10), { parts: [], fallback: true });
|
assert.deepEqual(await plan(-30, 40, 13), { parts: [], fallback: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('puts the countries of a border tile together, over the fallback where none is', async () => {
|
it('puts the countries of a border tile together, over the fallback where none is', async () => {
|
||||||
// Menton: France and Italy, which is not in the patchwork
|
// Menton: France and Italy, which is not in the patchwork
|
||||||
assert.deepEqual(await plan(7.5, 43.8, 12), {
|
assert.deepEqual(await plan(7.5, 43.78, 13), {
|
||||||
parts: ['fr:partial'],
|
parts: ['fr:partial'],
|
||||||
fallback: true,
|
fallback: true,
|
||||||
});
|
});
|
||||||
@@ -50,8 +55,4 @@ describe('planTile', () => {
|
|||||||
fallback: false,
|
fallback: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not take a tile covering several countries from their agencies', async () => {
|
|
||||||
assert.deepEqual(await plan(2.35, 48.85, 6), { parts: [], fallback: true });
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
@@ -15,8 +15,6 @@ type ImagerySource = {
|
|||||||
/** Key of the coverage in satellite-coverage.json */
|
/** Key of the coverage in satellite-coverage.json */
|
||||||
id: string;
|
id: string;
|
||||||
url: TileUrl;
|
url: TileUrl;
|
||||||
/** Below it, a tile spans too many sources and the fallback is used. */
|
|
||||||
minzoom: number;
|
|
||||||
/** Above it, the tile of this zoom level is scaled up. */
|
/** Above it, the tile of this zoom level is scaled up. */
|
||||||
maxzoom: number;
|
maxzoom: number;
|
||||||
};
|
};
|
||||||
@@ -26,6 +24,16 @@ const xyz =
|
|||||||
(z, x, y) =>
|
(z, x, y) =>
|
||||||
template.replace('{z}', String(z)).replace('{x}', String(x)).replace('{y}', String(y));
|
template.replace('{z}', String(z)).replace('{x}', String(x)).replace('{y}', String(y));
|
||||||
|
|
||||||
|
const ignOrthophotos = xyz(
|
||||||
|
'https://data.geopf.fr/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=ORTHOIMAGERY.ORTHOPHOTOS&STYLE=normal&FORMAT=image/jpeg&TILEMATRIXSET=PM&TILEMATRIX={z}&TILECOL={x}&TILEROW={y}'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Up to zoom 12, IGN's orthophotos cover the whole world with a mosaic of satellite images: all
|
||||||
|
* tiles come from it there, and the national sources and the commercial fallback only above.
|
||||||
|
*/
|
||||||
|
const world: ImagerySource = { id: 'world', url: ignOrthophotos, maxzoom: 12 };
|
||||||
|
|
||||||
/** In order of priority, the first one covering a point is used. */
|
/** In order of priority, the first one covering a point is used. */
|
||||||
const sources: ImagerySource[] = [
|
const sources: ImagerySource[] = [
|
||||||
{
|
{
|
||||||
@@ -33,15 +41,11 @@ const sources: ImagerySource[] = [
|
|||||||
url: xyz(
|
url: xyz(
|
||||||
'https://wmts.geo.admin.ch/1.0.0/ch.swisstopo.swissimage/default/current/3857/{z}/{x}/{y}.jpeg'
|
'https://wmts.geo.admin.ch/1.0.0/ch.swisstopo.swissimage/default/current/3857/{z}/{x}/{y}.jpeg'
|
||||||
),
|
),
|
||||||
minzoom: 8,
|
|
||||||
maxzoom: 20,
|
maxzoom: 20,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'fr',
|
id: 'fr',
|
||||||
url: xyz(
|
url: ignOrthophotos,
|
||||||
'https://data.geopf.fr/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=ORTHOIMAGERY.ORTHOPHOTOS&STYLE=normal&FORMAT=image/jpeg&TILEMATRIXSET=PM&TILEMATRIX={z}&TILECOL={x}&TILEROW={y}'
|
|
||||||
),
|
|
||||||
minzoom: 8,
|
|
||||||
maxzoom: 19,
|
maxzoom: 19,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -49,7 +53,6 @@ const sources: ImagerySource[] = [
|
|||||||
url: xyz(
|
url: xyz(
|
||||||
'https://www.ign.es/wmts/pnoa-ma?layer=OI.OrthoimageCoverage&style=default&tilematrixset=GoogleMapsCompatible&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image/jpeg&TileMatrix={z}&TileCol={x}&TileRow={y}'
|
'https://www.ign.es/wmts/pnoa-ma?layer=OI.OrthoimageCoverage&style=default&tilematrixset=GoogleMapsCompatible&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image/jpeg&TileMatrix={z}&TileCol={x}&TileRow={y}'
|
||||||
),
|
),
|
||||||
minzoom: 8,
|
|
||||||
maxzoom: 19,
|
maxzoom: 19,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -57,7 +60,6 @@ const sources: ImagerySource[] = [
|
|||||||
url: xyz(
|
url: xyz(
|
||||||
'https://mapsneu.wien.gv.at/basemap/bmaporthofoto30cm/normal/google3857/{z}/{y}/{x}.jpeg'
|
'https://mapsneu.wien.gv.at/basemap/bmaporthofoto30cm/normal/google3857/{z}/{y}/{x}.jpeg'
|
||||||
),
|
),
|
||||||
minzoom: 8,
|
|
||||||
maxzoom: 19,
|
maxzoom: 19,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -65,7 +67,6 @@ const sources: ImagerySource[] = [
|
|||||||
url: xyz(
|
url: xyz(
|
||||||
'https://service.pdok.nl/hwh/luchtfotorgb/wmts/v1_0/Actueel_orthoHR/EPSG:3857/{z}/{x}/{y}.jpeg'
|
'https://service.pdok.nl/hwh/luchtfotorgb/wmts/v1_0/Actueel_orthoHR/EPSG:3857/{z}/{x}/{y}.jpeg'
|
||||||
),
|
),
|
||||||
minzoom: 8,
|
|
||||||
maxzoom: 19,
|
maxzoom: 19,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -73,7 +74,6 @@ const sources: ImagerySource[] = [
|
|||||||
url: xyz(
|
url: xyz(
|
||||||
'https://wmts1.geoportail.lu/opendata/wmts/ortho_latest/GLOBAL_WEBMERCATOR_4_V3/{z}/{x}/{y}.jpeg'
|
'https://wmts1.geoportail.lu/opendata/wmts/ortho_latest/GLOBAL_WEBMERCATOR_4_V3/{z}/{x}/{y}.jpeg'
|
||||||
),
|
),
|
||||||
minzoom: 8,
|
|
||||||
maxzoom: 19,
|
maxzoom: 19,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -81,7 +81,6 @@ const sources: ImagerySource[] = [
|
|||||||
url: xyz(
|
url: xyz(
|
||||||
'https://ags.cuzk.gov.cz/arcgis1/rest/services/ORTOFOTO_WM/MapServer/tile/{z}/{y}/{x}'
|
'https://ags.cuzk.gov.cz/arcgis1/rest/services/ORTOFOTO_WM/MapServer/tile/{z}/{y}/{x}'
|
||||||
),
|
),
|
||||||
minzoom: 8,
|
|
||||||
maxzoom: 19,
|
maxzoom: 19,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -89,7 +88,6 @@ const sources: ImagerySource[] = [
|
|||||||
url: xyz(
|
url: xyz(
|
||||||
'https://wmts.ngi.be/inspire/ortho/1.0.0/orthoimage_coverage/default/3857/latest/{z}/{y}/{x}.png'
|
'https://wmts.ngi.be/inspire/ortho/1.0.0/orthoimage_coverage/default/3857/latest/{z}/{y}/{x}.png'
|
||||||
),
|
),
|
||||||
minzoom: 8,
|
|
||||||
maxzoom: 19,
|
maxzoom: 19,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -97,7 +95,6 @@ const sources: ImagerySource[] = [
|
|||||||
url: xyz(
|
url: xyz(
|
||||||
'https://mapy.geoportal.gov.pl/wss/service/PZGIK/ORTO/WMTS/StandardResolution?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=ORTOFOTOMAPA&STYLE=default&FORMAT=image/jpeg&TILEMATRIXSET=EPSG:3857&TILEMATRIX=EPSG:3857:{z}&TILEROW={y}&TILECOL={x}'
|
'https://mapy.geoportal.gov.pl/wss/service/PZGIK/ORTO/WMTS/StandardResolution?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=ORTOFOTOMAPA&STYLE=default&FORMAT=image/jpeg&TILEMATRIXSET=EPSG:3857&TILEMATRIX=EPSG:3857:{z}&TILEROW={y}&TILECOL={x}'
|
||||||
),
|
),
|
||||||
minzoom: 8,
|
|
||||||
maxzoom: 19,
|
maxzoom: 19,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -357,12 +354,12 @@ export async function planTile(
|
|||||||
x: number,
|
x: number,
|
||||||
y: number
|
y: number
|
||||||
): Promise<{ parts: TilePart[]; fallback: boolean }> {
|
): Promise<{ parts: TilePart[]; fallback: boolean }> {
|
||||||
|
if (z <= world.maxzoom) return { parts: [], fallback: true };
|
||||||
const n = 2 ** z;
|
const n = 2 ** z;
|
||||||
const rect: Rect = [x / n, y / n, (x + 1) / n, (y + 1) / n];
|
const rect: Rect = [x / n, y / n, (x + 1) / n, (y + 1) / n];
|
||||||
const coverageBySource = await getCoverages();
|
const coverageBySource = await getCoverages();
|
||||||
const parts: TilePart[] = [];
|
const parts: TilePart[] = [];
|
||||||
for (const source of sources) {
|
for (const source of sources) {
|
||||||
if (z < source.minzoom) continue;
|
|
||||||
const relation = relate(coverageBySource.get(source.id)!, rect);
|
const relation = relate(coverageBySource.get(source.id)!, rect);
|
||||||
if (relation.relation === 'full') {
|
if (relation.relation === 'full') {
|
||||||
return { parts: [{ ...relation, source }], fallback: false };
|
return { parts: [{ ...relation, source }], fallback: false };
|
||||||
@@ -377,8 +374,7 @@ export function maptilerSource(maptilerKey: string): ImagerySource {
|
|||||||
return {
|
return {
|
||||||
id: 'fallback',
|
id: 'fallback',
|
||||||
url: xyz(`https://api.maptiler.com/tiles/satellite-v2/{z}/{x}/{y}.jpg?key=${maptilerKey}`),
|
url: xyz(`https://api.maptiler.com/tiles/satellite-v2/{z}/{x}/{y}.jpg?key=${maptilerKey}`),
|
||||||
minzoom: 0,
|
maxzoom: 18,
|
||||||
maxzoom: 20,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,9 +382,10 @@ export async function loadTile(
|
|||||||
z: number,
|
z: number,
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
fallback: ImagerySource,
|
commercialFallback: ImagerySource,
|
||||||
signal: AbortSignal
|
signal: AbortSignal
|
||||||
): Promise<ArrayBuffer | ImageBitmap> {
|
): Promise<ArrayBuffer | ImageBitmap> {
|
||||||
|
const fallback = z <= world.maxzoom ? world : commercialFallback;
|
||||||
const plan = await planTile(z, x, y);
|
const plan = await planTile(z, x, y);
|
||||||
const { parts } = plan;
|
const { parts } = plan;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user