From b6aeac4d9274f17e748efb3715aa08f4b7c361f2 Mon Sep 17 00:00:00 2001 From: hellekin Date: Wed, 11 Nov 2020 22:27:18 +0100 Subject: Add map support This commit creates a dedicated Map model and moves the JavaScript from view to a Stimulus controller. - Stimulus.js https://stimulusjs.org - Leaflet.js https://leafletjs.org Upcoming resources: - https://discourse.stimulusjs.org/t/leafletjs-with-stimulusjs-on-rails-6/1343/4 - https://github.com/ghybs/leaflet-defaulticon-compatibility --- app/controllers/welcome_controller.rb | 1 + app/helpers/application_helper.rb | 14 ++++++++++++++ app/models/map.rb | 4 ++++ app/views/welcome/index.html.erb | 32 +++++++++++--------------------- 4 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 app/models/map.rb (limited to 'app') diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 0c41e5a..ee76eb6 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -1,6 +1,7 @@ class WelcomeController < ApplicationController # GET / def index + @map = Map.first @resources = Resource.order(:uuid).page params[:page] Rails.logger.info "WECLOME ///// #{@resources&.count || 0}" end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0b22f4b..aa3a8d7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,4 +7,18 @@ module ApplicationHelper current_agency.send(:"#{role}?") end end + + def map_container(map = Map.first) + raw tag.div( + tag.div(id: 'map', + data: { + target: 'map.container' + }), + data: { + controller: 'map', + 'map-latitude': map.latitude, + 'map-longitude': map.longitude, + 'map-zoom': map.zoom + }) + end end diff --git a/app/models/map.rb b/app/models/map.rb new file mode 100644 index 0000000..10a55f6 --- /dev/null +++ b/app/models/map.rb @@ -0,0 +1,4 @@ +class Map < ApplicationRecord + include UUIDParameter + belongs_to :taxonomy +end diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 1b6ab77..eac1eff 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -9,7 +9,17 @@

Bienvenue à l'atelier carto d'IN COMMON

-<%= tag.div(id: 'map') %> +<%= map_container %> + +<% content_for :aside do %> +
+
+ +
+ +
+<% end %> <% content_for :debug do %> <% if current_user.present? %> @@ -19,23 +29,3 @@

<%= res.feature["geometry"]["coordinates"] %>

<% end %><%# ensure it does not break when we don't have a record... %> <% end %> - -<% content_for :body_end do %> - -<% end %> -- cgit v1.2.3