Skip to content

Commit

Permalink
Clamp query bounding boxes to the whole world if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
trasch committed Oct 16, 2023
1 parent fd88214 commit baec5b9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Sources/MVTTools/VectorTileQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extension VectorTile {
-> [QueryResult]
{
let queryLayerNames: [String]
if let layerName = layerName {
if let layerName {
queryLayerNames = [layerName]
}
else {
Expand Down Expand Up @@ -109,7 +109,7 @@ extension VectorTile {
-> [QueryResult]
{
let queryLayerNames: [String]
if let layerName = layerName {
if let layerName {
queryLayerNames = [layerName]
}
else {
Expand Down Expand Up @@ -174,7 +174,7 @@ extension VectorTile {
}

let queryLayerNames: [String]
if let layerName = layerName {
if let layerName {
queryLayerNames = [layerName]
}
else {
Expand Down Expand Up @@ -260,14 +260,15 @@ extension VectorTile {
x: coordinate.longitude + tolerance,
y: coordinate.latitude + tolerance,
projection: projection))
.clamped()

case .epsg4326:
// Length of one minute at this latitude
let oneDegreeLatitudeDistanceInMeters = 111_000.0
let oneDegreeLongitudeDistanceInMeters: Double = fabs(cos(coordinate.longitude * Double.pi / 180.0) * oneDegreeLatitudeDistanceInMeters)
let oneDegreeLongitudeDistanceInMeters = fabs(cos(coordinate.longitude * Double.pi / 180.0) * oneDegreeLatitudeDistanceInMeters)

let longitudeDistance: Double = (tolerance / oneDegreeLongitudeDistanceInMeters)
let latitudeDistance: Double = (tolerance / oneDegreeLatitudeDistanceInMeters)
let longitudeDistance = (tolerance / oneDegreeLongitudeDistanceInMeters)
let latitudeDistance = (tolerance / oneDegreeLatitudeDistanceInMeters)

return BoundingBox(
southWest: Coordinate3D(
Expand All @@ -276,6 +277,7 @@ extension VectorTile {
northEast: Coordinate3D(
latitude: coordinate.latitude + latitudeDistance,
longitude: coordinate.longitude + longitudeDistance))
.clamped()
}
}

Expand Down

0 comments on commit baec5b9

Please sign in to comment.