Add methods to map locations helper.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -1,11 +1,13 @@
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
<div id="admin-map" class="map" data-map
|
||||
data-latitude="<%= Setting["map.latitude"] %>"
|
||||
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"
|
||||
<div id="admin-map" class="map"
|
||||
data-map
|
||||
data-map-zoom="<%= Setting["map.zoom"] %>"
|
||||
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">
|
||||
|
||||
@@ -1,25 +1,7 @@
|
||||
<%= form.label :map_location, label %>
|
||||
<p class="help-text" id="tag-list-help-text"><%= help %></p>
|
||||
|
||||
<div id="<%= dom_id(map_location)%>" class="map"
|
||||
data-map
|
||||
data-map-zoom="<%= map_location_zoom(map_location) %>"
|
||||
data-map-tiles-attribution-selector="#map-location-attribution"
|
||||
data-map-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png"
|
||||
data-marker-editable="true"
|
||||
data-marker-latitude="<%= map_location_latitude(map_location) %>"
|
||||
data-marker-longitude="<%= map_location_longitude(map_location) %>"
|
||||
data-marker-remove-selector=".location-map-remove-marker-button"
|
||||
data-latitude-input-selector="#<%= map_location_input_id(parent_class, 'latitude') %>"
|
||||
data-longitude-input-selector="#<%= map_location_input_id(parent_class, 'longitude') %>"
|
||||
data-zoom-input-selector="#<%= map_location_input_id(parent_class, 'zoom') %>">
|
||||
</div>
|
||||
|
||||
<div id="map-location-attribution" class="map-attributtion">
|
||||
© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors
|
||||
</div>
|
||||
|
||||
<a class="location-map-remove-marker-button" href="#"><%= remove_marker_label %></a>
|
||||
<%= 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,
|
||||
|
||||
Reference in New Issue
Block a user