Commit 37556a93 authored by Alexandre Friquet's avatar Alexandre Friquet

Use leaflet/openstreetmap for where2practice pages: refs #12.

parent 7533705a
......@@ -46,7 +46,7 @@ gem 'formatize', git: 'https://github.com/infoPiiaf/formatize.git'
gem 'simple_form'
gem "nested_form"
gem 'geocoder'
gem 'gmaps4rails'
gem 'leaflet-rails'
gem 'gretel'
gem 'gretel-trails', git: 'https://github.com/infoPiiaf/gretel-trails.git', branch: 'fix-alias-method-chain-error'
gem 'piwik_analytics', git: 'https://git.framasoft.org/infopiiaf/piwik_analytics.git'
......
......@@ -170,7 +170,6 @@ GEM
geocoder (1.4.4)
globalid (0.4.0)
activesupport (>= 4.2.0)
gmaps4rails (2.1.2)
google-api-client (0.8.6)
activesupport (>= 3.2)
addressable (~> 2.3)
......@@ -207,6 +206,8 @@ GEM
jwt (1.5.6)
launchy (2.4.3)
addressable (~> 2.3)
leaflet-rails (1.3.1)
rails (>= 4.2.0)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
......@@ -386,7 +387,6 @@ DEPENDENCIES
fullcalendar-rails
fuubar
geocoder
gmaps4rails
google-api-client (~> 0.8.0)
gretel
gretel-trails!
......@@ -395,6 +395,7 @@ DEPENDENCIES
jquery-rails
jquery-ui-rails
launchy
leaflet-rails
listen
momentjs-rails
nested_form
......@@ -422,4 +423,4 @@ DEPENDENCIES
will_paginate
BUNDLED WITH
1.15.4
1.16.1
......@@ -39,7 +39,7 @@
//= require jquery.switchButton
//= require fitvids.js
//= require underscore-min
//= require gmaps/google
//= require leaflet
//= require gretel.trails.hidden
//= require prettyphoto-rails
//= require moment
......
......@@ -32,6 +32,7 @@
*= require prettyphoto-rails
*= require fullcalendar
*= require jquery.minicolors
*= require leaflet
*= require_self
*/
......
......@@ -29,7 +29,7 @@ class MemberGroupsController < ApplicationController
def filter_members
prepare_markers
flash.now[:error] = "Aucune réponse n'a été trouvée. Merci d'élargir votre tri." if @json.empty?
flash.now[:error] = "Aucune réponse n'a été trouvée. Merci d'élargir votre tri." if @markers.empty?
render :show
end
......@@ -111,13 +111,15 @@ class MemberGroupsController < ApplicationController
base_members = base_members.localized
@published_members = base_members.published
@private_members = base_members.not_published
@json = Gmaps4rails.build_markers(base_members) do |member, marker|
marker.lat member.latitude
marker.lng member.longitude
marker.infowindow render_to_string(partial: "/members/infowindow", locals: { member: member})
marker.title member.name
color = member.published ? "59a3e8" : "c3c3c3"
marker.picture(google_marker(color))
@markers = [].tap do |markers|
base_members.each do |member|
markers << {
latlng: [member.latitude, member.longitude],
title: member.name,
popup: render_to_string(partial: "/members/infowindow", locals: { member: member}),
icon: (member.published ? :blue : :grey)
}
end
end
else
authorize
......
......@@ -120,15 +120,6 @@ SCSS
"© 2010#{Date.today.year == 2010 ? '' : "-"+Date.today.year.to_s} #{ENV['APP_NAME']}"
end
def gmaps4rails_scripts
scripts = <<EOS
<script src="//maps.google.com/maps/api/js?v=3.23&sensor=false&client=&key=&libraries=geometry&language=&hl=&region="></script>
<script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>
<script src='//cdn.rawgit.com/printercu/google-maps-utility-library-v3-read-only/master/infobox/src/infobox_packed.js' type='text/javascript'></script>
EOS
scripts.html_safe
end
def status_icon(obj, method, titles = ["OUI", "NON"])
icon, severity, title = obj.send(method) ? ['fa-check-square-o', 'success', titles[0]] : ['fa-ban', 'danger', titles[1]]
content_tag(:i, '', class: "fa #{icon} #{severity}", title: title)
......
module MapHelper
def tailored_map(markers)
final_map = case markers.length
when 0
""
when 1
update_icon_settings(markers)
map(markers: markers, center: {latlng: markers.first[:latlng], zoom: 13})
else
update_icon_settings(markers)
lats = markers.collect { |m| m[:latlng][0] }
longs = markers.collect { |m| m[:latlng][1] }
bottom_limit = markers.select { |m| m[:latlng][0] == lats.min}.first[:latlng]
top_marker = markers.select { |m| m[:latlng][0] == lats.max}.first[:latlng]
top_limit = [top_marker[0]+0.3, top_marker[1]]
fitbounds = [bottom_limit,top_limit]
map(markers: markers, fitbounds: fitbounds)
end
content_tag :div, id: 'map_container' do
final_map
end
end
def update_icon_settings(markers)
markers.each do |marker|
marker[:icon] = icon_settings(marker[:icon])
end
end
def icon_settings(color)
{
icon_url: ActionController::Base.helpers.asset_path("marker-icon-#{color}.png"),
icon_size: [25, 41],
icon_anchor: [12, 41],
popup_anchor: [1, -34],
shadow_size: [41, 41]
}
end
end
......@@ -20,7 +20,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
%>
<%= gmaps4rails_scripts %>
<% title @event.title %>
<% breadcrumb @event %>
......
......@@ -20,8 +20,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
%>
<%= gmaps4rails_scripts %>
<% title @member_group.title %>
<% breadcrumb @member_group %>
......@@ -69,9 +67,9 @@
</div>
<div class="card-block">
<% unless @json.empty? %>
<% unless @markers.empty? %>
<div class="map_container">
<div id="map"></div>
<%= tailored_map(@markers) %>
</div>
<% end %>
......@@ -100,14 +98,3 @@
</ul>
<% end %>
</div>
<% unless @json.empty? %>
<script type="text/javascript">
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers(<%=raw @json.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
</script>
<% end -%>
......@@ -20,8 +20,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
%>
<%= gmaps4rails_scripts %>
<% title "Carte des membres" %>
<%= form_tag map_members_path, method: :get, id: "members_filter" do -%>
......
Leaflet.tile_layer = '//{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png'
Leaflet.attribution = 'donn&eacute;es &copy; <a href="//osm.org/copyright">OpenStreetMap</a>/ODbL - rendu <a href="//openstreetmap.fr">OSM France</a>'
Leaflet.max_zoom = 20
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment