Simplify code setting marker data in maps

We were probably setting them separately to avoid having blank data
attributes in the HTML. However, when a data attribute is `nil`, Rails
doesn't write it in the HTML in the first place.
This commit is contained in:
Javi Martín
2023-03-07 18:45:15 +01:00
parent e00aa807b9
commit 84fff2e9fb

View File

@@ -44,7 +44,7 @@ class Shared::MapLocationComponent < ApplicationComponent
end
def data
options = {
{
map: "",
map_center_latitude: latitude,
map_center_longitude: longitude,
@@ -56,10 +56,9 @@ class Shared::MapLocationComponent < ApplicationComponent
latitude_input_selector: "##{map_location_input_id(parent_class, "latitude")}",
longitude_input_selector: "##{map_location_input_id(parent_class, "longitude")}",
zoom_input_selector: "##{map_location_input_id(parent_class, "zoom")}",
marker_investments_coordinates: investments_coordinates
marker_investments_coordinates: investments_coordinates,
marker_latitude: map_location.latitude.presence,
marker_longitude: map_location.longitude.presence
}
options[:marker_latitude] = map_location.latitude if map_location.latitude.present?
options[:marker_longitude] = map_location.longitude if map_location.longitude.present?
options
end
end