Skip to content

Commit

Permalink
Add mapkick_options to location field (#3593)
Browse files Browse the repository at this point in the history
* Add mapkick options to location field

* Delete spec

* Fix alignment
  • Loading branch information
Nevelito authored Jan 20, 2025
1 parent 1ec4e07 commit 3dfd9e7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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 %>
Expand Down
2 changes: 2 additions & 0 deletions lib/avo/fields/location_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
module Avo
module Fields
class LocationField < BaseField
attr_reader :mapkick_options
attr_reader :stored_as, :zoom

def initialize(id, **args, &block)
hide_on :index
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

Expand Down
9 changes: 8 additions & 1 deletion spec/dummy/app/avo/resources/city.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3dfd9e7

Please sign in to comment.