Class: Geoblacklight::LocationLeafletMapComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/geoblacklight/location_leaflet_map_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(id: "leaflet-viewer", map_geometry: config.homepage_map_geom, classes: "", page: nil, geosearch: nil) ⇒ LocationLeafletMapComponent

Returns a new instance of LocationLeafletMapComponent.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/components/geoblacklight/location_leaflet_map_component.rb', line 5

def initialize(
  id: "leaflet-viewer",
  map_geometry: config.homepage_map_geom,
  classes: "",
  page: nil,
  geosearch: nil
)
  @id = id
  @classes = classes
  @map_geometry = map_geometry if map_geometry != "null"
  @page = page
  @geosearch = geosearch
  super()
end

Instance Method Details

#configObject



34
35
36
# File 'app/components/geoblacklight/location_leaflet_map_component.rb', line 34

def config
  Geoblacklight.configuration
end

#data_permanentObject

We don’t want turbo-permanent on the home page.



39
40
41
42
# File 'app/components/geoblacklight/location_leaflet_map_component.rb', line 39

def data_permanent
  return {} unless helpers.has_search_parameters?
  {turbo_permanent: true}
end

#leaflet_optionsObject

Add top-level geosearch control to leaflet options if configured



28
29
30
31
32
# File 'app/components/geoblacklight/location_leaflet_map_component.rb', line 28

def leaflet_options
  config.leaflet_options.deep_dup.tap do |options|
    options.controls = {"Geosearch" => @geosearch} if @geosearch
  end
end

#leaflet_viewer_data_attributesObject



50
51
52
53
54
55
56
57
58
59
60
# File 'app/components/geoblacklight/location_leaflet_map_component.rb', line 50

def leaflet_viewer_data_attributes
  {
    "controller" => "leaflet-viewer",
    "leaflet-viewer-basemap-value" => helpers.geoblacklight_basemap,
    "leaflet-viewer-map-geom-value" => search_bbox || @map_geometry,
    "leaflet-viewer-data-map-value" => @data_map,
    "leaflet-viewer-page-value" => params[:action]&.upcase,
    "leaflet-viewer-options-value" => leaflet_options.to_h,
    "leaflet-viewer-catalog-base-url-value" => (helpers.search_action_path if @geosearch)
  }.compact
end

#search_bboxObject



20
21
22
23
24
25
# File 'app/components/geoblacklight/location_leaflet_map_component.rb', line 20

def search_bbox
  return unless params[:bbox].present?

  bbox = Geoblacklight::BoundingBox.new(*params[:bbox].split(" "))
  bbox.to_geojson
end

#viewer_tagObject



44
45
46
47
48
# File 'app/components/geoblacklight/location_leaflet_map_component.rb', line 44

def viewer_tag
  tag.div(id: @id,
    class: @classes,
    data: data_permanent.merge(leaflet_viewer_data_attributes))
end