Module: Blacklight::BlacklightMapsHelperBehavior
- Included in:
- BlacklightMapsHelper
- Defined in:
- app/helpers/blacklight/blacklight_maps_helper_behavior.rb
Instance Method Summary collapse
- #blacklight_map_tag(id, tag_options = {}, &block) ⇒ Object
-
#link_to_bbox_search(bbox) ⇒ Object
create a link to a bbox spatial search.
-
#link_to_placename_field(field_value, field, display_value = nil) ⇒ Object
create a link to a location name facet value.
-
#link_to_point_search(point_coords) ⇒ Object
create a link to a spatial search for a set of point coordinates.
-
#placename_value(geojson_hash) ⇒ Object
return the placename value to be used as a link.
-
#render_index_mapview ⇒ Object
render the map for #index and #map views.
-
#render_placename_heading(geojson_hash) ⇒ Object
render the location name for the Leaflet popup.
-
#render_spatial_search_link(coords) ⇒ Object
determine the type of spatial search to use based on coordinates (bbox or point).
-
#serialize_geojson(documents, options = {}) ⇒ Object
pass the document or facet values to BlacklightMaps::GeojsonExport.
Instance Method Details
#blacklight_map_tag(id, tag_options = {}, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 7 def blacklight_map_tag(id, = {}, &block) maps_config = blacklight_config.view.maps default_data = { maxzoom: maps_config.maxzoom, tileurl: maps_config.tileurl, mapattribution: maps_config.mapattribution } = { id: id, data: default_data }.deep_merge() block_given? ? content_tag(:div, , &block) : tag.div(**) end |
#link_to_bbox_search(bbox) ⇒ Object
create a link to a bbox spatial search
26 27 28 29 30 31 32 33 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 26 def link_to_bbox_search(bbox) bbox_coords = bbox.map(&:to_s) bbox_search_coords = "[#{bbox_coords[1]},#{bbox_coords[0]} TO #{bbox_coords[3]},#{bbox_coords[2]}]" link_to(t('blacklight.maps.interactions.bbox_search'), search_catalog_path(spatial_search_type: 'bbox', coordinates: bbox_search_coords, view: default_document_index_view_type)) end |
#link_to_placename_field(field_value, field, display_value = nil) ⇒ Object
create a link to a location name facet value
39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 39 def link_to_placename_field(field_value, field, display_value = nil) new_params = if params[:f] && params[:f][field]&.include?(field_value) search_state.params else search_state.add_facet_params(field, field_value) end new_params[:view] = default_document_index_view_type new_params.except!(:id, :spatial_search_type, :coordinates, :controller, :action) link_to(display_value.presence || field_value, search_catalog_path(new_params)) end |
#link_to_point_search(point_coords) ⇒ Object
create a link to a spatial search for a set of point coordinates
52 53 54 55 56 57 58 59 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 52 def link_to_point_search(point_coords) new_params = params.except(:controller, :action, :view, :id, :spatial_search_type, :coordinates) new_params[:spatial_search_type] = 'point' new_params[:coordinates] = "#{point_coords[1]},#{point_coords[0]}" new_params[:view] = default_document_index_view_type new_params.permit! link_to(t('blacklight.maps.interactions.point_search'), search_catalog_path(new_params)) end |
#placename_value(geojson_hash) ⇒ Object
return the placename value to be used as a link
20 21 22 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 20 def placename_value(geojson_hash) geojson_hash[:properties][blacklight_config.view.maps.placename_property.to_sym] end |
#render_index_mapview ⇒ Object
render the map for #index and #map views
68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 68 def render_index_mapview maps_config = blacklight_config.view.maps map_facet_field = if maps_config.facet_mode == 'coordinates' maps_config.coordinates_facet_field else maps_config.geojson_field end map_facet_values = @response.aggregations[map_facet_field]&.items || [] render partial: 'catalog/index_mapview', locals: { geojson_features: serialize_geojson(map_facet_values) } end |
#render_placename_heading(geojson_hash) ⇒ Object
render the location name for the Leaflet popup
63 64 65 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 63 def render_placename_heading(geojson_hash) geojson_hash[:properties][blacklight_config.view.maps.placename_property.to_sym] end |
#render_spatial_search_link(coords) ⇒ Object
determine the type of spatial search to use based on coordinates (bbox or point)
82 83 84 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 82 def render_spatial_search_link(coords) coords.length == 4 ? link_to_bbox_search(coords) : link_to_point_search(coords) end |
#serialize_geojson(documents, options = {}) ⇒ Object
pass the document or facet values to BlacklightMaps::GeojsonExport
88 89 90 91 92 93 94 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 88 def serialize_geojson(documents, = {}) export = BlacklightMaps::GeojsonExport.new(controller, action_name.to_sym, documents, ) export.to_geojson end |