Class: LayersOfLondon::Booth::MapTool::Square
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- LayersOfLondon::Booth::MapTool::Square
- Includes:
- AASM
- Defined in:
- app/models/layers_of_london/booth/map_tool/square.rb
Class Method Summary collapse
Instance Method Summary collapse
- #centroid ⇒ Object
- #editable? ⇒ Boolean
- #north_east ⇒ Object
- #north_west ⇒ Object
- #south_east ⇒ Object
- #south_west ⇒ Object
- #to_geojson(padding: 0) ⇒ Object
- #to_json(padding: 0) ⇒ Object
Class Method Details
.grid_coordinates ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/models/layers_of_london/booth/map_tool/square.rb', line 51 def self.grid_coordinates config = LayersOfLondon::Booth::MapTool.configuration down = (config.squares_x + 1).times.collect do |col| top = config.north_west.endpoint(90,col*config.square_size, units: :meters) bottom = top.endpoint(180, config.squares_y*config.square_size, units: :meters) [ top.to_a.reverse, bottom.to_a.reverse ] end across = (config.squares_y + 1).times.collect do |col| left = config.north_west.endpoint(180,col*config.square_size, units: :meters) right = left.endpoint(90, config.squares_x*config.square_size, units: :meters) [ left.to_a.reverse, right.to_a.reverse ] end down + across end |
Instance Method Details
#centroid ⇒ Object
137 138 139 |
# File 'app/models/layers_of_london/booth/map_tool/square.rb', line 137 def centroid north_west.midpoint_to(south_east) end |
#editable? ⇒ Boolean
141 142 143 |
# File 'app/models/layers_of_london/booth/map_tool/square.rb', line 141 def editable? !aasm_state.in?(["done", "flagged", "verified"]) end |
#north_east ⇒ Object
125 126 127 |
# File 'app/models/layers_of_london/booth/map_tool/square.rb', line 125 def north_east north_west.endpoint(90, square_size, units: :meters) end |
#north_west ⇒ Object
121 122 123 |
# File 'app/models/layers_of_london/booth/map_tool/square.rb', line 121 def north_west Geokit::LatLng.new(north_west_lat, north_west_lng) end |
#south_east ⇒ Object
133 134 135 |
# File 'app/models/layers_of_london/booth/map_tool/square.rb', line 133 def south_east south_west.endpoint(90, square_size, units: :meters) end |
#south_west ⇒ Object
129 130 131 |
# File 'app/models/layers_of_london/booth/map_tool/square.rb', line 129 def south_west north_west.endpoint(180, square_size, units: :meters) end |
#to_geojson(padding: 0) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/models/layers_of_london/booth/map_tool/square.rb', line 83 def to_geojson(padding: 0) distance_diagonally = CMath.sqrt((padding * padding) + (padding * padding)) north_west_padded = padding.zero? ? north_west : north_west.endpoint(315,distance_diagonally, units: :meters) north_east_padded = padding.zero? ? north_east : north_east.endpoint(45,distance_diagonally, units: :meters) south_east_padded = padding.zero? ? south_east : south_east.endpoint(135,distance_diagonally, units: :meters) south_west_padded = padding.zero? ? south_west : south_west.endpoint(225,distance_diagonally, units: :meters) { type: "Feature", geometry: { type: "Polygon", coordinates: [ # [ [ north_west.to_a.reverse, south_west.to_a.reverse, south_east.to_a.reverse, north_east.to_a.reverse, north_west.to_a.reverse ]#, # [ # LayersOfLondon::Booth::MapTool.configuration.north_west.to_a.reverse, # LayersOfLondon::Booth::MapTool.configuration.north_east.to_a.reverse, # LayersOfLondon::Booth::MapTool.configuration.south_east.to_a.reverse, # LayersOfLondon::Booth::MapTool.configuration.south_west.to_a.reverse, # LayersOfLondon::Booth::MapTool.configuration.north_west.to_a.reverse, # ] # ] ] }, properties: { id: id, state: aasm_state, centroid: centroid.to_a.collect {|coord| coord.round(5)} } } end |
#to_json(padding: 0) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'app/models/layers_of_london/booth/map_tool/square.rb', line 74 def to_json(padding: 0) # {id: id, state: {label: aasm_state, description: aasm_state.humanize}, geojson: to_geojson(padding: padding)} # state = {label: aasm_state, description: aasm_state.humanize} state.merge!({user: {id: user.id}}) if aasm_state === "done" {id: id, geojson: to_geojson(padding: padding)}.merge({state: state}) end |