diff --git a/app/components/avo/fields/location_field/show_component.html.erb b/app/components/avo/fields/location_field/show_component.html.erb index acd773d788..e67862e231 100644 --- a/app/components/avo/fields/location_field/show_component.html.erb +++ b/app/components/avo/fields/location_field/show_component.html.erb @@ -1,6 +1,6 @@ <%= field_wrapper **field_wrapper_args do %> <% if field.value_present? %> - <%= js_map [{latitude: field.value[0], longitude: field.value[1]}], id: "location-map", zoom: field.zoom, controls: true %> + <%= js_map [{latitude: field.value[0], longitude: field.value[1]}], id: "location-map", zoom: field.zoom, controls: true, **field.mapkick_options %> <% else %> — <% end %> diff --git a/lib/avo/fields/location_field.rb b/lib/avo/fields/location_field.rb index e92954c1c0..45a492d125 100644 --- a/lib/avo/fields/location_field.rb +++ b/lib/avo/fields/location_field.rb @@ -3,6 +3,7 @@ module Avo module Fields class LocationField < BaseField + attr_reader :mapkick_options attr_reader :stored_as, :zoom def initialize(id, **args, &block) @@ -10,6 +11,7 @@ def initialize(id, **args, &block) super(id, **args, &block) @stored_as = args[:stored_as].present? ? args[:stored_as] : nil # You can pass it an array of db columns [:latitude, :longitude] + @mapkick_options = args[:mapkick_options].presence || {} @zoom = args[:zoom].present? ? args[:zoom].to_i : 15 end diff --git a/spec/dummy/app/avo/resources/city.rb b/spec/dummy/app/avo/resources/city.rb index fe94612476..da9d9dae8c 100644 --- a/spec/dummy/app/avo/resources/city.rb +++ b/spec/dummy/app/avo/resources/city.rb @@ -36,7 +36,14 @@ class Avo::Resources::City < Avo::BaseResource def base_fields field :id, as: :id - field :coordinates, as: :location, stored_as: [:latitude, :longitude] + field :coordinates, + as: :location, + stored_as: [:latitude, :longitude], + mapkick_options: { + style: "mapbox://styles/mapbox/satellite-v9", + controls: true, + markers: {color: "#FFC0CB"} + } field :city_center_area, as: :area, geometry: :polygon,