Skip to content

Commit 3dfd9e7

Browse files
authored
Add mapkick_options to location field (#3593)
* Add mapkick options to location field * Delete spec * Fix alignment
1 parent 1ec4e07 commit 3dfd9e7

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

app/components/avo/fields/location_field/show_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%= field_wrapper **field_wrapper_args do %>
22
<% if field.value_present? %>
3-
<%= js_map [{latitude: field.value[0], longitude: field.value[1]}], id: "location-map", zoom: field.zoom, controls: true %>
3+
<%= js_map [{latitude: field.value[0], longitude: field.value[1]}], id: "location-map", zoom: field.zoom, controls: true, **field.mapkick_options %>
44
<% else %>
55
66
<% end %>

lib/avo/fields/location_field.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
module Avo
44
module Fields
55
class LocationField < BaseField
6+
attr_reader :mapkick_options
67
attr_reader :stored_as, :zoom
78

89
def initialize(id, **args, &block)
910
hide_on :index
1011
super(id, **args, &block)
1112

1213
@stored_as = args[:stored_as].present? ? args[:stored_as] : nil # You can pass it an array of db columns [:latitude, :longitude]
14+
@mapkick_options = args[:mapkick_options].presence || {}
1315
@zoom = args[:zoom].present? ? args[:zoom].to_i : 15
1416
end
1517

spec/dummy/app/avo/resources/city.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ class Avo::Resources::City < Avo::BaseResource
3636

3737
def base_fields
3838
field :id, as: :id
39-
field :coordinates, as: :location, stored_as: [:latitude, :longitude]
39+
field :coordinates,
40+
as: :location,
41+
stored_as: [:latitude, :longitude],
42+
mapkick_options: {
43+
style: "mapbox://styles/mapbox/satellite-v9",
44+
controls: true,
45+
markers: {color: "#FFC0CB"}
46+
}
4047
field :city_center_area,
4148
as: :area,
4249
geometry: :polygon,

0 commit comments

Comments
 (0)