Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/Main/src/Core/Scheduler/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import DataSourceProvider from 'Provider/DataSourceProvider';
import TileProvider from 'Provider/TileProvider';
import $3dTilesProvider from 'Provider/3dTilesProvider';
import PointCloudProvider from 'Provider/PointCloudProvider';
import URLBuilder from 'Provider/URLBuilder';
import * as URLBuilder from 'Provider/URLBuilder';
import CancelledCommandException from './CancelledCommandException';

function queueOrdering(a, b) {
Expand Down
6 changes: 6 additions & 0 deletions packages/Main/src/Core/Tile/Tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import * as THREE from 'three';
import { Coordinates, CRS, Extent } from '@itowns/geographic';
import { getInfoTms, getCountTiles } from './TileGrid';

export interface TileLike {
zoom: number;
row: number;
col: number;
}

const _tmsCoord = new THREE.Vector2();
const _dimensionTile = new THREE.Vector2();
const r = { row: 0, col: 0, invDiff: 0 };
Expand Down
4 changes: 2 additions & 2 deletions packages/Main/src/Process/LayeredMaterialNodeProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function refinementCommandCancellationFn(cmd) {
}

// Cancel the command if the layer was removed between command scheduling and command execution
if (!cmd.requester.layerUpdateState[cmd.layer.id]
|| !cmd.layer.source._featuresCaches[cmd.layer.crs]) {
if (!cmd.requester.layerUpdateState[cmd.layer.id]) {
// || !cmd.layer.source._featuresCaches[cmd.layer.crs]) {
return true;
}

Expand Down
129 changes: 0 additions & 129 deletions packages/Main/src/Provider/URLBuilder.js

This file was deleted.

146 changes: 146 additions & 0 deletions packages/Main/src/Provider/URLBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { TileLike } from 'Core/Tile/Tile';

let subDomainsCount = 0;

interface ExtentLike {
west: number;
south: number;
east: number;
north: number;
}

interface TileSource {
readonly url: string;
readonly tileMatrixCallback: (zoom: number) => string;
}

interface ExtentSource {
readonly url: string;
readonly crs: string;
readonly bboxDigits?: number;
readonly axisOrder?: string;
}

/**
* Builds an URL from a subdomain template.
* <br><br>
* The template uses the pattern `${u:subdomain1|subdomain2|subdomain3}` where
* subdomains are separated by `|`. Each call to this function will cycle
* through the subdomains in sequence, returning the next one in the list.
* <br><br>
* For example, `${u:a|b|c}` will be replaced by `a`, then `b`, then `c`, and
* then loop back to `a`.
*
* @example
* ```
* const url = 'https://${u:a|b|c}.tile.openstreetmap.org/';
* const urlWithSubdomains = subDomains(url);
* // First call returns 'https://a.tile.openstreetmap.org/'
* // Second call returns 'https://b.tile.openstreetmap.org/'
* // Third call returns 'https://c.tile.openstreetmap.org/'
* // And so on...
* ```
*
* @param url - The URL to process for subdomains
* @returns The URL with subdomain replacement applied
*/
export function subDomains(url: string): string {
const subDomainsPtrn = /\$\{u:([\w-_.|]+)\}/.exec(url);

if (!subDomainsPtrn) {
return url;
}

const subDomainsList = subDomainsPtrn[1].split('|');

return url.replace(
subDomainsPtrn[0],
subDomainsList[(subDomainsCount++) % subDomainsList.length],
);
}

/**
* Builds an URL knowing the coordinates and the source to query.
* <br><br>
* The source object needs to have an url property, which should have some
* specific strings that will be replaced by coordinates.
* <ul>
* <li>`${x}` or `%COL` will be replaced by `coords.col`</li>
* <li>`${y}` or `%ROW` will be replaced by `coords.row`</li>
* <li>`${z}` or `%TILEMATRIX` will be replaced by `coords.zoom`</li>
* </ul>
*
* @example
* ```
* coords = new Extent(CRS.formatToTms('EPSG:4326'), 12, 1410, 2072);
* source.url = 'http://server.geo/wmts/SERVICE=WMTS&TILEMATRIX=%TILEMATRIX&TILEROW=%ROW&TILECOL=%COL';
* url = xyz(coords, source);
*
* // The resulting url is:
* // http://server.geo/wmts/SERVICE=WMTS&TILEMATRIX=12&TILEROW=1410&TILECOL=2072;
* ```
* @example
* ```
* coords = new Extent('TMS', 15, 2142, 3412);
* source.url = 'http://server.geo/tms/${z}/${y}/${x}.jpg';
* url = xyz(coords, source);
*
* // The resulting url is:
* // http://server.geo/tms/15/2142/3412.jpg;
* ```
* @param coords - tile coordinates
* @param source - the source object (url and tileMatrixCallback)
*
* @returns the formed url
*/
export function xyz(coords: TileLike, source: TileSource): string {
return source.url.replace(/(\$\{z\}|%TILEMATRIX)/, source.tileMatrixCallback(coords.zoom))
.replace(/(\$\{y\}|%ROW)/, coords.row.toString())
.replace(/(\$\{x\}|%COL)/, coords.col.toString());
}

/**
* Builds an URL knowing the bounding box and the source to query.
* <br><br>
* The source object needs to have an url property, which should have the
* string `%bbox` in it. This string will be replaced by the four cardinal
* points composing the bounding box.
* <br><br>
* Order of the points can be specified in the `axisOrder` property in
* source, using the letters `w, s, e, n` respectively for
* `WEST, SOUTH, EAST, NORTH`. The default order is `wsen`.
*
* @example
* ```
* extent = new Extent('EPSG:4326', 12, 14, 35, 46);
* source.crs = 'EPSG:4326';
* source.url = 'http://server.geo/wms/BBOX=%bbox&FORMAT=jpg&SERVICE=WMS';
* url = bbox(extent, source);
*
* // The resulting url is:
* // http://server.geo/wms/BBOX=12,35,14,46&FORMAT=jpg&SERVICE=WMS
* ```
* @param bbox - the bounding box (west, south, east, north)
* @param source - the source of data (url, crs, bboxDigits and axisOrder)
*
* @returns the formed url
*/
export function bbox(bbox: ExtentLike, source: ExtentSource): string {
let precision = source.crs == 'EPSG:4326' ? 9 : 2;
if (source.bboxDigits !== undefined) {
precision = source.bboxDigits;
}
const w = bbox.west.toFixed(precision);
const s = bbox.south.toFixed(precision);
const e = bbox.east.toFixed(precision);
const n = bbox.north.toFixed(precision);

let bboxInUnit = source.axisOrder || 'wsen';
bboxInUnit = bboxInUnit.replace('w', `${w},`)
.replace('s', `${s},`)
.replace('e', `${e},`)
.replace('n', `${n},`)
.slice(0, -1);

return source.url.replace('%bbox', bboxInUnit);
}
8 changes: 8 additions & 0 deletions packages/Main/src/Source/C3DTilesSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ class C3DTilesSource extends Source {
*/
constructor(source) {
super(source);

this.isC3DTilesSource = true;

if (!source.url) {
throw new Error(`[${this.constructor.name}]: url is required`);
}

this.url = source.url;
this.networkOptions = source.networkOptions ?? {};
this.baseUrl = this.url.slice(0, this.url.lastIndexOf('/') + 1);
this.whenReady = Fetcher.json(this.url, this.networkOptions);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/Main/src/Source/CopcSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class CopcSource extends Source {

this.isCopcSource = true;

this.url = config.url;
this.networkOptions = config.networkOptions;

this.parser = LASParser.parseChunk;
this.fetcher = Fetcher.arrayBuffer;

Expand Down
7 changes: 7 additions & 0 deletions packages/Main/src/Source/EntwinePointTileSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class EntwinePointTileSource extends Source {
this.isEntwinePointTileSource = true;
this.colorDepth = config.colorDepth;

if (!config.url) {
throw new Error(`[${this.constructor.name}]: url is required`);
}

this.url = config.url;
this.networkOptions = config.networkOptions ?? {};

// Necessary because we use the url without the ept.json part as a base
this.url = this.url.replace('/ept.json', '');

Expand Down
Loading
Loading