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_coordinates) ⇒ Object
create a link to a bbox spatial search.
-
#link_to_placename_field(field_value, field, displayvalue = nil) ⇒ Object
create a link to a location name facet value.
-
#link_to_point_search(point_coordinates) ⇒ Object
create a link to a spatial search for a set of point coordinates.
-
#map_facet_field ⇒ Object
return the facet field containing geographic data.
-
#map_facet_values ⇒ Object
return an array of Blacklight::SolrResponse::Facets::FacetItem items.
-
#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 separate from BlacklightMapsHelperBehavior#placename_value so location name display can be easily customized.
-
#render_spatial_search_link(coordinates) ⇒ 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
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 5 def blacklight_map_tag id, = {}, &block default_data = { maxzoom: blacklight_config.view.maps.maxzoom, tileurl: blacklight_config.view.maps.tileurl, mapattribution: blacklight_config.view.maps.mapattribution } = {id: id, data: default_data}.deep_merge() if block_given? content_tag(:div, , &block) else tag(:div, ) end end |
#link_to_bbox_search(bbox_coordinates) ⇒ Object
create a link to a bbox spatial search
26 27 28 29 30 31 32 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 26 def link_to_bbox_search bbox_coordinates coords_for_search = bbox_coordinates.map { |v| v.to_s } link_to(t('blacklight.maps.interactions.bbox_search'), search_catalog_path(spatial_search_type: "bbox", coordinates: "[#{coords_for_search[1]},#{coords_for_search[0]} TO #{coords_for_search[3]},#{coords_for_search[2]}]", view: default_document_index_view_type)) end |
#link_to_placename_field(field_value, field, displayvalue = nil) ⇒ Object
create a link to a location name facet value
35 36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 35 def link_to_placename_field field_value, field, displayvalue = nil if params[:f] && params[:f][field] && params[:f][field].include?(field_value) new_params = params else new_params = search_state.add_facet_params(field, field_value) end new_params[:view] = default_document_index_view_type link_to(displayvalue.presence || field_value, search_catalog_path(new_params.except(:id, :spatial_search_type, :coordinates))) end |
#link_to_point_search(point_coordinates) ⇒ Object
create a link to a spatial search for a set of point coordinates
47 48 49 50 51 52 53 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 47 def link_to_point_search point_coordinates new_params = params.except(:controller, :action, :view, :id, :spatial_search_type, :coordinates) new_params[:spatial_search_type] = "point" new_params[:coordinates] = "#{point_coordinates[1]},#{point_coordinates[0]}" new_params[:view] = default_document_index_view_type link_to(t('blacklight.maps.interactions.point_search'), search_catalog_path(new_params)) end |
#map_facet_field ⇒ Object
return the facet field containing geographic data
56 57 58 59 60 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 56 def map_facet_field blacklight_config.view.maps.facet_mode == "coordinates" ? blacklight_config.view.maps.coordinates_facet_field : blacklight_config.view.maps.geojson_field end |
#map_facet_values ⇒ Object
return an array of Blacklight::SolrResponse::Facets::FacetItem items
63 64 65 66 67 68 69 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 63 def map_facet_values if @response.aggregations[map_facet_field] @response.aggregations[map_facet_field].items else [] end end |
#placename_value(geojson_hash) ⇒ Object
return the placename value to be used as a link
21 22 23 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 21 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
79 80 81 82 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 79 def render_index_mapview 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 separate from BlacklightMapsHelperBehavior#placename_value so location name display can be easily customized
74 75 76 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 74 def render_placename_heading(geojson_hash) geojson_hash[:properties][blacklight_config.view.maps.placename_property.to_sym] end |
#render_spatial_search_link(coordinates) ⇒ Object
determine the type of spatial search to use based on coordinates (bbox or point)
85 86 87 88 89 90 91 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 85 def render_spatial_search_link coordinates if coordinates.length == 4 link_to_bbox_search(coordinates) else link_to_point_search(coordinates) end end |
#serialize_geojson(documents, options = {}) ⇒ Object
pass the document or facet values to BlacklightMaps::GeojsonExport
94 95 96 97 98 99 100 |
# File 'app/helpers/blacklight/blacklight_maps_helper_behavior.rb', line 94 def serialize_geojson(documents, ={}) export = BlacklightMaps::GeojsonExport.new(controller, controller.action_name, documents, ) export.to_geojson end |