From 9f84393f87cfba99baf0a2fd0a2c78af4e497ca9 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Thu, 4 Jul 2024 14:22:42 +0300 Subject: [PATCH] feature: custom map markers --- app/components/avo/index/resource_map_component.rb | 6 ++++-- spec/dummy/app/avo/resources/city.rb | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/components/avo/index/resource_map_component.rb b/app/components/avo/index/resource_map_component.rb index ea2798ddc1..dc3f5c1627 100644 --- a/app/components/avo/index/resource_map_component.rb +++ b/app/components/avo/index/resource_map_component.rb @@ -64,7 +64,7 @@ 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 @@ -72,6 +72,8 @@ def resource_location_markers .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 @@ -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 diff --git a/spec/dummy/app/avo/resources/city.rb b/spec/dummy/app/avo/resources/city.rb index 718ce92c54..1dabb13a65 100644 --- a/spec/dummy/app/avo/resources/city.rb +++ b/spec/dummy/app/avo/resources/city.rb @@ -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