Skip to content

Commit

Permalink
refactor(Source): remove extentsInsideLimit.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Mar 9, 2021
1 parent 3efea0e commit 035701b
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 132 deletions.
15 changes: 4 additions & 11 deletions src/Layer/LabelLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,16 @@ class LabelLayer extends Layer {

if (!node.layerUpdateState[this.id].canTryUpdate()) {
return;
} else if (!this.source.extentInsideLimit(node.extent, zoomDest)) {
node.layerUpdateState[this.id].noMoreUpdatePossible();
return;
}


const extentsSource = [];
for (const extentDest of extentsDestination) {
const ext = this.source.crs == extentDest.crs ? extentDest : extentDest.as(this.source.crs);
if (!this.source.extentInsideLimit(ext)) {
node.layerUpdateState[this.id].noMoreUpdatePossible();
return;
}
extentsSource.push(extentDest);
}
node.layerUpdateState[this.id].newTry();

const command = {
layer: this,
extentsSource,
extentsSource: extentsDestination,
view: context.view,
threejsLayer: this.threejsLayer,
requester: node,
Expand Down
4 changes: 2 additions & 2 deletions src/Layer/TiledGeometryLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class TiledGeometryLayer extends GeometryLayer {
if (zoom > e.zoom.max || zoom < e.zoom.min) {
continue;
}
if (!e.frozen && e.ready && e.source.extentsInsideLimit(extents) && (!nodeLayer || nodeLayer.level < 0)) {
if (!e.frozen && e.ready && e.source.extentInsideLimit(node.extent, zoom) && (!nodeLayer || nodeLayer.level < 0)) {
// no stop subdivision in the case of a loading error
if (layerUpdateState[e.id] && layerUpdateState[e.id].inError()) {
continue;
Expand All @@ -322,7 +322,7 @@ class TiledGeometryLayer extends GeometryLayer {
continue;
}
nodeLayer = node.material.getLayer(c.id);
if (c.source.extentsInsideLimit(extents) && (!nodeLayer || nodeLayer.level < 0)) {
if (c.source.extentInsideLimit(node.extent, zoom) && (!nodeLayer || nodeLayer.level < 0)) {
return false;
}
}
Expand Down
30 changes: 9 additions & 21 deletions src/Process/FeatureProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ function assignLayer(object, layer) {
}
}

function extentInsideSource(extent, source) {
return !source.extentInsideLimit(extent) ||
(source.isFileSource && !extent.isPointInside(source.extent.center(coord)));
}

export default {
update(context, layer, node) {
if (!node.parent && node.children.length) {
Expand All @@ -55,9 +50,7 @@ export default {

if (node.layerUpdateState[layer.id] === undefined) {
node.layerUpdateState[layer.id] = new LayerUpdateState();
}

if (!node.layerUpdateState[layer.id].canTryUpdate()) {
} else if (!node.layerUpdateState[layer.id].canTryUpdate()) {
return;
}

Expand All @@ -71,27 +64,22 @@ export default {

const zoomDest = extentsDestination[0].zoom;

if (zoomDest != layer.zoom.min) {
// check if it's tile level is equal to display level layer.
if (zoomDest != layer.zoom.min ||
// check if there's data in extent tile.
!this.source.extentInsideLimit(node.extent, zoomDest) ||
// In FileSource case, check if the feature center is in extent tile.
(layer.source.isFileSource && !node.extent.isPointInside(layer.source.extent.center(coord)))) {
// if not, there's not data to add at this tile.
node.layerUpdateState[layer.id].noMoreUpdatePossible();
return;
}

const extentsSource = [];
for (const extentDest of extentsDestination) {
const ext = layer.source.crs == extentDest.crs ? extentDest : extentDest.as(layer.source.crs);
ext.zoom = extentDest.zoom;
if (extentInsideSource(ext, layer.source)) {
node.layerUpdateState[layer.id].noMoreUpdatePossible();
return;
}
extentsSource.push(extentDest);
}

node.layerUpdateState[layer.id].newTry();

const command = {
layer,
extentsSource,
extentsSource: extentsDestination,
view: context.view,
threejsLayer: layer.threejsLayer,
requester: node,
Expand Down
38 changes: 11 additions & 27 deletions src/Process/LayeredMaterialNodeProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function updateLayeredMaterialNodeImagery(context, layer, node, parent) {
if (node.layerUpdateState[layer.id] === undefined) {
node.layerUpdateState[layer.id] = new LayerUpdateState();

if (!layer.source.extentsInsideLimit(extentsDestination)) {
if (!layer.source.extentInsideLimit(node.extent, zoom)) {
// we also need to check that tile's parent doesn't have a texture for this layer,
// because even if this tile is outside of the layer, it could inherit it's
// parent texture
Expand Down Expand Up @@ -126,23 +126,13 @@ export function updateLayeredMaterialNodeImagery(context, layer, node, parent) {
node.layerUpdateState[layer.id].noMoreUpdatePossible();
}
return;
} else if (!layer.source.extentInsideLimit(node.extent, targetLevel)) {
node.layerUpdateState[layer.id].noData({ targetLevel });
context.view.notifyChange(node, false);
return;
}

// Get equivalent of extent destination in source
const extentsSource = [];
for (const extentDestination of extentsDestination) {
const extentSource = extentDestination.tiledExtentParent(targetLevel);
if (!layer.source.extentInsideLimit(extentSource)) {
// Retry extentInsideLimit because you must check with the targetLevel
// if the first test extentInsideLimit returns that it is out of limits
// and the node inherits from its parent, then it'll still make a command to fetch texture.
node.layerUpdateState[layer.id].noData({ targetLevel });
context.view.notifyChange(node, false);
return;
}
extentsSource.push(extentSource);
}

const extentsSource = extentsDestination.map(e => e.tiledExtentParent(targetLevel));
node.layerUpdateState[layer.id].newTry();
const features = nodeLayer.textures.map(t => layer.isValidData(t.features));
const command = buildCommand(context.view, layer, extentsSource, extentsDestination, node, features);
Expand Down Expand Up @@ -206,19 +196,13 @@ export function updateLayeredMaterialNodeElevation(context, layer, node, parent)
if (targetLevel <= nodeLayer.level || targetLevel > extentsDestination[0].zoom) {
node.layerUpdateState[layer.id].noMoreUpdatePossible();
return;
} else if (!layer.source.extentInsideLimit(node.extent, targetLevel)) {
node.layerUpdateState[layer.id].noData({ targetLevel });
context.view.notifyChange(node, false);
return;
}

const extentsSource = [];
for (const nodeExtent of extentsDestination) {
const extentSource = nodeExtent.tiledExtentParent(targetLevel);
if (!layer.source.extentInsideLimit(extentSource)) {
node.layerUpdateState[layer.id].noData({ targetLevel });
context.view.notifyChange(node, false);
return;
}
extentsSource.push(extentSource);
}

const extentsSource = extentsDestination.map(e => e.tiledExtentParent(targetLevel));
node.layerUpdateState[layer.id].newTry();
const command = buildCommand(context.view, layer, extentsSource, extentsDestination, node);

Expand Down
10 changes: 2 additions & 8 deletions src/Source/FileSource.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import Source from 'Source/Source';
import Cache from 'Core/Scheduler/Cache';
import Extent from 'Core/Geographic/Extent';
import CRS from 'Core/Geographic/Crs';

const ext = new Extent('EPSG:4326', [0, 0, 0, 0]);

/**
* @classdesc
* An object defining the source of a single resource to get from a direct
Expand Down Expand Up @@ -150,7 +147,7 @@ class FileSource extends Source {

this.whenReady.then(() => this.fetchedData);

this.zoom = source.zoom || { min: 0, max: Infinity };
this.zoom = { min: 0, max: Infinity };
}

urlFromExtent() {
Expand Down Expand Up @@ -190,10 +187,7 @@ class FileSource extends Source {
}

extentInsideLimit(extent) {
// Fix me => may be not
const localExtent = this.extent.crs == extent.crs ? extent : extent.as(this.extent.crs, ext);
return (extent.zoom == undefined || !(extent.zoom < this.zoom.min || extent.zoom > this.zoom.max)) &&
this.extent.intersectsExtent(localExtent);
return this.extent.intersectsExtent(extent);
}
}

Expand Down
16 changes: 0 additions & 16 deletions src/Source/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,6 @@ class Source extends InformationsData {
extentInsideLimit(extent) {
throw new Error('In extented Source, you have to implement the method extentInsideLimit!');
}

/**
* Tests if an array of extents is inside the source limits.
*
* @param {Array.<Extent>} extents - Array of extents to test.
* @return {boolean} True if all extents are inside, false otherwise.
*/
extentsInsideLimit(extents) {
for (const extent of extents) {
if (!this.extentInsideLimit(extent)) {
return false;
}
}
return true;
}
}

export default Source;
41 changes: 29 additions & 12 deletions src/Source/TMSSource.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Source from 'Source/Source';
import URLBuilder from 'Provider/URLBuilder';
import { globalExtentTMS } from 'Core/Geographic/Extent';
import Extent, { globalExtentTMS } from 'Core/Geographic/Extent';
import CRS from 'Core/Geographic/Crs';

const extent = new Extent(CRS.tms_4326, 0, 0, 0);

/**
* @classdesc
* An object defining the source of resources to get from a [TMS]{@link
Expand All @@ -20,8 +22,8 @@ import CRS from 'Core/Geographic/Crs';
* or other system. See [this link]{@link
* https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates/}
* for more information.
* @property {string} tileMatrixSet - Tile matrix set of the layer, used in the
* generation of the coordinates to build the url. Default value is 'WGS84'.
* @property {Object} tileMatrixSetLimits - it describes the available tile for this layer
* @property {Object} extentSetlimits - these are the extents of the set of identical zoom tiles.
* @property {Object} zoom - Object containing the minimum and maximum values of
* the level, to zoom in the source.
* @property {number} zoom.min - The minimum level of the source. Default value
Expand All @@ -38,7 +40,7 @@ import CRS from 'Core/Geographic/Crs';
* name: 'OpenStreetMap',
* url: 'http://www.openstreetmap.org/',
* },
* tileMatrixSet: 'PM',
* crs: 'EPSG:3857',
* });
*
* // Create the layer
Expand Down Expand Up @@ -78,6 +80,7 @@ class TMSSource extends Source {
this.url = source.url;
this.crs = CRS.formatToTms(source.crs);
this.tileMatrixSetLimits = source.tileMatrixSetLimits;
this.extentSetlimits = {};

if (!this.zoom) {
if (this.tileMatrixSetLimits) {
Expand All @@ -91,7 +94,7 @@ class TMSSource extends Source {
max: maxZoom,
};
} else {
this.zoom = { min: 0, max: 20 };
this.zoom = { min: 0, max: Infinity };
}
}
}
Expand All @@ -100,16 +103,30 @@ class TMSSource extends Source {
return URLBuilder.xyz(extent, this);
}

extentInsideLimit(extent) {
onLayerAdded(options) {
super.onLayerAdded(options);
// Build extents of the set of identical zoom tiles.
const parent = options.out.parent;
// The extents crs is chosen to facilitate in raster tile process.
const crs = parent ? parent.extent.crs : options.out.crs;
if (this.tileMatrixSetLimits && !this.extentSetlimits[crs]) {
this.extentSetlimits[crs] = {};
extent.crs = this.crs;
for (let i = this.zoom.max; i >= this.zoom.min; i--) {
const tmsl = this.tileMatrixSetLimits[i];
const { west, north } = extent.set(i, tmsl.minTileRow, tmsl.minTileCol).as(crs);
const { east, south } = extent.set(i, tmsl.maxTileRow, tmsl.maxTileCol).as(crs);
this.extentSetlimits[crs][i] = new Extent(crs, west, east, south, north);
}
}
}

extentInsideLimit(extent, zoom) {
// This layer provides data starting at level = layer.source.zoom.min
// (the zoom.max property is used when building the url to make
// sure we don't use invalid levels)
return extent.zoom >= this.zoom.min && extent.zoom <= this.zoom.max &&
(this.tileMatrixSetLimits == undefined ||
(extent.row >= this.tileMatrixSetLimits[extent.zoom].minTileRow &&
extent.row <= this.tileMatrixSetLimits[extent.zoom].maxTileRow &&
extent.col >= this.tileMatrixSetLimits[extent.zoom].minTileCol &&
extent.col <= this.tileMatrixSetLimits[extent.zoom].maxTileCol));
return zoom >= this.zoom.min && zoom <= this.zoom.max &&
(this.extentSetlimits[extent.crs] == undefined || this.extentSetlimits[extent.crs][zoom].intersectsExtent(extent));
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/Source/WFSSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class WFSSource extends Source {
}&outputFormat=${this.format
}&BBOX=%bbox,${this.crs}`;

this.zoom = source.zoom || { min: 0, max: Infinity };
this.zoom = { min: 0, max: Infinity };

this.vendorSpecific = source.vendorSpecific;
for (const name in this.vendorSpecific) {
Expand Down Expand Up @@ -162,8 +162,7 @@ class WFSSource extends Source {
}

extentInsideLimit(extent) {
return (extent.zoom == undefined || (extent.zoom >= this.zoom.min && extent.zoom <= this.zoom.max))
&& this.extent.intersectsExtent(extent);
return this.extent.intersectsExtent(extent);
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/Source/WMSSource.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Source from 'Source/Source';
import URLBuilder from 'Provider/URLBuilder';
import Extent from 'Core/Geographic/Extent';

const _extent = new Extent('EPSG:4326', 0, 0, 0, 0);
/**
* @classdesc
* An object defining the source of images to get from a
Expand Down Expand Up @@ -94,7 +92,7 @@ class WMSSource extends Source {

this.isWMSSource = true;
this.name = source.name;
this.zoom = source.zoom || { min: 0, max: 21 };
this.zoom = { min: 0, max: Infinity };
this.style = source.style || '';

this.width = source.width || source.height || 256;
Expand Down Expand Up @@ -139,9 +137,7 @@ class WMSSource extends Source {
}

extentInsideLimit(extent) {
const localExtent = this.crs == extent.crs ? extent : extent.as(this.crs, _extent);
return (extent.zoom == undefined || !(extent.zoom < this.zoom.min || extent.zoom > this.zoom.max)) &&
this.extent.intersectsExtent(localExtent);
return this.extent.intersectsExtent(extent);
}
}

Expand Down
1 change: 0 additions & 1 deletion test/unit/layeredmaterialnodeprocessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ describe('updateLayeredMaterialNodeImagery', function () {
};
layer.visible = true;

source.extentsInsideLimit = () => true;
source.extentInsideLimit = () => true;
source.zoom = { min: 0, max: 10 };
source.extent = { crs: 'EPSG:4326' };
Expand Down
Loading

0 comments on commit 035701b

Please sign in to comment.