diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 2ef6fea23..aec72b35b 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -996,10 +996,15 @@ table { position: absolute; border-radius: 50%; } + .map-attributtion{ + visibility: visible; + height: auto; + } } .map-marker{ visibility: hidden; } .map-attributtion{ visibility: hidden; + height: 0; } \ No newline at end of file diff --git a/app/helpers/map_locations_helper.rb b/app/helpers/map_locations_helper.rb index 08d16391f..805d5504c 100644 --- a/app/helpers/map_locations_helper.rb +++ b/app/helpers/map_locations_helper.rb @@ -16,4 +16,50 @@ module MapLocationsHelper "#{prefix}_map_location_attributes_#{attribute}" end + def map_location_attribution_id(map_location) + "attribution-#{dom_id(map_location)}" + end + + def map_location_remove_marker_link_id(map_location) + "remove-marker-link-#{dom_id(map_location)}" + end + + def render_map(map_location, parent_class, editable, remove_marker_label) + map = content_tag_for :div, + map_location, + class: "map", + data:{ + map: "", + map_zoom: map_location_zoom(map_location), + map_tiles_attribution_selector: map_location_attribution_id(map_location), + map_tiles_provider: "//{s}.tile.osm.org/{z}/{x}/{y}.png", + marker_editable: editable, + marker_latitude: map_location_latitude(map_location), + marker_longitude: map_location_longitude(map_location), + marker_remove_selector: "##{map_location_remove_marker_link_id(map_location)}", + latitude_input_selector: "##{map_location_input_id(parent_class, 'latitude')}", + longitude_input_selector: "##{map_location_input_id(parent_class, 'longitude')}", + zoom_input_selector: "##{map_location_input_id(parent_class, 'zoom')}" + } + map += map_attributtion(map_location) + map += map_location_remove_marker(map_location, remove_marker_label) if editable + end + + def map_attributtion(map_location, klass = nil) + content = "©#{link_to("OpenStreetMap", "http://osm.org/copyright")} contributors".html_safe + content_tag :div, id: map_location_attribution_id(map_location), class: "map-attributtion #{klass}" do + content + end + end + + def map_location_remove_marker(map_location, text) + content_tag :div, class: "small-12 column text-right" do + content_tag :a, + id: map_location_remove_marker_link_id(map_location), + class: "location-map-remove-marker-button delete" do + text + end + end + end + end \ No newline at end of file diff --git a/app/views/admin/settings/_map_form.html.erb b/app/views/admin/settings/_map_form.html.erb index 53eb3d882..256bcd478 100644 --- a/app/views/admin/settings/_map_form.html.erb +++ b/app/views/admin/settings/_map_form.html.erb @@ -1,11 +1,13 @@
-
" - data-longitude="<%= Setting["map.longitude"] %>" - data-zoom="<%= Setting["map.zoom"] %>" - data-tiles-attribution-selector="#admin-map-attribution" - data-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png" +
" + data-map-tiles-attribution-selector="#admin-map-attribution" + data-map-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png" + data-marker-editable="true" + data-marker-latitude="<%= Setting["map.latitude"] %>" + data-marker-longitude="<%= Setting["map.longitude"] %>" data-latitude-input-selector="#latitude" data-longitude-input-selector="#longitude" data-zoom-input-selector="#zoom"> diff --git a/app/views/map_locations/_form_fields.html.erb b/app/views/map_locations/_form_fields.html.erb index 2b1b3738c..f838d1f98 100644 --- a/app/views/map_locations/_form_fields.html.erb +++ b/app/views/map_locations/_form_fields.html.erb @@ -1,25 +1,7 @@ <%= form.label :map_location, label %>

<%= help %>

-
-
- -
- © OpenStreetMap contributors -
- -<%= remove_marker_label %> +<%= render_map(map_location, parent_class, true, remove_marker_label) %> <%= form.fields_for :map_location, map_location do |m_l_fields| %> <%= m_l_fields.hidden_field :latitude, @@ -27,7 +9,7 @@ id: map_location_input_id(parent_class, 'latitude') %> <%= m_l_fields.hidden_field :longitude, value: map_location.longitude, - id: map_location_input_id(parent_class, 'longitude') %> + id: map_location_input_id(parent_class, 'longitude') %> <%= m_l_fields.hidden_field :zoom, value: map_location.zoom, id: map_location_input_id(parent_class, 'zoom') %>