Commit 18d9d6b3 authored by Alexandre Friquet's avatar Alexandre Friquet

More precise fitbounds for map: refs #12.

parent 89039023
......@@ -8,13 +8,11 @@ module MapHelper
when 1
map(markers: markers, center: {latlng: markers.first[:latlng], zoom: 13})
else
update_icon_settings(markers)
lats = markers.collect { |m| m[:latlng][0] }
longs = markers.collect { |m| m[:latlng][1] }
bottom_limit = markers.select { |m| m[:latlng][0] == lats.min}.first[:latlng]
top_marker = markers.select { |m| m[:latlng][0] == lats.max}.first[:latlng]
top_limit = [top_marker[0]+0.3, top_marker[1]]
fitbounds = [bottom_limit,top_limit]
lower_marker, upper_marker = markers.minmax_by { |m| m[:latlng][0] }
western_marker, eastern_marker = markers.minmax_by { |m| m[:latlng][1] }
bottom_left_limit = [lower_marker[:latlng][0], western_marker[:latlng][1]]
top_right_limit = [upper_marker[:latlng][0], eastern_marker[:latlng][1]]
fitbounds = [bottom_left_limit, top_right_limit]
map(markers: markers, fitbounds: fitbounds)
end
content_tag :div, id: 'map_container' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment