class BlacklightMaps::Geometry::BoundingBox

This class contains Bounding Box objects and methods for interacting with them.

Public Class Methods

from_lon_lat_string(points) click to toggle source

Creates a new bounding box from from a string of points “-100 -50 100 50” (south west north east)

# File lib/blacklight/maps/geometry.rb, line 42
def self.from_lon_lat_string(points)
  new(points.split(' '))
end
from_wkt_envelope(envelope) click to toggle source

Creates a new bounding box from from a Solr WKT Envelope string “ENVELOPE(34.26, 35.89, 33.33, 29.47)” (minX, maxX, maxY, minY)

# File lib/blacklight/maps/geometry.rb, line 48
def self.from_wkt_envelope(envelope)
  coords = envelope.gsub(/[[A-Z]\(\)]/, '')&.split(', ')
  new([coords[0], coords[3], coords[1], coords[2]])
end
new(points) click to toggle source

points is an array containing longitude and latitude values which relate to the southwest and northeast points of a bounding box

west, south, east, north

([minX, minY, maxX, maxY]).

# File lib/blacklight/maps/geometry.rb, line 12
def initialize(points)
  @west = points[0].to_f
  @south = points[1].to_f
  @east = points[2].to_f
  @north = points[3].to_f
end

Public Instance Methods

find_center() click to toggle source

Returns an array [lng, lat] which is the centerpoint of a BoundingBox.

# File lib/blacklight/maps/geometry.rb, line 32
def find_center
  center = []
  center[0] = (@west + @east) / 2
  center[1] = (@south + @north) / 2
  center[0] -= 180 if @west > @east # handle bboxes that cross the dateline
  center
end
geojson_geometry_array() click to toggle source
# File lib/blacklight/maps/geometry.rb, line 19
def geojson_geometry_array
  [
    [
      [@west, @south],
      [@east, @south],
      [@east, @north],
      [@west, @north],
      [@west, @south]
    ]
  ]
end
to_a() click to toggle source
# File lib/blacklight/maps/geometry.rb, line 53
def to_a
  [@west, @south, @east, @north]
end