Class: Map::PolygonService

Inherits:
Object
  • Object
show all
Defined in:
lib/map/polygon_service.rb

Constant Summary collapse

CACHE_EXPIRES =
1.hours

Instance Method Summary collapse

Constructor Details

#initialize(glebas = nil) ⇒ PolygonService

Returns a new instance of PolygonService.



6
7
8
# File 'lib/map/polygon_service.rb', line 6

def initialize(glebas = nil)
  @glebas = glebas
end

Instance Method Details

#glebasObject



21
22
23
# File 'lib/map/polygon_service.rb', line 21

def glebas
  @glebas ||= Gleba.select(:cd_gleba, :cd_propriedade, :arquivo_kml, :descricao).active.with_kml
end

#inside_any_gleba?(point) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
# File 'lib/map/polygon_service.rb', line 10

def inside_any_gleba?(point)
  glebas.each do |gleba|
    coords = polygon(gleba)
    coords.each do |coord|
      return gleba if point_inside?(point, coord)
    end
  end

  nil
end

#inside_polygons?(point, polygons) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/map/polygon_service.rb', line 25

def inside_polygons?(point, polygons)
  polygons.any? do |polygon|
    point_inside?(point, polygon)
  end
end