Class: MapTool::GridGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/map_tool/grid_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_squaresObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/map_tool/grid_generator.rb', line 4

def create_squares
  config = LayersOfLondon::Booth::MapTool.configuration

  squares_y = config.squares_y
  squares_x = config.squares_x
  north_west = config.north_west
  row_north_west = north_west

  squares_y.times do |row|
    puts "Creating row #{row}"
      square_north_west = row_north_west
    square = nil
    squares_x.times do |col|
      puts "\tCreating column #{col}"
      square = LayersOfLondon::Booth::MapTool::Square.create(north_west_lat: square_north_west.lat, north_west_lng: square_north_west.lng, row: row, col: col)
      # get the next square's northwest corner by moving east (90ยบ) by the number of columns from the row's northwest
      square_north_west = square.north_east
    end
    # increment row_north_west by square_size, southwards, ready for the next iteration
    row_north_west = LayersOfLondon::Booth::MapTool::Square.find_by(row: row, col: 0).south_west
  end

end