Skip to content

Commit

Permalink
Fix map on profile and add check for zoom tag (publiclab#7089)
Browse files Browse the repository at this point in the history
* add zoom to profile map, fix error on map so it shows correctly

* clean up code
  • Loading branch information
nstjean authored and Vinit Shahdeo committed Feb 1, 2020
1 parent bfc645f commit d8719dd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,11 @@ def profile
@count_activities_attempted = Tag.tagged_nodes_by_author("replication:*", @profile_user).count
@map_lat = nil
@map_lon = nil
@map_zoom = nil
if @profile_user.has_power_tag("lat") && @profile_user.has_power_tag("lon")
@map_lat = @profile_user.get_value_of_power_tag("lat").to_f
@map_lon = @profile_user.get_value_of_power_tag("lon").to_f
@map_zoom = @profile_user.get_value_of_power_tag("zoom").to_i if @profile_user.has_power_tag("zoom")
@map_blurred = @profile_user.has_tag('blurred:true')
end

Expand Down
35 changes: 23 additions & 12 deletions app/views/map/_userLeaflet.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,39 @@
<% user = user || @user # allow overriding w/ local variable %>
<% if haslocation == true %>
<% if haslocation == true %>

<style>
#map_leaflet{ height:300px; width:100%; margin: auto; position: relative;}
</style>
<div class="leaflet-map" id="map_leaflet"></div>
<script>
var bounds = new L.LatLngBounds(new L.LatLng(84.67351257, -172.96875), new L.LatLng(-54.36775852, 178.59375));
var map_lat = <%= @map_lat %> ;
var map_lon = <%= @map_lon %> ;
var map = setupLeafletMap() ;
var layerGroup = L.layerGroup() ;
var map_lat = <%= lat %>;
var map_lon = <%= lon %>;
var zoom = <%= zoom || lat.to_s.length.to_i + 6 %>;
map.setView([map_lat,map_lon], 2);
setupFullScreen(map , map_lat , map_lon) ;
setupLEL(map , 1) ;
// var hash = new L.Hash(map);
var map = L.map('map_leaflet', {
maxBounds: bounds,
maxBoundsViscosity: 0.75
}).setView([<%= lat %>, <%= lon %>], zoom);
setupLEL(map, 0);
var markers_hash = new Map();
var layerGroup = L.layerGroup();
var hash = new L.Hash(map);
<% if !(@map_blurred == true) %>
var default_Icon =new PLmarker_default() ;
L.marker([<%= @map_lat %>, <%= @map_lon %>] , {icon: default_Icon}).addTo(map).bindPopup("<a href='https://publiclab.org/profile/<%= user.username %>'><%= user.username %> </a>");
var default_Icon =new PLmarker_default();
L.marker([<%= lat %>, <%= lon %>] , {icon: default_Icon}).addTo(map).bindPopup("<a href='https://publiclab.org/profile/<%= user.username %>'><%= user.username %></a>");
<% end %>
</script>
<% else %>
<div id="map_template" style="position: relative; width: 100%; display: inline-block;">
<img src="https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/0/0/0.png" style="height:300px; width: 100%; margin: 0; position: relative; margin-right: -10px;">
<button type='button' class='btn btn-default btn-lg' onclick='addLocation()' style="position: absolute; position: absolute;top: 41% ; left: 15% ;"> <strong> Share your Location </strong> </button>
Expand All @@ -35,4 +45,5 @@
$('.blurred-location-input').click() ;
}
</script>
<% end %>
2 changes: 1 addition & 1 deletion app/views/users/profile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="col-md-7 order-last order-md-first">

<% if !@map_lat.nil? && !@map_lon.nil? %>
<%= render :partial => "map/userLeaflet" , locals: { haslocation: true, user: @profile_user } %>
<%= render :partial => "map/userLeaflet" , locals: { lat: @map_lat, lon: @map_lon, zoom: @map_zoom, haslocation: true, user: @profile_user } %>
<% elsif !current_user.nil? && current_user.id == @profile_user.id %>
<%= render :partial => "map/userLeaflet" , locals: { haslocation: false, user: @profile_user } %>
<% end %>
Expand Down

0 comments on commit d8719dd

Please sign in to comment.