Commit 58f65ad1 authored by David F.'s avatar David F.

Merge branch '12-use-openstreetmap' into 'master'

Resolve "Utiliser Openstreetmap pour les cartes"

See merge request !78
parents 7533705a 01148709
......@@ -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'
......
......@@ -167,10 +167,9 @@ GEM
fuubar (2.2.0)
rspec-core (~> 3.0)
ruby-progressbar (~> 1.4)
geocoder (1.4.4)
geocoder (1.4.9)
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
*/
......
......@@ -32,10 +32,12 @@ class EventsController < ApplicationController
def show
@event = Event.find(params[:id])
@json = Gmaps4rails.build_markers(@event) do |event, marker|
marker.lat event.latitude
marker.lng event.longitude
end
marker = {
latlng: [@event.latitude, @event.longitude],
title: @event.title,
icon: :blue
}
@markers = [marker]
end
def new
......
......@@ -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,13 @@ 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 = base_members.map do |member|
{
latlng: [member.latitude, member.longitude],
title: member.name,
popup: render_to_string(partial: "/members/infowindow", locals: { member: member}),
icon: (member.published ? :blue : :grey)
}
end
else
authorize
......
......@@ -52,32 +52,32 @@ class MembersController < ApplicationController
base_members = base_members.for_years(params[:registry_dates]) if params[:registry_dates]
@members = (params[:member_groups] || params[:registry_dates]) ? base_members : []
if @members.empty?
@json = []
@markers = []
flash[:alert] = "Aucun élément n'a été trouvé"
else
@legend = {}
colors = COLORS.values.reverse!
default_color = "bbb"
colors = COLORS.dup
default_color = :grey
if params[:member_groups]
requested_groups = MemberGroup.find(params[:member_groups])
requested_groups.each do |group|
@legend[group.id] = {name: group.title, color: (colors.empty? ? default_color : colors.shift.delete('#'))}
@legend[group.id] = {name: group.title, color: (colors.empty? ? default_color : colors.shift)}
end
else
requested_groups = []
end
@json = Gmaps4rails.build_markers(@members) do |member, marker|
marker.lat member.latitude
marker.lng member.longitude
marker.title member.name
@markers = @members.map do |member|
color = if !member.member_groups.empty? && (mg = (member.member_groups & requested_groups).first) && @legend[mg.id].present?
@legend[mg.id][:color]
else
default_color
end
marker.picture(google_marker(color))
marker.infowindow render_to_string(partial: "/members/infowindow", locals: { member: member})
{
latlng: [member.latitude, member.longitude],
title: member.name,
popup: render_to_string(partial: "/members/infowindow", locals: { member: member}),
icon: color
}
end
end
end
......
......@@ -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)
update_icon_settings(markers)
final_map = case markers.length
when 0
""
when 1
map(markers: markers, center: {latlng: markers.first[:latlng], zoom: 13})
else
lower_marker, upper_marker = markers.minmax_by { |m| m[:latlng][0] }
western_marker, eastern_marker = markers.minmax_by { |m| m[:latlng][1] }
bottom_left_limit = [lower_marker[:latlng][0], western_marker[:latlng][1]]
top_right_limit = [upper_marker[:latlng][0], eastern_marker[:latlng][1]]
fitbounds = [bottom_left_limit, top_right_limit]
map(markers: markers, fitbounds: fitbounds)
end
content_tag :div, id: 'map_container' do
final_map
end
end
def ban_data_gouv_fr_map
textilize_without_paragraph 'Pour vous aider à préciser l\'adresse : "(externe)carte interactive":https://adresse.data.gouv.fr/map'
end
private
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
......@@ -35,7 +35,7 @@
<%= f.input :begin_at, as: :date_picker %>
<%= f.input :end_at, as: :date_picker %>
<%= f.association :event_type, prompt: "Choisir un type d'évenement" %>
<%= f.input :location %>
<%= f.input :location, hint: ban_data_gouv_fr_map %>
<%= f.input :price, input_html: {class: "small_string"} %>
</div>
<div id="event_activities">
......
......@@ -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 %>
......@@ -53,9 +52,9 @@
<%= @event.location %>
</p>
<% unless @json.empty? %>
<% unless @markers.empty? %>
<div class="map_container map_container-mini">
<div id="map"></div>
<%= tailored_map(@markers) %>
</div>
<% end %>
......@@ -79,15 +78,3 @@
<%= render 'attachments', data: @event.attached_files %>
</article>
<% 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();
handler.getMap().setZoom(12);
});
</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 @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 -%>
......@@ -61,7 +61,7 @@
<div id="information">
<%= f.input :description %>
<%= f.input :address %>
<%= f.input :address, hint: ban_data_gouv_fr_map %>
<%= localized_status %>
<%= f.input :website %>
<%= f.input :join_us %>
......
......@@ -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 -%>
......@@ -50,29 +48,20 @@
</div>
<% end -%>
<% unless @json.empty? %>
<% unless @markers.empty? %>
<div class="map_container">
<div id="map"></div>
<%= tailored_map(@markers) %>
<% unless @legend.empty? %>
<div class="map_legend">
<ul>Légende :
<% @legend.each_value do |item| %>
<li style="color: #<%= item[:color] %>"><%= item[:name] %></li>
<li><%= image_tag "marker-icon-#{item[:color]}.png" %><%= item[:name] %></li>
<% end %>
</ul>
</div>
<% end -%>
</div>
<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>
<div id="displayed_members">
<h2>Liste des membres trouvés</h2>
<ul>
......
......@@ -23,7 +23,7 @@
require_relative 'boot'
require 'pdfkit'
COLORS = { :bleu => "#87CEFA", :gris => "#D3D3D3", :jaune => "#EEE8AA", :orange => "#F4A460", :rouge => "#F08080", :rose => "#FFC0CB", :vert => "#90EE90", :violet => "#DDA0DD" }
COLORS = [:blue, :green, :yellow, :grey, :orange, :red, :violet, :black]
require 'rails/all'
......
Geocoder.configure(
# Geocoding options
# timeout: 3, # geocoding service timeout (secs)
lookup: :ban_data_gouv_fr, # name of geocoding service (symbol)
# ip_lookup: :freegeoip, # name of IP address geocoding service (symbol)
language: :fr, # ISO-639 language code
# use_https: false, # use HTTPS for lookup requests? (if supported)
# http_proxy: nil, # HTTP proxy server (user:pass@host:port)
# https_proxy: nil, # HTTPS proxy server (user:pass@host:port)
# api_key: nil, # API key for geocoding service
# cache: nil, # cache object (must respond to #[], #[]=, and #del)
# cache_prefix: 'geocoder:', # prefix (string) to use for all cache keys
# http_headers: { "User-Agent" => ENV['APP_NAME'] }
# Exceptions that should not be rescued by default
# (if you want to implement custom error handling);
# supports SocketError and Timeout::Error
# always_raise: [],
# Calculation options
# units: :mi, # :km for kilometers or :mi for miles
# distances: :linear # :spherical or :linear
)
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