From 1faa342c1a73c9f8b23aa857242ddb1b3e6578f5 Mon Sep 17 00:00:00 2001 From: Ferdinando Traversa Date: Mon, 1 Jul 2019 12:18:13 +0200 Subject: [PATCH] Mappa generale in index, calcolo del geocenter, api mapbox --- app/controllers/monuments_controller.rb | 4 ++++ app/helpers/monuments_helper.rb | 3 +++ app/views/monuments/index.html.erb | 12 ++++++++++++ app/views/monuments/map.html.erb | 2 +- app/views/monuments/show.html.erb | 2 +- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/controllers/monuments_controller.rb b/app/controllers/monuments_controller.rb index 1aaa420..f482614 100644 --- a/app/controllers/monuments_controller.rb +++ b/app/controllers/monuments_controller.rb @@ -1,12 +1,16 @@ class MonumentsController < ApplicationController include Pagy::Backend + include MonumentsHelper def index if params[:latitude] && params[:longitude] @pagy, @monument = pagy(Monument.near([BigDecimal.new(params[:latitude]), BigDecimal.new(params[:longitude])])) + @monument_nopagy = Monument.near([BigDecimal.new(params[:latitude]), BigDecimal.new(params[:longitude])]) elsif params[:city] @pagy, @monument = pagy(Monument.near("#{params[:city]}")) + @monument_nopagy = Monument.near(params[:city]) end + @geocenter = Geocoder::Calculations.geographic_center(@monument_nopagy) end def show diff --git a/app/helpers/monuments_helper.rb b/app/helpers/monuments_helper.rb index 89c6413..fc70d8f 100644 --- a/app/helpers/monuments_helper.rb +++ b/app/helpers/monuments_helper.rb @@ -1,3 +1,6 @@ module MonumentsHelper include Pagy::Frontend + def geocenter(monuments) + return Geocoder::Calculations.geographic_center(monuments) + end end diff --git a/app/views/monuments/index.html.erb b/app/views/monuments/index.html.erb index c2cdaef..0a54a6d 100644 --- a/app/views/monuments/index.html.erb +++ b/app/views/monuments/index.html.erb @@ -1,6 +1,18 @@ <% provide(:title, 'Monumenti nelle vicinanze') %>

Lista monumenti nelle vicinanze

<% if @monument.any? %> +
+ diff --git a/app/views/monuments/map.html.erb b/app/views/monuments/map.html.erb index 25bb64c..d637e40 100644 --- a/app/views/monuments/map.html.erb +++ b/app/views/monuments/map.html.erb @@ -1,7 +1,7 @@
Immagine