-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create /map/ route for wiki pages #7061
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d1a6590
add route for map/wiki/:id and display wiki location
nstjean 8ceccca
add error messages for no location, no wiki
nstjean c276774
fix codeclimate error
nstjean e6ef6be
display url hash on page load
nstjean 578597e
Add buttons on wiki pages to link to map or prompt location entry
nstjean 8c0cd7b
add redirect from /maps/ to /map/
nstjean 97bfba0
change url hash format to #zoom/lat/lon
nstjean a3798d9
fix codeclimate error
nstjean 156f243
change button on wiki and page to new hash format
nstjean 4007f36
change PublicPagesTest test from /maps to /map
nstjean f41b7e4
clean up code
nstjean 6d8f8f5
remove center tag and unnecessary javascript
nstjean 03e79ff
add map tests to system tests
nstjean bbf6d9c
include 0 in testing numbers
nstjean 4b9f645
increase capybara default max wait time
nstjean 17801ed
change test tag contributors to a fixed tag name to stop error
nstjean 13a3100
remove two tests to check if it passes on server
nstjean 10a4ceb
add map controller tests
nstjean 034044a
attempt to fix travis error
nstjean ed4b780
comment out all system map tests
nstjean c2829a6
format assertion in show map by hash location in a different way
nstjean 2a1c3c9
hide show map by hash location, show correct url for wiki map
nstjean 9fbe561
Increase wait time for map system tests
nstjean 498d826
update yarn.lock
nstjean e7a54a3
set max wait time to 90
nstjean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
function urlMapHash() { | ||
// This is based off of jywarren's urlhash, made specific to our map hash needs | ||
|
||
const paramArray = ["zoom", "lat", "lon"]; | ||
|
||
function getUrlHashParameter(param) { | ||
|
||
var params = getUrlHashParameters(); | ||
return params[param]; | ||
|
||
} | ||
|
||
function getUrlHashParameters() { | ||
|
||
var sPageURL = window.location.hash; | ||
if (sPageURL) sPageURL = sPageURL.split('#')[1]; | ||
var items = sPageURL.split('/'); | ||
var object = {}; | ||
items.forEach(function(item, i) { | ||
if ((item !== '') && (paramArray[i])) object[paramArray[i]] = item; | ||
}); | ||
return object; | ||
} | ||
|
||
// accepts an object like { paramName: value, paramName1: value } | ||
// and transforms to: url.com#zoom/lat/lon | ||
function setUrlHashParameters(params) { | ||
|
||
var values = []; | ||
paramArray.forEach(function(key, i) { | ||
values.push(params[key]); | ||
}); | ||
var hash = values.join('/'); | ||
window.location.hash = hash; | ||
|
||
} | ||
|
||
function setUrlHashParameter(param, value) { | ||
|
||
var params = getUrlHashParameters(); | ||
params[param] = value; | ||
setUrlHashParameters(params); | ||
|
||
} | ||
|
||
return { | ||
getUrlHashParameter: getUrlHashParameter, | ||
getUrlHashParameters: getUrlHashParameters, | ||
setUrlHashParameter: setUrlHashParameter, | ||
setUrlHashParameters: setUrlHashParameters | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
<%= javascript_include_tag('/lib/urlhash/urlHash.js') %> | ||
<%= render :partial => "map/mapDependencies" %> | ||
|
||
<style> | ||
|
@@ -21,53 +20,63 @@ | |
height: 80vh; | ||
background:rgba(255,255,255,0.5); | ||
} | ||
.alert { | ||
z-index: 600; | ||
} | ||
</style> | ||
|
||
<div id="map"></div> | ||
<div id="map"></div> | ||
|
||
<script> | ||
|
||
var urlHash = urlHash(); | ||
var urlHash = urlMapHash(); | ||
|
||
// if there are location params in URL let them override, otherwise save lat/lon/zoom from controller | ||
if (!urlHash.getUrlHashParameter('lat') || !urlHash.getUrlHashParameter('lon')) { | ||
<% if @lat && @lon %> | ||
urlHash.setUrlHashParameter('lat', <%= @lat %> + ""); | ||
urlHash.setUrlHashParameter('lon', <%= @lon %> + ""); | ||
<% if @zoom %> | ||
urlHash.setUrlHashParameter('zoom', <%= @zoom %> + ""); | ||
<% end %> | ||
<% end %> | ||
} | ||
|
||
const params = urlHash.getUrlHashParameters(); | ||
|
||
var lat = parseFloat(params.lat); | ||
var lon = parseFloat(params.lon); | ||
var zoom = parseFloat(params.zoom); | ||
|
||
const bounds = new L.LatLngBounds( | ||
new L.LatLng(84.67351257, -172.96875), | ||
new L.LatLng(-54.36775852, 178.59375) | ||
); | ||
|
||
var user_lat = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes awesome i wanted this to be removed from here and not the URLHash logic! Thanks! |
||
var user_lon = null; | ||
var profile_zoom = null; | ||
<% if @user_lat && @user_lon %> | ||
user_lat = "<%= @user_lat %>"; | ||
user_lon = "<%= @user_lon %>"; | ||
profile_zoom = 7; | ||
<% end %> | ||
|
||
var lat = params.lat || user_lat || 23; | ||
var lon = params.lon || user_lon || 77; | ||
var zoom = parseFloat(params.zoom) || profile_zoom || 3; | ||
// These must be parsed after evaluating above or else 0 will not be displayed | ||
lat = parseFloat(lat); | ||
lon = parseFloat(lon); | ||
|
||
var map = L.map("map", { | ||
maxBounds: bounds, | ||
maxBoundsViscosity: 0.75 | ||
}).setView([lat, lon], zoom); | ||
|
||
updateLocationHash(); | ||
updateZoomHash(); | ||
|
||
map.options.minZoom = 3; | ||
|
||
map.on('moveend', function() { | ||
map.on('moveend', updateLocationHash); | ||
|
||
map.on('zoomend', updateZoomHash); | ||
|
||
function updateLocationHash() { | ||
const center = map.getCenter(); | ||
urlHash.setUrlHashParameter('lat', center.lat + ""); | ||
urlHash.setUrlHashParameter('lon', center.lng + ""); | ||
}) | ||
} | ||
|
||
map.on('zoomend', function() { | ||
function updateZoomHash() { | ||
const zoom = map.getZoom(); | ||
urlHash.setUrlHashParameter('zoom', zoom + ""); | ||
}) | ||
} | ||
|
||
<% if @layersname.nil? %> | ||
var layersname = ['odorreport', 'asian', 'clouds', 'eonetFiresLayer', 'Unearthing']; | ||
|
@@ -90,5 +99,4 @@ | |
embed: true, | ||
}).addTo(map); | ||
|
||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<div class="col-lg-3 d-print-none"> | ||
<div class="sidebar-panel"> | ||
<div id="sidebar"> | ||
<div id="sidebar" class="mb-3"> | ||
|
||
<% cache('related_sidebar-feature', skip_digest: true) do %> | ||
<%= feature('sidebar') %> | ||
|
@@ -41,17 +41,22 @@ | |
<% if @node && @node.has_power_tag('response') %> | ||
<%= 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.has_power_tag("place")) && @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, @node.zoom) %> | ||
<% elsif [email protected] && [email protected] %> | ||
<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;"> | ||
<button class="btn btn-outline-secondary btn-lg" id="add_location" style="position: absolute; position: absolute;top: 19% ; left: 24% ;" type="button" name="button"><strong>Add location</strong></button> | ||
</div> | ||
<center><span>Learn about location <a href="https://publiclab.org/location-privacy">privacy</a></span></center> | ||
<% end %> | ||
<% if @node && @node.lat && @node.lon %> | ||
<% if @node.has_tag("place") %> | ||
<%= render_top_map(@node.lat, @node.lon, @node.zoom) %> | ||
<% else %> | ||
<%= render_map(@node.lat, @node.lon, @node.zoom) %> | ||
<% end %> | ||
<%# Link to map %> | ||
<% zoom = @node.zoom ? @node.zoom : "" %> | ||
<% url = "/map#" + zoom.to_s + "/" + @node.lat.to_s + "/" + @node.lon.to_s %> | ||
<% if @node.type == "page" %> | ||
<% url = "/map/" + @node.slug_from_path %> | ||
<% end %> | ||
<a href="<%= url %>" class="btn btn-outline-secondary btn-location mt-2"><i class="fa fa-map" aria-hidden="true"></i> View on a map</a> | ||
<% elsif [email protected] && [email protected] %> | ||
<a class="blurred-location-input btn btn-outline-secondary btn-location my-2"><i class="fa fa-map-marker" aria-hidden="true"></i> Add a location</a> | ||
<% end %> | ||
|
||
<br style="clear:both;" /> | ||
|
||
|
@@ -72,10 +77,4 @@ | |
<% end %> | ||
</div> | ||
</div> | ||
<%= javascript_include_tag 'sidebar' %> | ||
|
||
<script type="text/javascript"> | ||
$('#add_location').on('click', function() { | ||
$('.blurred-location-input').click(); | ||
}) | ||
</script> | ||
<%= javascript_include_tag 'sidebar' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey this is cool, can you tell what specific changes you did to match plots2? Is the URL different now? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the format to be
#zoom/lat/lon
. I really like having a hash function available to get and set the values!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick question, have the layer names been removed from the hash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently yes they aren't in the hash. It had been set up to use the route for the layer names, which had to be changed. Do you need them added back in? It's easy enough to add them at the end of the hash, if that works for @jywarren ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that's fine for now. I was trying to figure out an issue when I noticed we don't have them anymore. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had them to track active layers. In LEL it is used in the embed to preserve the state of the layers. I don't remember if this was the case in plots2? @sagarpreet-chadha, could you confirm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey,
So i made embed feature to take array of layers as input, and show them on map by default (@nstjean ...we will use this in /people map in plots2). This feature is unrelated to url hash AFAIK.
If we will require layer names in future, it should be pretty easy, right? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Got it. To correct what I said earlier, it wasn't in the hash but before it. Thanks, @sagarpreet-chadha!