Skip to content

Commit

Permalink
add zoom option to maps in sidebar and top (#7078)
Browse files Browse the repository at this point in the history
  • Loading branch information
nstjean authored and jywarren committed Jan 2, 2020
1 parent 28f9dbf commit b701668
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
8 changes: 4 additions & 4 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def insert_extras(body)
end

# we should move this to the Node model:
def render_map(lat, lon)
render partial: 'map/leaflet', locals: { lat: lat, lon: lon, top_map: false }
def render_map(lat, lon, zoom = '')
render partial: 'map/leaflet', locals: { lat: lat, lon: lon, zoom: zoom, top_map: false }
end

def render_top_map(lat, lon)
render partial: 'map/leaflet', locals: { lat: lat, lon: lon, top_map: true }
def render_top_map(lat, lon, zoom = '')
render partial: 'map/leaflet', locals: { lat: lat, lon: lon, zoom: zoom, top_map: true }
end

# we should move this to the Comment model:
Expand Down
13 changes: 3 additions & 10 deletions app/views/map/_leaflet.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%= render :partial => "map/mapDependencies" %>
<% top_map = top_map || false %>
<% zoom = zoom || lat.to_s.length.to_i + 6 %>
<% unique_id = rand(1000) %>
<% if top_map == true %>
Expand All @@ -21,23 +22,15 @@
var map<%= unique_id %> = L.map('top_map' , {
maxBounds: bounds ,
maxBoundsViscosity: 0.75
}).setView([<%= lat %>,<%= lon %>], <%= lat.to_s.length.to_i %> + 6);
}).setView([<%= lat %>,<%= lon %>], <%= zoom %>);
<% else %>
var map<%= unique_id %> = L.map('map<%= unique_id %>' , {
maxBounds: bounds ,
maxBoundsViscosity: 0.75
}).setView([<%= lat %>,<%= lon %>], <%= lat.to_s.length.to_i %> + 6);
}).setView([<%= lat %>,<%= lon %>], <%= zoom %>);
<% end %>

var markers_hash<%= unique_id %> = new Map() ;
var map_lat = <%= lat %> ;
var map_lon = <%= lon %> ;

window.setTimeout(function(){

map<%= unique_id %>.setZoom(<%= lat.to_s.length.to_i %> + 6) ;

}, 3500);

setupLEL(map<%= unique_id %> , 0) ;

Expand Down
4 changes: 2 additions & 2 deletions app/views/sidebar/_related.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
<%= render partial: 'sidebar/notes', locals: { notes: @node.responses, title: I18n.t('sidebar._related.responses_to_note'), node: @node } %>
<% end %>
<% if @node && @node.has_tag("place") && @node.lat && @node.lon %>
<%= render_top_map(@node.lat, @node.lon) %>
<%= render_top_map(@node.lat, @node.lon, @node.zoom) %>
<% elsif @node && @node.lat && @node.lon %>
<%= render_map(@node.lat, @node.lon) %>
<%= render_map(@node.lat, @node.lon, @node.zoom) %>
<% elsif !@node.lat && !@node.lon %>
<div id="map_template" style="position: relative; display: inline-block;">
<img src="https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/0/0/0.png" style="height:69px; width: 263px; position: relative; margin-right: -10px;">
Expand Down

0 comments on commit b701668

Please sign in to comment.