Skip to content

Commit

Permalink
Add default location to /post (publiclab#6957)
Browse files Browse the repository at this point in the history
* update yarn

* add default location to post form

* keep default lat/lon zoom level by calculating precision

* display zoom or calculate and save zoom

* use LBL's getZoomFromCoordinates for zoom and style location button

* fix codeclimate error with parentheses

* fix codeclimate error

* make map slider in modal update when map is zoomed

* fix merge
  • Loading branch information
nstjean authored and Tlazypanda committed Jan 14, 2020
1 parent 541f405 commit af486b7
Show file tree
Hide file tree
Showing 5 changed files with 1,387 additions and 788 deletions.
11 changes: 11 additions & 0 deletions app/controllers/editor_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ def rich
x.include? "zoom:" and (@zoom = x.split(':')[1])
end
end

# if user has a location, set the @lat and @lon
if @lat.nil? && @lon.nil? && current_user&.has_power_tag("lat") && current_user&.has_power_tag("lon")
@lat = current_user.get_value_of_power_tag("lat").to_f
@lon = current_user.get_value_of_power_tag("lon").to_f
@map_blurred = current_user.has_tag('location:blurred')
if @zoom.nil? && current_user&.has_power_tag("zoom")
@zoom = current_user.get_value_of_power_tag("zoom")
end
end

template if params[:n] && !params[:body] # use another node body as a template
image if params[:i]
end
Expand Down
43 changes: 42 additions & 1 deletion app/views/editor/rich.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
#coord_button {
text-decoration: underline;
}

button i.fa-map-marker {
color: #c40;
}
button:hover i.fa-map-marker {
color: inherit;
}
</style>

<div class="pl-editor">
Expand Down Expand Up @@ -136,6 +143,8 @@
class="leaflet-map"
style="width: 100% ; height: 300px; margin-bottom:8px;">
</div>


</div>

<div class="col-lg-6">
Expand Down Expand Up @@ -208,7 +217,6 @@
</div>
<!-- Map Module end -->


<!-- body module -->
<div class="ple-module-body ple-module row">

Expand Down Expand Up @@ -420,12 +428,44 @@
new L.LatLng(-90, 180)
);
editor.mapModule.blurredLocation.map.setMaxBounds(bounds);

<% if @lat and @lon %>
<% if @zoom %>
editor.mapModule.blurredLocation.setZoom(<%= @zoom %>);
<% else %>
let zoom = editor.mapModule.blurredLocation.getZoomFromCoordinates(<%= @lat %>, <%= @lon %>);
addTag('zoom:'+zoom, '/profile/tags/create/<%= current_user.uid %>');
editor.mapModule.blurredLocation.setZoom(zoom);
<% end %>
<% end %>

$('#coord_button').click((event) => {
event.preventDefault();
$('#coord_input').toggle();
});
$("#coord_input").hide();

$(function() {
var target = document.querySelector('#map_content');
var observer = new MutationObserver(function(mutations) {
setLocationButtonText();
});
observer.observe(target, {
attributes: true
});
});

function setLocationButtonText() {
if ($('#map_content').is(':hidden')) {
$('#location_button').html('<i class="fa fa-map-marker" aria-hidden="true"></i> Add a location');
} else {
$('#location_button').html('<i class="fa fa-trash"></i> Remove location');
}
}
setLocationButtonText();

$("#obscureLocation").prop('checked', <%= @map_blurred %>);
editor.mapModule.blurredLocation.setBlurred(<%= @map_blurred %>);

// upload via posting "posted_main_image"
function dataURItoBlob(dataURI) {
Expand Down Expand Up @@ -472,3 +512,4 @@
}

</script>

21 changes: 13 additions & 8 deletions app/views/locations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,19 @@

blurredLocation.map.setMaxBounds(bounds);

var changeZoom = function() {
var zoom = slider.getValue();
blurredLocation.map.setZoom(zoom);
}

var slider = $('#ex1').slider()
.on('slide', changeZoom)
.data('slider');
var changeZoom = function() {
var zoom = slider.getValue();
blurredLocation.map.setZoom(zoom);
}

var slider = $('#ex1').slider()
.on('slide', changeZoom)
.data('slider');

blurredLocation.map.on('zoomend', function() {
let zoom = blurredLocation.map.getZoom();
$('#ex1').slider('setValue', zoom);
})

})();

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@
"jquery-validation": "^1.19.1",
"jsdiff": "components/jsdiff#~3.4.0",
"junction": "theleagueof/junction#*",
"urlhash": "^0.1.3",
"leaflet": "^1.6.0",
"leaflet-environmental-layers": "^2.0.6",
"leaflet-blurred-location": "^1.5.1",
"leaflet-environmental-layers": "^2.0.6",
"leaflet-hash": "^0.2.1",
"leaflet-spin": "1.1.0",
"leaflet.fullscreen": "1.6.0",
Expand All @@ -58,6 +57,7 @@
"simple-data-grapher": "^2.0.0",
"typeahead.js": "^0.11.1",
"typeahead.js-browserify": "Javier-Rotelli/typeahead.js-browserify#~1.0.7",
"urlhash": "^0.1.3",
"woofmark": "~4.2.0"
},
"devDependencies": {},
Expand Down
Loading

0 comments on commit af486b7

Please sign in to comment.