Commit b9c136ed authored by Alexandre Friquet's avatar Alexandre Friquet

Use leaflet/osm for admin member map page: refs #12.

parent 37556a93
......@@ -52,32 +52,34 @@ 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
color = if !member.member_groups.empty? && (mg = (member.member_groups & requested_groups).first) && @legend[mg.id].present?
@legend[mg.id][:color]
else
default_color
@markers = [].tap do |markers|
@members.each 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
markers << {
latlng: [member.latitude, member.longitude],
title: member.name,
popup: render_to_string(partial: "/members/infowindow", locals: { member: member}),
icon: color
}
end
marker.picture(google_marker(color))
marker.infowindow render_to_string(partial: "/members/infowindow", locals: { member: member})
end
end
end
......
......@@ -48,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'
......
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