From c31a50b13985cbcedc50ec2f53f2f081708fb57e Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Fri, 1 Oct 2021 01:33:07 +0200 Subject: [PATCH] BBox bounds can not be bigger then the entire world anymore, fixes performance issues --- Logic/BBox.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Logic/BBox.ts b/Logic/BBox.ts index e642c6ce3..a6f350cf8 100644 --- a/Logic/BBox.ts +++ b/Logic/BBox.ts @@ -22,6 +22,13 @@ export class BBox { this.minLon = Math.min(this.minLon, coordinate[0]); this.minLat = Math.min(this.minLat, coordinate[1]); } + + this.maxLon = Math.min(this.maxLon, 180) + this.maxLat = Math.min(this.maxLat, 90) + this.minLon = Math.max(this.minLon, -180) + this.minLat = Math.max(this.minLat, -90) + + this.check(); } @@ -41,10 +48,10 @@ export class BBox { * Constructs a tilerange which fully contains this bbox (thus might be a bit larger) * @param zoomlevel */ - public containingTileRange(zoomlevel): TileRange{ - return Tiles.TileRangeBetween(zoomlevel, this.minLat, this.minLon, this.maxLat, this.maxLon) + public containingTileRange(zoomlevel): TileRange { + return Tiles.TileRangeBetween(zoomlevel, this.minLat, this.minLon, this.maxLat, this.maxLon) } - + public overlapsWith(other: BBox) { if (this.maxLon < other.minLon) { return false; @@ -148,7 +155,7 @@ export class BBox { * Expands the BBOx so that it contains complete tiles for the given zoomlevel * @param zoomlevel */ - expandToTileBounds(zoomlevel: number) : BBox{ + expandToTileBounds(zoomlevel: number): BBox { const ul = Tiles.embedded_tile(this.minLat, this.minLon, zoomlevel) const lr = Tiles.embedded_tile(this.maxLat, this.maxLon, zoomlevel) const boundsul = Tiles.tile_bounds_lon_lat(ul.z, ul.x, ul.y)