Simplify creating a map location from a heading

This commit is contained in:
Javi Martín
2023-03-07 17:47:05 +01:00
parent deb965bcce
commit aa5f5235de
2 changed files with 7 additions and 7 deletions

View File

@@ -181,7 +181,7 @@ module Budgets
end end
def load_map def load_map
@map_location = MapLocation.load_from_heading(@heading) if @heading.present? @map_location = MapLocation.from_heading(@heading) if @heading.present?
end end
end end
end end

View File

@@ -17,11 +17,11 @@ class MapLocation < ApplicationRecord
} }
end end
def self.load_from_heading(heading) def self.from_heading(heading)
map = new new(
map.zoom = Budget::Heading::OSM_DISTRICT_LEVEL_ZOOM zoom: Budget::Heading::OSM_DISTRICT_LEVEL_ZOOM,
map.latitude = heading.latitude.to_f if heading.latitude.present? latitude: (heading.latitude.to_f if heading.latitude.present?),
map.longitude = heading.longitude.to_f if heading.longitude.present? longitude: (heading.longitude.to_f if heading.longitude.present?)
map )
end end
end end