Skip to content

Commit a6413bb

Browse files
cesswairimujywarren
authored andcommitted
New view only map page (#777)
* view map page * view map routing and styling * improve map view * style mappers * add edit map button * test view map action * Enhance view page * show nearby maps * change div to class * update tests * move view_map to maps controller * show images on top of map * fix filename typo * fix typo * Fix mobile view * include tags in posting to publiclab * fix styling * change to new view page and create an edit page * add show page button in edit * fix failing tests * make buttons style consistent * change button to exit editor * remove observation section
1 parent e7da080 commit a6413bb

13 files changed

+209
-91
lines changed

app/assets/images/balloon1.png

13.8 KB
Loading

app/assets/images/binoculars.png

30 KB
Loading

app/assets/images/quiz.png

12.8 KB
Loading

app/assets/stylesheets/style.scss

+5-13
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ label small {
230230
letter-spacing: -0.2px;
231231
}
232232

233-
234233
.item-description {
235234
font-size: 18px;
236235
font-weight: 300;
@@ -240,21 +239,14 @@ label small {
240239
color: #a2aaad;
241240
}
242241

243-
244-
#info {
245-
.fa-stack {
246-
font-size: 0.7em;
247-
color: gray
248-
}
249-
.fa {
250-
font-size: 6em;
251-
padding-bottom: 20px;
252-
}
253-
}
254-
#all-maps {
242+
.all-maps {
255243
img {
256244
display: block;
257245
width: 200px;
258246
height: 200px;
259247
}
260248
}
249+
250+
.light-blue {
251+
background-color: #d0e2f2;
252+
}

app/controllers/maps_controller.rb

+13-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class MapsController < ApplicationController
44
protect_from_forgery except: :export
55

66
before_action :require_login, only: %i(edit update destroy)
7-
before_action :find_map, only: %i(show annotate embed edit update images destroy archive)
7+
before_action :find_map, only: %i(show annotate embed edit update images destroy archive view_map)
88

99
layout 'knitter2'
1010

@@ -57,10 +57,10 @@ def create
5757

5858
def show
5959
@map.zoom ||= 12
60-
61-
# this is used for the resolution slider
62-
@resolution = @map.average_cm_per_pixel.round(4)
63-
@resolution = 5 if @resolution < 5 # soft-set min res
60+
@maps = Map.maps_nearby(lat: @map.lat, lon: @map.lon, dist: 10)
61+
.sample(4)
62+
@unpaginated = true
63+
render layout: 'application'
6464
end
6565

6666
def archive
@@ -81,15 +81,21 @@ def embed
8181
@map.zoom ||= 12
8282
@embed = true
8383
response.headers.except! 'X-Frame-Options' # allow use of embed in iframes
84-
render template: 'maps/show'
84+
render template: 'maps/edit'
8585
end
8686

8787
def annotate
8888
@map.zoom = 12 # get rid of this; use setBounds or something
8989
@annotations = true # loads annotations-specific assets
9090
end
9191

92-
def edit; end
92+
def edit
93+
@map.zoom ||= 12
94+
95+
# this is used for the resolution slider
96+
@resolution = @map.average_cm_per_pixel.round(4)
97+
@resolution = 5 if @resolution < 5 # soft-set min res
98+
end
9399

94100
def update
95101
@map.update_attributes(map_params)

app/views/front_ui/_featured_mappers.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<div class="row map-list mx-auto mt-3">
22
<% mappers.each do |user| %>
33
<div class="card-deck map col-md-6 col-lg-3 col-xs-12 mb-2 ml-2">
4-
<div class="card card-without-border">
4+
<div class="bg-transparent card card-without-border">
55
<%= image_tag(profile_image(user), class: "img-icon card-img-top mx-auto") %>
66
<div class="card-body text-center" style="margin-left: -18px !important;">
77
<h5 class="card-title"><a href="/profile/<%= user.login %>">@<%= user.login %></a></h5>
8-
<p class="card-text text-muted"> <%= user.maps.count %>
8+
<p class="card-text text-muted"> <%= user.maps.count %> maps
99
near <%= user.maps.first.location %>
1010
<br>
1111
</p>

app/views/front_ui/_maps.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<% maps.each do |map| %>
33
<% warp = map.placed_warpables.first %>
44
<div class="card-deck map col-md-6 col-lg-3 col-xs-12 mb-2 ml-2">
5-
<div class="card card-without-border">
5+
<div class="card bg-transparent card-without-border">
66
<a href="/maps/<%= map.slug %>">
77
<% if warp.present? %>
88
<img class="card-img-top map-img" src="<%= warp.image.url %>" alt="<%= map.name %>">

app/views/front_ui/gallery.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="section-header mt-4" id="all-maps" >
1+
<div class="section-header mt-4 all-maps" >
22
<% if params[:q].present? %>
33
<h2 class="section-title text-center"> <%= @title %></h2>
44
<hr style="max-width: 500px;">

app/views/maps/edit.html.erb

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<% content_for :title do %>
2+
<div class="sidebar-title mt-3">
3+
<h3><%= @map.name %>
4+
<%= link_to 'Exit editor', @map, class: 'float-right btn btn-sm btn-info'%>
5+
</h3>
6+
</div>
7+
<div class="map-author">
8+
<% if @map.user %>
9+
by <a href="//publiclab.org/profile/<%= @map.user.login %>"><%= @map.user.login %></a>
10+
<% else %>
11+
anonymous
12+
<% end %>
13+
</div>
14+
<% end %>
15+
16+
<% content_for :details do %>
17+
<div>
18+
<%=raw markdown_to_html(@map.description) unless @map.description.nil? %>
19+
</div>
20+
21+
<p>
22+
<span class="map-detail-label">Location</span>
23+
<a href="https://www.openstreetmap.org/#map=<%= @map.zoom %>/<%= @map.lat %>/<%= @map.lon %>"><%= @map.location %></a>
24+
</p>
25+
26+
<table>
27+
<tr><td><span class="map-detail-label">Latitude </span><%= @map.lat %></td><td><span class="map-detail-label">Longitude </span><%= @map.lon %></td></tr>
28+
</table>
29+
30+
<p>
31+
<span class="map-detail-label">License (<a target="_blank" href="http://publiclab.org/licenses">Learn more</a>):</span>
32+
<a href="/maps/license/<%= @map.license %>"><%= @map.license %></a>
33+
</p>
34+
35+
<hr />
36+
<p>
37+
<% if logged_in? %>
38+
<button type="button" class="btn btn-outline-info btn-sm" onClick="$('#map-edit-container').toggle()">Edit details</button>
39+
<% end %>
40+
<button type="button" class="btn btn-outline-info btn-sm" onClick="$('.share-link').toggle()">Embed code</button>
41+
<button type="button" class="btn btn-outline-info btn-sm" title="Preview with NDVI" onClick="ImageSequencer().replaceImage('.leaflet-image-layer',['ndvi','colormap'])">NDVI (beta)</button>
42+
<button type="button" class="btn btn-outline-info btn-sm" rel="tooltip" title="Custom image processing" onClick="ImageSequencer().replaceImage('.leaflet-image-layer',prompt('Enter an ImageSequencer code', 'invert,ndvi,colormap').split(','))">Add ImageSequencer code</button>
43+
<div class="share-link" style="display:none;">
44+
<%= render :partial => 'maps/share' %>
45+
</div>
46+
<a href="https://publiclab.org/image-sequencer#NDVI">Learn more about ImageSequencer code</a>
47+
</p>
48+
49+
<div style="display:none;" id="map-edit-container">
50+
<%= render :partial => 'maps/edit' %>
51+
</div>
52+
53+
<hr />
54+
<div class="tags">
55+
<%= render :partial => "tags/index" %>
56+
</div>
57+
58+
<hr />
59+
60+
<div class="comments">
61+
<%= render :partial => "comments/index" %>
62+
<hr />
63+
<%= render :partial => "comments/new" %>
64+
</div>
65+
<% end %>
66+
67+
<% content_for :images do %>
68+
<%= render :partial => "/images/index" %>
69+
<% end %>

app/views/maps/show.html.erb

+92-59
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,100 @@
1-
<% content_for :title do %>
2-
<div class="sidebar-title mt-3">
3-
<h3><%= @map.name %></h3>
4-
</div>
5-
<div class="map-author">
6-
<% if @map.user %>
7-
by <a href="//publiclab.org/profile/<%= @map.user.login %>"><%= @map.user.login %></a>
8-
<% else %>
9-
anonymous
10-
<% end %>
11-
</div>
12-
<% end %>
13-
14-
<% content_for :details do %>
15-
<div>
16-
<%=raw markdown_to_html(@map.description) unless @map.description.nil? %>
17-
</div>
18-
19-
<p>
20-
<span class="map-detail-label">Location</span>
21-
<a href="https://www.openstreetmap.org/#map=<%= @map.zoom %>/<%= @map.lat %>/<%= @map.lon %>"><%= @map.location %></a>
22-
</p>
23-
24-
<table>
25-
<tr><td><span class="map-detail-label">Latitude </span><%= @map.lat %></td><td><span class="map-detail-label">Longitude </span><%= @map.lon %></td></tr>
26-
</table>
1+
<%= stylesheet_link_tag "/lib/leaflet/dist/leaflet.css" %>
2+
<%= stylesheet_link_tag "https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/leaflet.fullscreen.css" %>
273

28-
<p>
29-
<span class="map-detail-label">License (<a target="_blank" href="http://publiclab.org/licenses">Learn more</a>):</span>
30-
<a href="/maps/license/<%= @map.license %>"><%= @map.license %></a>
31-
</p>
4+
<%= javascript_include_tag 'maps' %>
5+
<%= javascript_include_tag '//api.tiles.mapbox.com/mapbox.js/plugins/leaflet-omnivore/v0.3.1/leaflet-omnivore.min.js' %>
6+
<%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=AIzaSyAxlBXzYwdeaOMKZgx_UNBp2qBtdD0L_9g" %>
7+
<%= javascript_include_tag 'https://unpkg.com/leaflet.gridlayer.googlemutant@0.7.0/Leaflet.GoogleMutant.js' %>
8+
<%= javascript_include_tag '/lib/image-sequencer/dist/image-sequencer.js' %>
329

33-
<hr />
34-
<p>
35-
<% if logged_in? %>
36-
<button type="button" class="btn btn-outline-info btn-sm" onClick="$('#map-edit-container').toggle()">Edit details</button>
37-
<% end %>
38-
<button type="button" class="btn btn-outline-info btn-sm" onClick="$('.share-link').toggle()">Embed code</button>
39-
<button type="button" class="btn btn-outline-info btn-sm" title="Preview with NDVI" onClick="ImageSequencer().replaceImage('.leaflet-image-layer',['ndvi','colormap'])">NDVI (beta)</button>
40-
<button type="button" class="btn btn-outline-info btn-sm" rel="tooltip" title="Custom image processing" onClick="ImageSequencer().replaceImage('.leaflet-image-layer',prompt('Enter an ImageSequencer code', 'invert,ndvi,colormap').split(','))">Add ImageSequencer code</button>
41-
<div class="share-link" style="display:none;">
42-
<%= render :partial => 'maps/share' %>
10+
<div class= "row" id="knitter-map-pane" style="height: 450px; width: 100%; margin-bottom: 1%; z-index: 5; float: none; max-width: none;"> </div>
11+
<div class="container-fluid">
12+
<div class="row">
13+
<div class="col-md-6">
14+
<button type="button" class="btn btn-outline-info btn-sm" onClick="$('.share-link').toggle()" style="margin-left: 1%;">Embed code</button>
15+
<div class="share-link" style="display:none;">
16+
<%= render :partial => 'maps/share' %>
17+
</div>
18+
</div>
19+
<div class="col-md-6">
20+
<a href="/maps/edit/<%= @map.slug %>">
21+
<button class="btn btn-outline-info float-right">
22+
<span class="fas fa-pencil-alt"> </span> Edit this map
23+
</button>
24+
</a>
25+
</div>
4326
</div>
44-
<a href="https://publiclab.org/image-sequencer#NDVI">Learn more about ImageSequencer code</a>
45-
</p>
27+
</div>
4628

47-
<div style="display:none;" id="map-edit-container">
48-
<%= render :partial => 'maps/edit' %>
49-
</div>
50-
51-
<hr />
52-
<div class="tags">
53-
<%= render :partial => "tags/index" %>
54-
</div>
29+
<div class="container-fluid">
30+
<div class="text-center lead-text">
31+
<p class="text-muted">A Community Atlas of </p>
32+
<h2><%= @map.location %> </h2>
33+
<p> by <%= link_to "@#{@map.author}", "/profile/#{@map.author}" unless @map.author == 'anonymous' %> </p>
34+
</div>
35+
<br>
36+
</div>
5537

56-
<hr />
38+
<div class="container">
39+
<div class="card-deck mb-6 text-center mx-auto">
40+
<div class="card mapping-kits">
41+
<img class="card-img-top img-draw mx-auto" src="<%= asset_path('balloon1.png') %>" alt="balloon icon">
42+
<div class="card-body">
43+
<h3>Make your own map </h3>
44+
<p class="card-text item-description">
45+
Use a kite, balloon, pole or drone to take an aerial photo and tell your own visual story of the place
46+
</p>
47+
<p>
48+
<a class="btn btn-primary btn-lg" href= 'https://store.publiclab.org/collections/mapping-kits'>
49+
Get a mapping kit<i class="fa fa-angle-double-right fa-fw" style="font-size:18px;color:white;"></i>
50+
</a>
51+
<a class="btn btn-primary btn-lg" href="<%= new_map_url %>">
52+
Add a new map <i class="fa fa-plus fa-fw" style="font-size:12px;color:white;"></i>
53+
</a>
54+
</p>
55+
</div>
56+
</div>
57+
<div class="card mapping-kits">
58+
<img class="card-img-top img-draw mx-auto" src="<%= asset_path('quiz.png') %>" alt="questions">
59+
<div class="card-body">
60+
<h3>Ask a question</h3>
61+
<p class="card-text item-description">
62+
<a href="https://publiclab.org/questions" target="blank">Search </a>through questions or Ask a question to get help from others and share ideas with the PublicLab Community
63+
<%# hence helping you in your environmental exploration %>
64+
</p>
65+
<p>
66+
<a href="https://publiclab.org/questions/new?tags=lat:<%= @map.lat %>,lon:<%= @map.lon %>&body=Question posted from map at https://mapknitter.org/m/<%= @map.slug %>" target="blank">
67+
<button class="btn btn-lg btn-primary">
68+
Ask a Question
69+
</button>
70+
</a>
71+
</p>
72+
</div>
73+
</div>
74+
</div>
75+
</div>
5776

58-
<div class="comments">
59-
<%= render :partial => "comments/index" %>
60-
<hr />
61-
<%= render :partial => "comments/new" %>
77+
<div class="all-maps light-blue">
78+
<br>
79+
<h3 class="text-center"> Nearby Maps </h3>
80+
<hr style="max-width: 500px;">
81+
<br>
82+
<%= render :partial => 'front_ui/maps', :locals => { :maps => @maps } %>
6283
</div>
63-
<% end %>
6484

65-
<% content_for :images do %>
66-
<%= render :partial => "/images/index" %>
67-
<% end %>
85+
<script>
86+
var map
87+
(function(){
88+
window.mapKnitter = new MapKnitter.Map({
89+
latlng: L.latLng(<%= @map.lat %>, <%= @map.lon %>),
90+
zoom: <%= @map.zoom %>,
91+
readOnly: true,
92+
logged_in: <%= logged_in? == true %>,
93+
anonymous: <%= @map.anonymous? == true %>,
94+
warpablesUrl: "<%= url_for([@map, :warpables])+'.json' unless @map.warpables.empty? %>"
95+
});
96+
<% if @map.warpables.empty? && params[:action] == "show" %>
97+
$('.modal-welcome').modal()
98+
<% end %>
99+
})();
100+
</script>

config/routes.rb

+9-7
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@
1212
get 'gallery', to: 'front_ui#gallery'
1313
get 'location' => 'front_ui#location'
1414
post 'save_location', to: 'front_ui#save_location'
15-
15+
1616
get 'legacy', to: 'maps#index' # remove once new front page is stable
17-
17+
1818
get 'external_url_test', to: 'export#external_url_test'
19-
19+
20+
get 'm/:id' => 'front_ui#view_map'
21+
2022
# since rails 3.2, we use this to log in:
2123
get 'sessions/create', to: 'sessions#create'
2224
get 'local/:login', to: 'sessions#local'
2325
get 'logout', to: 'sessions#logout'
2426
get 'login', to: 'sessions#new'
25-
26-
27+
28+
2729
resources :users, :sessions, :maps, :images, :comments, :tags
28-
30+
2931
# redirect legacy route:
3032
get 'tag/:id', to: redirect('/tags/%{id}')
31-
33+
3234
# Registered user pages:
3335
get 'register', to: 'users#create'
3436
get 'signup', to: 'users#new'

test/controllers/front_ui_controller_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ def teardown
4646
assert @maps.collect(&:name).include?('Cubbon Park')
4747
end
4848

49+
test 'view map page' do
50+
map = maps(:saugus)
51+
get :view_map, id: map.slug
52+
53+
assert_response :success
54+
assert assigns(:maps)
55+
assert_template 'front_ui/view_map'
56+
end
4957
end

0 commit comments

Comments
 (0)