Show area and length on champ carto selections utilisateur
This commit is contained in:
parent
54d37bdb5d
commit
9cb612bb3d
6 changed files with 106 additions and 1 deletions
2
Gemfile
2
Gemfile
|
@ -25,11 +25,13 @@ gem 'devise' # Gestion des comptes utilisateurs
|
|||
gem 'devise-async'
|
||||
gem 'discard'
|
||||
gem 'dotenv-rails', require: 'dotenv/rails-now' # dotenv should always be loaded before rails
|
||||
gem 'ffi-geos'
|
||||
gem 'flipper'
|
||||
gem 'flipper-active_record'
|
||||
gem 'flipper-ui'
|
||||
gem 'font-awesome-rails'
|
||||
gem 'fugit'
|
||||
gem 'geo_coord', require: "geo/coord"
|
||||
gem 'geocoder'
|
||||
gem 'gon'
|
||||
gem 'graphql'
|
||||
|
|
|
@ -215,6 +215,8 @@ GEM
|
|||
faraday (0.15.4)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
ffi (1.12.2)
|
||||
ffi-geos (2.1.0)
|
||||
ffi (>= 1.0.0)
|
||||
flipper (0.17.2)
|
||||
flipper-active_record (0.17.2)
|
||||
activerecord (>= 4.2, < 7)
|
||||
|
@ -242,6 +244,7 @@ GEM
|
|||
fugit (1.3.3)
|
||||
et-orbi (~> 1.1, >= 1.1.8)
|
||||
raabro (~> 1.1)
|
||||
geo_coord (0.1.0)
|
||||
geocoder (1.6.0)
|
||||
globalid (0.4.2)
|
||||
activesupport (>= 4.2.0)
|
||||
|
@ -750,11 +753,13 @@ DEPENDENCIES
|
|||
discard
|
||||
dotenv-rails
|
||||
factory_bot
|
||||
ffi-geos
|
||||
flipper
|
||||
flipper-active_record
|
||||
flipper-ui
|
||||
font-awesome-rails
|
||||
fugit
|
||||
geo_coord
|
||||
geocoder
|
||||
gon
|
||||
graphql
|
||||
|
|
|
@ -49,6 +49,17 @@ module ChampHelper
|
|||
"#{geo_area.commune} : #{geo_area.nom}"
|
||||
when GeoArea.sources.fetch(:parcelle_agricole)
|
||||
"Culture : #{geo_area.culture} - Surface : #{geo_area.surface} ha"
|
||||
when GeoArea.sources.fetch(:selection_utilisateur)
|
||||
if geo_area.polygon?
|
||||
capture do
|
||||
concat "Une aire de surface #{geo_area.area} m"
|
||||
concat content_tag(:sup, "2")
|
||||
end
|
||||
elsif geo_area.line?
|
||||
"Une ligne longue de #{geo_area.length} m"
|
||||
elsif geo_area.point?
|
||||
"Un point situé à #{geo_area.location}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,7 +36,7 @@ class GeoArea < ApplicationRecord
|
|||
{
|
||||
type: 'Feature',
|
||||
geometry: geometry,
|
||||
properties: properties.merge(source: source)
|
||||
properties: properties.merge(source: source, area: area, length: length).compact
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -53,4 +53,34 @@ class GeoArea < ApplicationRecord
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
def area
|
||||
if polygon?
|
||||
rgeo_geometry.area.round(1)
|
||||
end
|
||||
end
|
||||
|
||||
def length
|
||||
if line?
|
||||
rgeo_geometry.length.round(1)
|
||||
end
|
||||
end
|
||||
|
||||
def location
|
||||
if point?
|
||||
Geo::Coord.new(*rgeo_geometry.coordinates).to_s
|
||||
end
|
||||
end
|
||||
|
||||
def line?
|
||||
geometry['type'] == 'LineString'
|
||||
end
|
||||
|
||||
def polygon?
|
||||
geometry['type'] == 'Polygon'
|
||||
end
|
||||
|
||||
def point?
|
||||
geometry['type'] == 'Point'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
- if champ.selections_utilisateur.present?
|
||||
.areas-title Sélections utilisateur
|
||||
.areas
|
||||
%ul
|
||||
- champ.selections_utilisateur.each do |geo_area|
|
||||
%li= geo_area_label(geo_area)
|
||||
|
||||
- if champ.quartiers_prioritaires?
|
||||
.areas-title Quartiers prioritaires
|
||||
.areas
|
||||
|
|
50
spec/models/geo_area_spec.rb
Normal file
50
spec/models/geo_area_spec.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
RSpec.describe GeoArea, type: :model do
|
||||
describe '#area' do
|
||||
let(:geo_area) do
|
||||
create(:geo_area, geometry: {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[2.428439855575562, 46.538476837725796],
|
||||
[2.4284291267395024, 46.53842148758162],
|
||||
[2.4282521009445195, 46.53841410755813],
|
||||
[2.42824137210846, 46.53847314771794],
|
||||
[2.428284287452698, 46.53847314771794],
|
||||
[2.428364753723145, 46.538487907747864],
|
||||
[2.4284291267395024, 46.538491597754714],
|
||||
[2.428439855575562, 46.538476837725796]
|
||||
]
|
||||
]
|
||||
})
|
||||
end
|
||||
|
||||
it { expect(geo_area.area).to eq(219.0) }
|
||||
end
|
||||
|
||||
describe '#length' do
|
||||
let(:geo_area) do
|
||||
create(:geo_area, geometry: {
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[2.4282521009445195, 46.53841410755813],
|
||||
[2.42824137210846, 46.53847314771794],
|
||||
[2.428284287452698, 46.53847314771794],
|
||||
[2.4284291267395024, 46.538491597754714]
|
||||
]
|
||||
})
|
||||
end
|
||||
|
||||
it { expect(geo_area.length).to eq(30.8) }
|
||||
end
|
||||
|
||||
describe '#location' do
|
||||
let(:geo_area) do
|
||||
create(:geo_area, geometry: {
|
||||
"type": "Point",
|
||||
"coordinates": [2.428439855575562, 46.538476837725796]
|
||||
})
|
||||
end
|
||||
|
||||
it { expect(geo_area.location).to eq("2°25'42\"N 46°32'19\"E") }
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue