Skip to content

Commit

Permalink
add TileLayer.createTileNode method
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhenn committed Dec 25, 2023
1 parent 1456349 commit b54e2c2
Showing 1 changed file with 39 additions and 71 deletions.
110 changes: 39 additions & 71 deletions src/layer/tile/TileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,24 +303,10 @@ class TileLayer extends Layer {
const error = this._getRootError();
const tiles = [];
const z = 0;
const zoomOffset = this.options['zoomOffset'];
for (let i = -left; i < right; i++) {
for (let j = -top; j < bottom; j++) {
const y = scale.y < 0 ? j : -(j + 1);
tiles.push({
x: i,
y,
z,
idx: i,
idy: y,
res,
extent2d: tileConfig.getTilePrjExtent(i, y, res).convertTo(c => map._prjToPointAtRes(c, res, TEMP_POINT)),
id: this._getTileId(i, y, z),
url: this.getTileUrl(i, y, z + zoomOffset),
offset: [0, 0],
error: error,
children: []
});
tiles.push(this.createTileNode(i, y, z, i, y, res, error));
}
}

Expand All @@ -333,6 +319,33 @@ class TileLayer extends Layer {
return this._getRootNodes(offset0);
}

createTileNode(x, y, z, idx, idy, res, error, parentId, extent2d, tileId) {
const map = this.getMap();
const zoomOffset = this.options['zoomOffset'];
if (!extent2d) {
const tileConfig = this._getTileConfig();
extent2d = tileConfig.getTilePrjExtent(x, y, res).convertTo(c => map._prjToPointAtRes(c, res, TEMP_POINT));
}
const offset = this._getTileOffset(z);

return {
parent: parentId,
layer: this.getId(),
x: x,
y,
z,
idx,
idy,
res,
extent2d,
id: tileId || this._getTileId(x, y, z),
url: this.getTileUrl(x, y, z + zoomOffset),
offset,
error,
children: []
};
}

_getRootError() {
const map = this.getMap();
const fov = toRadian(map.getFov());
Expand Down Expand Up @@ -482,9 +495,6 @@ class TileLayer extends Layer {
if (!childNode) {
childNode = this._createChildNode(node, dx, dy, offset, tileId);
}
if (parentRenderer) {
childNode['layer'] = this.getId();
}
}
childNode.error = node.error / 2;
childNode.offset[0] = offset[0];
Expand Down Expand Up @@ -516,7 +526,7 @@ class TileLayer extends Layer {
}

_createChildNode(node, dx, dy, offset, tileId) {
const zoomOffset = this.options['zoomOffset'];
// const zoomOffset = this.options['zoomOffset'];
const { x, y, idx, idy, extent2d } = node;
const z = node.z + 1;
const childX = (x << 1) + dx;
Expand Down Expand Up @@ -544,21 +554,7 @@ class TileLayer extends Layer {
const swy = miny + dy * height;
extent = new PointExtent(swx, swy, swx + width, swy + height);
}
const childNode = {
parent: node.id,
x: childX,
y: childY,
idx: childIdx,
idy: childIdy,
z,
extent2d: extent,
error: node.error / 2,
res: node.res / 2,
id: tileId,
children: [],
url: this.getTileUrl(childX, childY, z + zoomOffset),
offset
};
const childNode = this.createTileNode(childX, childY, z, childIdx, childIdy, node.res / 2, node.error / 2, node.id, extent, tileId);
this.tileInfoCache.add(tileId, childNode);
return childNode;
}
Expand Down Expand Up @@ -1070,27 +1066,11 @@ class TileLayer extends Layer {
this._visitedTiles.add(tileId);
}
if (canSplitTile && cascadeLevel === 0) {
this._splitTiles(frustumMatrix, tiles, renderer, idx, z + 1, tileRes, tileExtent, dx, dy, tileOffsets, parentRenderer);
this._splitTiles(frustumMatrix, tiles, renderer, idx, z + 1, tileRes, tileExtent, dx, dy, tileOffsets);
extent._combine(tileExtent);
} else {
if (!tileInfo) {
tileInfo = {
//reserve point caculated by tileConfig
//so add offset because we have p._sub(offset) and p._add(dx, dy) if hasOffset
'z': z,
'x': idx.x,
'y': idx.y,
'idx': idx.idx,
'idy': idx.idy,
'extent2d': tileExtent,
'offset': offset,
'id': tileId,
'res': tileRes,
'url': this.getTileUrl(idx.x, idx.y, zoom)
};
if (parentRenderer) {
tileInfo['layer'] = this.getId();
}
tileInfo = this.createTileNode(idx.x, idx.y, z, idx.idx, idx.idy, tileRes, 0, null, tileExtent, tileId);
} else {
tileInfo.offset[0] = offset[0];
tileInfo.offset[1] = offset[1];
Expand Down Expand Up @@ -1147,7 +1127,7 @@ class TileLayer extends Layer {
});
}

_splitTiles(frustumMatrix, tiles, renderer, tileIdx, z, res, tileExtent, dx, dy, tileOffsets, parentRenderer) {
_splitTiles(frustumMatrix, tiles, renderer, tileIdx, z, res, tileExtent, dx, dy, tileOffsets) {
// const hasOffset = offset[0] || offset[1];
const yOrder = this._getTileConfig().tileSystem.scale.y;
const glScale = this.getMap().getGLScale(z);
Expand All @@ -1160,17 +1140,17 @@ class TileLayer extends Layer {
const x = tileIdx.x * 2;
const y = tileIdx.y * 2;

let tile = this._checkAndAddTile(frustumMatrix, renderer, idx, idy, x, y, z, res, 0, 0, w, h, corner, glScale, tileOffsets, parentRenderer);
let tile = this._checkAndAddTile(frustumMatrix, renderer, idx, idy, x, y, z, res, 0, 0, w, h, corner, glScale, tileOffsets);
if (tile) tiles.push(tile);
tile = this._checkAndAddTile(frustumMatrix, renderer, idx, idy, x, y, z, res, 0, 1, w, h, corner, glScale, tileOffsets, parentRenderer);
tile = this._checkAndAddTile(frustumMatrix, renderer, idx, idy, x, y, z, res, 0, 1, w, h, corner, glScale, tileOffsets);
if (tile) tiles.push(tile);
tile = this._checkAndAddTile(frustumMatrix, renderer, idx, idy, x, y, z, res, 1, 0, w, h, corner, glScale, tileOffsets, parentRenderer);
tile = this._checkAndAddTile(frustumMatrix, renderer, idx, idy, x, y, z, res, 1, 0, w, h, corner, glScale, tileOffsets);
if (tile) tiles.push(tile);
tile = this._checkAndAddTile(frustumMatrix, renderer, idx, idy, x, y, z, res, 1, 1, w, h, corner, glScale, tileOffsets, parentRenderer);
tile = this._checkAndAddTile(frustumMatrix, renderer, idx, idy, x, y, z, res, 1, 1, w, h, corner, glScale, tileOffsets);
if (tile) tiles.push(tile);
}

_checkAndAddTile(frustumMatrix, renderer, idx, idy, x, y, z, res, i, j, w, h, corner, glScale, tileOffsets, parentRenderer) {
_checkAndAddTile(frustumMatrix, renderer, idx, idy, x, y, z, res, i, j, w, h, corner, glScale, tileOffsets) {
const tileId = this._getTileId(idx + i, idy + j, z);
if (this._visitedTiles && this._visitedTiles.has(tileId)) {
return null;
Expand All @@ -1190,19 +1170,7 @@ class TileLayer extends Layer {
if (!tileInfo) {
//reserve point caculated by tileConfig
//so add offset because we have p._sub(offset) and p._add(dx, dy) if hasOffset
tileInfo = {
'z': z,
'x': x + i,
'y': y + j,
'extent2d': childExtent,
'id': tileId,
'offset': offset,
'res': childRes,
'url': this.getTileUrl(x + i, y + j, z + this.options['zoomOffset'])
};
if (parentRenderer) {
tileInfo['layer'] = this.getId();
}
tileInfo = this.createTileNode(x + i, y + j, z, idx + i, idx + y, childRes, 0, null, childExtent, tileId);
} else {
tileInfo = tileInfo.info;
}
Expand Down

0 comments on commit b54e2c2

Please sign in to comment.