-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#369 monitor vector tiles poc - improve tile calculation
- Loading branch information
Showing
12 changed files
with
292 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
server/src/main/scala/kpn/server/analyzer/engine/tile/LineSegmentTileCalculator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package kpn.server.analyzer.engine.tile | ||
|
||
import kpn.server.analyzer.engine.tiles.domain.Tile | ||
import org.locationtech.jts.geom.LineSegment | ||
|
||
trait LineSegmentTileCalculator { | ||
|
||
def tiles(z: Int, lineSegments: Seq[LineSegment]): Seq[Tile] | ||
} |
52 changes: 52 additions & 0 deletions
52
server/src/main/scala/kpn/server/analyzer/engine/tile/LineSegmentTileCalculatorImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package kpn.server.analyzer.engine.tile | ||
|
||
import kpn.server.analyzer.engine.tiles.domain.Tile | ||
import kpn.server.analyzer.engine.tiles.domain.TileUtil | ||
import org.locationtech.jts.geom.Coordinate | ||
import org.locationtech.jts.geom.LineSegment | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class LineSegmentTileCalculatorImpl(tileCalculator: TileCalculator) extends LineSegmentTileCalculator { | ||
|
||
override def tiles(z: Int, lineSegments: Seq[LineSegment]): Seq[Tile] = { | ||
|
||
val tileQueue = scala.collection.mutable.Queue[Tile]() | ||
val foundTiles = scala.collection.mutable.Set[Tile]() | ||
|
||
val tiles = lineSegments.flatMap(ls => Seq(ls.p0, ls.p1)).map { p: Coordinate => | ||
tileCalculator.tileContainingWorldCoordinate(z, p.x, p.y) | ||
}.toSet | ||
|
||
foundTiles ++= tiles.toSeq | ||
tileQueue ++= tiles | ||
|
||
while (tileQueue.nonEmpty) { | ||
val tile = tileQueue.dequeue() | ||
explore(tileQueue, foundTiles, lineSegments, tile, TileUtil.left(tile), -1, 0) | ||
explore(tileQueue, foundTiles, lineSegments, tile, TileUtil.right(tile), 1, 0) | ||
explore(tileQueue, foundTiles, lineSegments, tile, TileUtil.top(tile), 0, 1) | ||
explore(tileQueue, foundTiles, lineSegments, tile, TileUtil.bottom(tile), 0, -1) | ||
} | ||
foundTiles.toSeq | ||
} | ||
|
||
private def explore( | ||
tileQueue: scala.collection.mutable.Queue[Tile], | ||
foundTiles: scala.collection.mutable.Set[Tile], | ||
lineSegments: Seq[LineSegment], | ||
tile: Tile, | ||
side: LineSegment, | ||
xDelta: Int, | ||
yDelta: Int | ||
): Unit = { | ||
val adjecentTile = tileCalculator.tileXY(tile.z, tile.x + xDelta, tile.y + yDelta) | ||
if (!foundTiles.map(_.name).contains(adjecentTile.name)) { | ||
if (lineSegments.exists(_.intersection(side) != null)) { | ||
tileQueue += adjecentTile | ||
foundTiles += adjecentTile | ||
() | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
server/src/main/scala/kpn/server/analyzer/engine/tile/TileCalculator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package kpn.server.analyzer.engine.tile | ||
|
||
import kpn.server.analyzer.engine.tiles.domain.Tile | ||
|
||
trait TileCalculator { | ||
|
||
def tileContainingWorldCoordinate(z: Int, worldX: Double, worldY: Double): Tile | ||
|
||
def tileXY(z: Int, x: Int, y: Int): Tile | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
server/src/main/scala/kpn/server/analyzer/engine/tile/TileCalculatorImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package kpn.server.analyzer.engine.tile | ||
|
||
import kpn.server.analyzer.engine.tiles.domain.Tile | ||
import kpn.server.analyzer.engine.tiles.domain.TileCache | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class TileCalculatorImpl extends TileCalculator { | ||
|
||
private val cache = new TileCache() | ||
|
||
def tileContainingWorldCoordinate(z: Int, worldX: Double, worldY: Double): Tile = { | ||
cache.tileContainingWorldCoordinate(z, worldX, worldY) | ||
} | ||
|
||
def tileXY(z: Int, x: Int, y: Int): Tile = { | ||
cache(z, x, y) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
server/src/main/scala/kpn/server/analyzer/engine/tiles/domain/NewTile.scala
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.