Class: BlacklightMaps::Geometry::BoundingBox

Inherits:
Object
  • Object
show all
Defined in:
lib/blacklight/maps/geometry.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(points) ⇒ BoundingBox

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

([swlng, swlat, nelng, nelat]).


13
14
15
16
17
18
# File 'lib/blacklight/maps/geometry.rb', line 13

def initialize(points)
  @west = points[0].to_f
  @south = points[1].to_f
  @east = points[2].to_f
  @north = points[3].to_f
end

Class Method Details

.from_lon_lat_string(points) ⇒ Object

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


34
35
36
# File 'lib/blacklight/maps/geometry.rb', line 34

def self.from_lon_lat_string(points)
  new(points.split(' '))
end

Instance Method Details

#find_centerObject

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


21
22
23
24
25
26
27
28
29
30
# File 'lib/blacklight/maps/geometry.rb', line 21

def find_center
  center = []
  center[0] = (@west + @east) / 2
  center[1] = (@south + @north) / 2

  # Handle bounding boxes that cross the dateline
  center[0] -= 180 if @west > @east

  center
end