Add RPG carte source
This commit is contained in:
parent
7ffbe417f9
commit
5a8a4b393f
12 changed files with 71 additions and 5 deletions
|
@ -46,6 +46,14 @@ class Champs::CarteController < ApplicationController
|
|||
qp
|
||||
end
|
||||
end
|
||||
|
||||
if @champ.parcelles_agricoles?
|
||||
parcelles_agricoles = ModuleApiCartoService.generate_rpg(geo_json)
|
||||
geo_areas += parcelles_agricoles.map do |parcelle_agricole|
|
||||
parcelle_agricole[:source] = GeoArea.sources.fetch(:parcelle_agricole)
|
||||
parcelle_agricole
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@champ.geo_areas = geo_areas.map do |geo_area|
|
||||
|
|
|
@ -10,7 +10,8 @@ module ChampHelper
|
|||
position: champ.position,
|
||||
selection: champ.value.present? ? JSON.parse(champ.value) : [],
|
||||
quartiersPrioritaires: champ.quartiers_prioritaires? ? champ.quartiers_prioritaires : [],
|
||||
cadastres: champ.cadastres? ? champ.cadastres : []
|
||||
cadastres: champ.cadastres? ? champ.cadastres : [],
|
||||
parcellesAgricoles: champ.parcelles_agricoles? ? champ.parcelles_agricoles : []
|
||||
}.to_json)
|
||||
# rubocop:enable Rails/OutputSafety
|
||||
end
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
geocodeAddress,
|
||||
drawCadastre,
|
||||
drawQuartiersPrioritaires,
|
||||
drawParcellesAgricoles,
|
||||
drawUserSelection,
|
||||
addFreeDrawEvents
|
||||
} from '../../shared/carte';
|
||||
|
@ -30,6 +31,7 @@ function diplayMap(element, data, initial = false) {
|
|||
// draw external polygons
|
||||
drawCadastre(map, data, editable);
|
||||
drawQuartiersPrioritaires(map, data, editable);
|
||||
drawParcellesAgricoles(map, data, editable);
|
||||
|
||||
// draw user polygon
|
||||
if (initial) {
|
||||
|
|
|
@ -57,6 +57,19 @@ export function drawQuartiersPrioritaires(
|
|||
);
|
||||
}
|
||||
|
||||
export function drawParcellesAgricoles(
|
||||
map,
|
||||
{ parcellesAgricoles },
|
||||
editable = false
|
||||
) {
|
||||
drawLayer(
|
||||
map,
|
||||
parcellesAgricoles,
|
||||
editable ? RPG_POLYGON_STYLE : noEditStyle(RPG_POLYGON_STYLE),
|
||||
'parcellesAgricoles'
|
||||
);
|
||||
}
|
||||
|
||||
export function drawUserSelection(map, { selection }, editable = false) {
|
||||
let hasSelection = selection && selection.length > 0;
|
||||
|
||||
|
@ -170,6 +183,10 @@ const QP_POLYGON_STYLE = Object.assign({}, POLYGON_STYLE, {
|
|||
fillColor: '#31708f'
|
||||
});
|
||||
|
||||
const RPG_POLYGON_STYLE = Object.assign({}, POLYGON_STYLE, {
|
||||
fillColor: '#31708f'
|
||||
});
|
||||
|
||||
delegate('click', '.carte.edit', event => {
|
||||
let element = event.target;
|
||||
let isPath = element.matches('.leaflet-container g path');
|
||||
|
|
|
@ -15,6 +15,12 @@ class Champs::CarteChamp < Champ
|
|||
end
|
||||
end
|
||||
|
||||
def parcelles_agricoles
|
||||
geo_areas.select do |area|
|
||||
area.source == GeoArea.sources.fetch(:parcelle_agricole)
|
||||
end
|
||||
end
|
||||
|
||||
def cadastres?
|
||||
type_de_champ&.cadastres && type_de_champ.cadastres != '0'
|
||||
end
|
||||
|
@ -23,6 +29,10 @@ class Champs::CarteChamp < Champ
|
|||
type_de_champ&.quartiers_prioritaires && type_de_champ.quartiers_prioritaires != '0'
|
||||
end
|
||||
|
||||
def parcelles_agricoles?
|
||||
type_de_champ&.parcelles_agricoles && type_de_champ.parcelles_agricoles != '0'
|
||||
end
|
||||
|
||||
def position
|
||||
if dossier.present?
|
||||
dossier.geo_position
|
||||
|
|
|
@ -13,14 +13,20 @@ class GeoArea < ApplicationRecord
|
|||
:code_arr,
|
||||
:code,
|
||||
:nom,
|
||||
:commune
|
||||
:commune,
|
||||
:culture,
|
||||
:code_culture,
|
||||
:surface,
|
||||
:bio
|
||||
]
|
||||
|
||||
enum source: {
|
||||
quartier_prioritaire: 'quartier_prioritaire',
|
||||
cadastre: 'cadastre'
|
||||
cadastre: 'cadastre',
|
||||
parcelle_agricole: 'parcelle_agricole'
|
||||
}
|
||||
|
||||
scope :quartiers_prioritaires, -> { where(source: sources.fetch(:quartier_prioritaire)) }
|
||||
scope :cadastres, -> { where(source: sources.fetch(:cadastre)) }
|
||||
scope :parcelles_agricoles, -> { where(source: sources.fetch(:parcelle_agricole)) }
|
||||
end
|
||||
|
|
|
@ -31,7 +31,7 @@ class TypeDeChamp < ApplicationRecord
|
|||
|
||||
belongs_to :procedure
|
||||
|
||||
store :options, accessors: [:cadastres, :quartiers_prioritaires]
|
||||
store :options, accessors: [:cadastres, :quartiers_prioritaires, :parcelles_agricoles]
|
||||
|
||||
after_initialize :set_dynamic_type
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ class TypesDeChampService
|
|||
:piece_justificative_template,
|
||||
:quartiers_prioritaires,
|
||||
:cadastres,
|
||||
:parcelles_agricoles,
|
||||
drop_down_list_attributes: [:value, :id]
|
||||
])
|
||||
|
||||
|
|
|
@ -47,6 +47,10 @@
|
|||
%label
|
||||
= ff.check_box :cadastres
|
||||
Cadastre
|
||||
%br
|
||||
%label
|
||||
= ff.check_box :parcelles_agricoles
|
||||
Parcelles Agricoles
|
||||
|
||||
- hide_mandatory = (ff.object.object.private? || type_champ == TypeDeChamp.type_champs.fetch(:explication))
|
||||
.form-group.mandatory{ style: hide_mandatory ? 'visibility: hidden;' : nil }
|
||||
|
|
|
@ -25,3 +25,17 @@
|
|||
%ul
|
||||
- champ.cadastres.each do |pc|
|
||||
%li Parcelle n° #{pc.numero} - Feuille #{pc.code_arr} #{pc.section} #{pc.feuille}
|
||||
|
||||
- if champ.parcelles_agricoles?
|
||||
.areas-title Parcelles agricoles (RPG)
|
||||
.areas
|
||||
- if error.present?
|
||||
.error Merci de dessiner une surface plus petite afin de récupérer les parcelles agricoles.
|
||||
- elsif champ.value.blank?
|
||||
Aucune zone tracée
|
||||
- elsif champ.parcelles_agricoles.blank?
|
||||
= t('errors.messages.parcelles_agricoles_empty', count: champ.zones.size)
|
||||
- else
|
||||
%ul
|
||||
- champ.parcelles_agricoles.each do |pa|
|
||||
%li Culture : #{pa.culture} - Surface : #{pa.surface} ha
|
||||
|
|
|
@ -183,6 +183,9 @@ fr:
|
|||
quartiers_prioritaires_empty:
|
||||
one: "Aucun quartier prioritaire sur la zone séléctionnée"
|
||||
other: "Aucun quartier prioritaire sur les zones séléctionnées"
|
||||
parcelles_agricoles_empty:
|
||||
one: "Aucune parcelle agricole sur la zone séléctionnée"
|
||||
other: "Aucune parcelle agricole sur les zones séléctionnées"
|
||||
|
||||
date:
|
||||
abbr_day_names:
|
||||
|
|
|
@ -36,7 +36,7 @@ describe Champs::CarteController, type: :controller do
|
|||
context 'when coordinates are empty' do
|
||||
let(:selection) { [] }
|
||||
|
||||
it { expect(response.body).to include("DS.drawMapData(\".carte-1\", {\"position\":{\"lon\":\"2.428462\",\"lat\":\"46.538192\",\"zoom\":\"13\"},\"selection\":[],\"quartiersPrioritaires\":[],\"cadastres\":[]});") }
|
||||
it { expect(response.body).to include("DS.drawMapData(\".carte-1\", {\"position\":{\"lon\":\"2.428462\",\"lat\":\"46.538192\",\"zoom\":\"13\"},\"selection\":[],\"quartiersPrioritaires\":[],\"cadastres\":[],\"parcellesAgricoles\":[]});") }
|
||||
end
|
||||
|
||||
context 'when coordinates are informed' do
|
||||
|
|
Loading…
Reference in a new issue