Skip to content

Commit

Permalink
feature: custom map markers
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Jul 4, 2024
1 parent 70dd05f commit 9f84393
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/components/avo/index/resource_map_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ def resource_location_markers
# If we have no proc and no default location method, don't try to create markers
return [] unless resource_mappable?

resources
records_markers = resources
.map do |resource|
Avo::ExecutionContext.new(target: marker_proc, record: resource.record).handle
end
.compact
.filter do |coordinates|
coordinates[:latitude].present? && coordinates[:longitude].present?
end

records_markers + Avo::ExecutionContext.new(target: map_options[:custom_markers]).handle
end

def resource_mapkick_options
Expand Down Expand Up @@ -102,7 +104,7 @@ def marker_proc
end

def resource_mappable?
map_options[:record_marker].present? || @resources.first.record.respond_to?(:coordinates)
map_options[:record_marker].present? || map_options[:custom_markers].present? || @resources.first.record.respond_to?(:coordinates)
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions spec/dummy/app/avo/resources/city.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ class Avo::Resources::City < Avo::BaseResource
tooltip: record.name
}
},
custom_markers: -> do
[
{
latitude: params[:lat] || 37.780411,
longitude: params[:long] || -25.497047,
label: "Açores",
tooltip: "São Miguel",
color: "#0F0"
}
]
end,
table: {
visible: true,
layout: :bottom
Expand Down

0 comments on commit 9f84393

Please sign in to comment.