fix map rendering for budget headings
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
class Budget
|
||||
class Heading < ActiveRecord::Base
|
||||
OSM_DISTRICT_LEVEL_ZOOM = 12.freeze
|
||||
|
||||
include Sluggable
|
||||
|
||||
belongs_to :group
|
||||
@@ -12,9 +14,9 @@ class Budget
|
||||
validates :price, presence: true
|
||||
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
|
||||
validates :population, numericality: { greater_than: 0 }, allow_nil: true
|
||||
validates :latitude, length: { maximum: 22, minimum: 1 }, presence: true, \
|
||||
validates :latitude, length: { maximum: 22 }, allow_blank: true, \
|
||||
format: /\A(-|\+)?([1-8]?\d(?:\.\d{1,})?|90(?:\.0{1,6})?)\z/
|
||||
validates :longitude, length: { maximum: 22, minimum: 1}, presence: true, \
|
||||
validates :longitude, length: { maximum: 22 }, allow_blank: true, \
|
||||
format: /\A(-|\+)?((?:1[0-7]|[1-9])?\d(?:\.\d{1,})?|180(?:\.0{1,})?)\z/
|
||||
|
||||
delegate :budget, :budget_id, to: :group, allow_nil: true
|
||||
|
||||
@@ -18,4 +18,12 @@ class MapLocation < ActiveRecord::Base
|
||||
}
|
||||
end
|
||||
|
||||
def self.load_from_heading(heading)
|
||||
map = new
|
||||
map.zoom = Budget::Heading::OSM_DISTRICT_LEVEL_ZOOM
|
||||
map.latitude = heading.latitude.to_f if heading.latitude.present?
|
||||
map.longitude = heading.longitude.to_f if heading.latitude.present?
|
||||
map
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user