Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mapkick_options to location field #3593

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading