Remove legacy carto
This commit is contained in:
parent
c4c1c971ca
commit
901b6e23a8
17 changed files with 10 additions and 572 deletions
|
@ -1,45 +1,6 @@
|
||||||
class Champs::CarteController < ApplicationController
|
class Champs::CarteController < ApplicationController
|
||||||
before_action :authenticate_logged_user!
|
before_action :authenticate_logged_user!
|
||||||
|
|
||||||
ERROR_GEO_JSON = ''
|
|
||||||
|
|
||||||
def show
|
|
||||||
@selector = ".carte-#{params[:position]}"
|
|
||||||
|
|
||||||
feature_collection = if params[:dossier].key?(:champs_attributes)
|
|
||||||
params[:dossier][:champs_attributes][params[:position]][:value]
|
|
||||||
else
|
|
||||||
params[:dossier][:champs_private_attributes][params[:position]][:value]
|
|
||||||
end
|
|
||||||
|
|
||||||
@champ = if params[:champ_id].present?
|
|
||||||
policy_scope(Champ).find(params[:champ_id])
|
|
||||||
else
|
|
||||||
policy_scope(TypeDeChamp).find(params[:type_de_champ_id]).champ.build
|
|
||||||
end
|
|
||||||
|
|
||||||
geo_areas = []
|
|
||||||
|
|
||||||
if feature_collection == ERROR_GEO_JSON
|
|
||||||
@error = true
|
|
||||||
else
|
|
||||||
feature_collection = JSON.parse(feature_collection, symbolize_names: true)
|
|
||||||
|
|
||||||
if @champ.cadastres?
|
|
||||||
populate_cadastres(feature_collection)
|
|
||||||
end
|
|
||||||
|
|
||||||
geo_areas = GeoArea.from_feature_collection(feature_collection)
|
|
||||||
end
|
|
||||||
|
|
||||||
if @champ.persisted?
|
|
||||||
@champ.update(value: nil, geo_areas: geo_areas)
|
|
||||||
end
|
|
||||||
rescue ApiCarto::API::ResourceNotFound
|
|
||||||
flash.alert = 'Les données cartographiques sont temporairement indisponibles. Réessayez dans un instant.'
|
|
||||||
response.status = 503
|
|
||||||
end
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@selector = ".carte-#{params[:champ_id]}"
|
@selector = ".carte-#{params[:champ_id]}"
|
||||||
@champ = policy_scope(Champ).find(params[:champ_id])
|
@champ = policy_scope(Champ).find(params[:champ_id])
|
||||||
|
@ -90,26 +51,6 @@ class Champs::CarteController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def populate_cadastres(feature_collection)
|
|
||||||
coordinates = feature_collection[:features].filter do |feature|
|
|
||||||
feature[:geometry][:type] == 'Polygon'
|
|
||||||
end.map do |feature|
|
|
||||||
feature[:geometry][:coordinates][0].map { |(lng, lat)| { 'lng' => lng, 'lat' => lat } }
|
|
||||||
end
|
|
||||||
|
|
||||||
if coordinates.present?
|
|
||||||
cadastres = ApiCartoService.generate_cadastre(coordinates)
|
|
||||||
|
|
||||||
feature_collection[:features] += cadastres.map do |cadastre|
|
|
||||||
{
|
|
||||||
type: 'Feature',
|
|
||||||
geometry: cadastre.delete(:geometry),
|
|
||||||
properties: cadastre.merge(source: GeoArea.sources.fetch(:cadastre))
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def params_feature
|
def params_feature
|
||||||
params[:feature]
|
params[:feature]
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,12 +4,6 @@ module ChampHelper
|
||||||
!types_without_label.include?(champ.type_champ)
|
!types_without_label.include?(champ.type_champ)
|
||||||
end
|
end
|
||||||
|
|
||||||
def geo_data(champ)
|
|
||||||
# rubocop:disable Rails/OutputSafety
|
|
||||||
raw(champ.to_render_data.to_json)
|
|
||||||
# rubocop:enable Rails/OutputSafety
|
|
||||||
end
|
|
||||||
|
|
||||||
def champ_carte_params(champ)
|
def champ_carte_params(champ)
|
||||||
if champ.persisted?
|
if champ.persisted?
|
||||||
{ champ_id: champ.id }
|
{ champ_id: champ.id }
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
async function initialize() {
|
|
||||||
const elements = document.querySelectorAll('.carte');
|
|
||||||
|
|
||||||
if (elements.length) {
|
|
||||||
for (let element of elements) {
|
|
||||||
loadAndDrawMap(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadAndDrawMap(element) {
|
|
||||||
const data = JSON.parse(element.dataset.geo);
|
|
||||||
const editable = element.classList.contains('edit');
|
|
||||||
|
|
||||||
if (editable) {
|
|
||||||
const { drawEditableMap } = await import('../../shared/carte-editor');
|
|
||||||
|
|
||||||
drawEditableMap(element, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadAndRedrawMap(element, data) {
|
|
||||||
const { redrawMap } = await import('../../shared/carte-editor');
|
|
||||||
|
|
||||||
redrawMap(element, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
addEventListener('DOMContentLoaded', initialize);
|
|
||||||
|
|
||||||
addEventListener('carte:update', ({ detail: { selector, data } }) => {
|
|
||||||
const element = document.querySelector(selector);
|
|
||||||
|
|
||||||
loadAndRedrawMap(element, data);
|
|
||||||
});
|
|
|
@ -24,7 +24,6 @@ import '../new_design/support';
|
||||||
import '../new_design/dossiers/auto-save';
|
import '../new_design/dossiers/auto-save';
|
||||||
import '../new_design/dossiers/auto-upload';
|
import '../new_design/dossiers/auto-upload';
|
||||||
|
|
||||||
import '../new_design/champs/carte';
|
|
||||||
import '../new_design/champs/linked-drop-down-list';
|
import '../new_design/champs/linked-drop-down-list';
|
||||||
import '../new_design/champs/repetition';
|
import '../new_design/champs/repetition';
|
||||||
|
|
||||||
|
|
|
@ -1,220 +0,0 @@
|
||||||
import L from 'leaflet';
|
|
||||||
import FreeDraw from 'leaflet-freedraw';
|
|
||||||
import area from '@turf/area';
|
|
||||||
import { fire, delegate } from '@utils';
|
|
||||||
import $ from 'jquery';
|
|
||||||
|
|
||||||
import createFeatureCollection from './create-feature-collection';
|
|
||||||
|
|
||||||
const MAPS = new WeakMap();
|
|
||||||
|
|
||||||
export function drawEditableMap(element, data) {
|
|
||||||
const map = initMap(element, data);
|
|
||||||
|
|
||||||
drawCadastre(map, data);
|
|
||||||
drawQuartiersPrioritaires(map, data);
|
|
||||||
drawParcellesAgricoles(map, data);
|
|
||||||
|
|
||||||
drawUserSelectionEditor(map, data);
|
|
||||||
|
|
||||||
const input = element.parentElement.querySelector('input[data-remote]');
|
|
||||||
addFreeDrawEvents(map, input);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function redrawMap(element, data) {
|
|
||||||
const map = initMap(element, data);
|
|
||||||
|
|
||||||
clearLayers(map);
|
|
||||||
|
|
||||||
drawCadastre(map, data);
|
|
||||||
drawQuartiersPrioritaires(map, data);
|
|
||||||
drawParcellesAgricoles(map, data);
|
|
||||||
|
|
||||||
bringToFrontUserSelection(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
function initMap(element, { position }) {
|
|
||||||
if (MAPS.has(element)) {
|
|
||||||
return MAPS.get(element);
|
|
||||||
} else {
|
|
||||||
const map = L.map(element, {
|
|
||||||
scrollWheelZoom: false
|
|
||||||
}).setView([position.lat, position.lon], 18);
|
|
||||||
|
|
||||||
const loadTilesLayer = process.env.RAILS_ENV != 'test';
|
|
||||||
if (loadTilesLayer) {
|
|
||||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
||||||
attribution:
|
|
||||||
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
|
||||||
}).addTo(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
const freeDraw = new FreeDraw({
|
|
||||||
mode: FreeDraw.NONE,
|
|
||||||
smoothFactor: 4,
|
|
||||||
mergePolygons: false
|
|
||||||
});
|
|
||||||
map.addLayer(freeDraw);
|
|
||||||
map.freeDraw = freeDraw;
|
|
||||||
|
|
||||||
MAPS.set(element, map);
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function toLatLngs({ coordinates }) {
|
|
||||||
return coordinates.map((polygon) =>
|
|
||||||
polygon[0].map((point) => L.GeoJSON.coordsToLatLng(point))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawUserSelectionEditor(map, { selection }) {
|
|
||||||
if (selection) {
|
|
||||||
const geoJSON = L.geoJSON(selection);
|
|
||||||
|
|
||||||
for (let polygon of toLatLngs(selection)) {
|
|
||||||
map.freeDraw.create(polygon);
|
|
||||||
}
|
|
||||||
|
|
||||||
map.fitBounds(geoJSON.getBounds());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function addFreeDrawEvents(map, selector) {
|
|
||||||
const input = findInput(selector);
|
|
||||||
|
|
||||||
map.freeDraw.on('markers', ({ latLngs }) => {
|
|
||||||
if (latLngs.length === 0) {
|
|
||||||
input.value = EMPTY_GEO_JSON;
|
|
||||||
} else {
|
|
||||||
const featureCollection = createFeatureCollection(latLngs);
|
|
||||||
|
|
||||||
if (area(featureCollection) < 300000) {
|
|
||||||
input.value = JSON.stringify(featureCollection);
|
|
||||||
} else {
|
|
||||||
input.value = ERROR_GEO_JSON;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fire(input, 'change');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawCadastre(map, { cadastres }) {
|
|
||||||
drawLayer(map, cadastres, CADASTRE_POLYGON_STYLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawQuartiersPrioritaires(map, { quartiersPrioritaires }) {
|
|
||||||
drawLayer(map, quartiersPrioritaires, QP_POLYGON_STYLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawParcellesAgricoles(map, { parcellesAgricoles }) {
|
|
||||||
drawLayer(map, parcellesAgricoles, RPG_POLYGON_STYLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCurrentMap(element) {
|
|
||||||
if (!element.matches('.carte')) {
|
|
||||||
const closestCarteElement = element.closest('.carte');
|
|
||||||
const closestToolbarElement = element.closest('.toolbar');
|
|
||||||
|
|
||||||
element = closestCarteElement
|
|
||||||
? closestCarteElement
|
|
||||||
: closestToolbarElement.parentElement.querySelector('.carte');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MAPS.has(element)) {
|
|
||||||
return MAPS.get(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const EMPTY_GEO_JSON = '{ "type": "FeatureCollection", "features": [] }';
|
|
||||||
const ERROR_GEO_JSON = '';
|
|
||||||
|
|
||||||
function findInput(selector) {
|
|
||||||
return typeof selector === 'string'
|
|
||||||
? document.querySelector(selector)
|
|
||||||
: selector;
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearLayers(map) {
|
|
||||||
map.eachLayer((layer) => {
|
|
||||||
if (layer instanceof L.GeoJSON) {
|
|
||||||
map.removeLayer(layer);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function bringToFrontUserSelection(map) {
|
|
||||||
for (let layer of map.freeDraw.all()) {
|
|
||||||
layer.bringToFront();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawLayer(map, data, style) {
|
|
||||||
if (Array.isArray(data) && data.length > 0) {
|
|
||||||
const layer = new L.GeoJSON(undefined, {
|
|
||||||
interactive: false,
|
|
||||||
style
|
|
||||||
});
|
|
||||||
|
|
||||||
for (let { geometry } of data) {
|
|
||||||
layer.addData(geometry);
|
|
||||||
}
|
|
||||||
|
|
||||||
layer.addTo(map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const POLYGON_STYLE = {
|
|
||||||
weight: 2,
|
|
||||||
opacity: 0.3,
|
|
||||||
color: 'white',
|
|
||||||
dashArray: '3',
|
|
||||||
fillOpacity: 0.7
|
|
||||||
};
|
|
||||||
|
|
||||||
const CADASTRE_POLYGON_STYLE = Object.assign({}, POLYGON_STYLE, {
|
|
||||||
fillColor: '#8a6d3b'
|
|
||||||
});
|
|
||||||
|
|
||||||
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) => {
|
|
||||||
const map = getCurrentMap(event.target);
|
|
||||||
|
|
||||||
if (map) {
|
|
||||||
const isPath = event.target.matches('.leaflet-container g path');
|
|
||||||
if (isPath) {
|
|
||||||
setTimeout(() => {
|
|
||||||
map.freeDraw.mode(FreeDraw.EDIT | FreeDraw.DELETE);
|
|
||||||
}, 50);
|
|
||||||
} else {
|
|
||||||
map.freeDraw.mode(FreeDraw.NONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
delegate('click', '.toolbar .new-area', (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
const map = getCurrentMap(event.target);
|
|
||||||
|
|
||||||
if (map) {
|
|
||||||
map.freeDraw.mode(FreeDraw.CREATE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('select2:select', 'select[data-address]', (event) => {
|
|
||||||
const map = getCurrentMap(event.target);
|
|
||||||
const { geometry } = event.params.data;
|
|
||||||
|
|
||||||
if (map && geometry && geometry.type === 'Point') {
|
|
||||||
const [lon, lat] = geometry.coordinates;
|
|
||||||
map.setView(new L.LatLng(lat, lon), 14);
|
|
||||||
}
|
|
||||||
});
|
|
|
@ -1,19 +0,0 @@
|
||||||
export default function createFeatureCollection(latLngs) {
|
|
||||||
return {
|
|
||||||
type: 'FeatureCollection',
|
|
||||||
features: latLngs.map(featurePolygonLatLngs)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function featurePolygonLatLngs(latLngs) {
|
|
||||||
return {
|
|
||||||
type: 'Feature',
|
|
||||||
properties: {
|
|
||||||
source: 'selection_utilisateur'
|
|
||||||
},
|
|
||||||
geometry: {
|
|
||||||
type: 'Polygon',
|
|
||||||
coordinates: [latLngs.map(({ lng, lat }) => [lng, lat])]
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -80,10 +80,6 @@ class Champs::CarteChamp < Champ
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_cadastres?
|
|
||||||
cadastres? ? true : false
|
|
||||||
end
|
|
||||||
|
|
||||||
def geometry?
|
def geometry?
|
||||||
geo_areas.present?
|
geo_areas.present?
|
||||||
end
|
end
|
||||||
|
@ -98,16 +94,6 @@ class Champs::CarteChamp < Champ
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_render_data
|
|
||||||
{
|
|
||||||
position: position,
|
|
||||||
selection: selection_utilisateur_legacy_geometry,
|
|
||||||
quartiersPrioritaires: quartiers_prioritaires? ? quartiers_prioritaires.as_json(except: :properties) : [],
|
|
||||||
cadastres: cadastres? ? cadastres.as_json(except: :properties) : [],
|
|
||||||
parcellesAgricoles: parcelles_agricoles? ? parcelles_agricoles.as_json(except: :properties) : []
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def for_api
|
def for_api
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<%= render_to_element("#{@selector} + .geo-areas",
|
<%= render_to_element("#{@selector} + .geo-areas",
|
||||||
partial: 'shared/champs/carte/geo_areas',
|
partial: 'shared/champs/carte/geo_areas',
|
||||||
locals: { champ: @champ, error: @error }) %>
|
locals: { champ: @champ }) %>
|
||||||
|
|
||||||
<% if @update_cadastres %>
|
<% if @update_cadastres %>
|
||||||
<%= fire_event('cadastres:update', { featureCollection: @champ.to_feature_collection }.to_json) %>
|
<%= fire_event('cadastres:update', { featureCollection: @champ.to_feature_collection }.to_json) %>
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
<%= render_flash(timeout: 5000, fixed: true) %>
|
|
||||||
|
|
||||||
<%= render_to_element("#{@selector} + .geo-areas",
|
|
||||||
partial: 'shared/champs/carte/geo_areas',
|
|
||||||
locals: { champ: @champ, error: @error }) %>
|
|
||||||
|
|
||||||
<%= fire_event('carte:update', { selector: @selector, data: @champ.to_render_data }.to_json) %>
|
|
|
@ -8,9 +8,7 @@
|
||||||
- if champ.quartiers_prioritaires?
|
- if champ.quartiers_prioritaires?
|
||||||
.areas-title Quartiers prioritaires
|
.areas-title Quartiers prioritaires
|
||||||
.areas
|
.areas
|
||||||
- if error.present?
|
- if !champ.geometry?
|
||||||
.error Merci de dessiner une surface plus petite afin de récupérer les quartiers prioritaires.
|
|
||||||
- elsif !champ.geometry?
|
|
||||||
Aucune zone tracée
|
Aucune zone tracée
|
||||||
- elsif champ.quartiers_prioritaires.blank?
|
- elsif champ.quartiers_prioritaires.blank?
|
||||||
= t('errors.messages.quartiers_prioritaires_empty', count: champ.selections_utilisateur.size)
|
= t('errors.messages.quartiers_prioritaires_empty', count: champ.selections_utilisateur.size)
|
||||||
|
@ -22,9 +20,7 @@
|
||||||
- if champ.cadastres?
|
- if champ.cadastres?
|
||||||
.areas-title Parcelles cadastrales
|
.areas-title Parcelles cadastrales
|
||||||
.areas
|
.areas
|
||||||
- if error.present?
|
- if !champ.geometry?
|
||||||
.error Merci de dessiner une surface plus petite afin de récupérer les parcelles cadastrales.
|
|
||||||
- elsif !champ.geometry?
|
|
||||||
Aucune zone tracée
|
Aucune zone tracée
|
||||||
- elsif champ.cadastres.blank?
|
- elsif champ.cadastres.blank?
|
||||||
= t('errors.messages.cadastres_empty', count: champ.selections_utilisateur.size)
|
= t('errors.messages.cadastres_empty', count: champ.selections_utilisateur.size)
|
||||||
|
@ -36,9 +32,7 @@
|
||||||
- if champ.parcelles_agricoles?
|
- if champ.parcelles_agricoles?
|
||||||
.areas-title Parcelles agricoles (RPG)
|
.areas-title Parcelles agricoles (RPG)
|
||||||
.areas
|
.areas
|
||||||
- if error.present?
|
- if !champ.geometry?
|
||||||
.error Merci de dessiner une surface plus petite afin de récupérer les parcelles agricoles.
|
|
||||||
- elsif !champ.geometry?
|
|
||||||
Aucune zone tracée
|
Aucune zone tracée
|
||||||
- elsif champ.parcelles_agricoles.blank?
|
- elsif champ.parcelles_agricoles.blank?
|
||||||
= t('errors.messages.parcelles_agricoles_empty', count: champ.selections_utilisateur.size)
|
= t('errors.messages.parcelles_agricoles_empty', count: champ.selections_utilisateur.size)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
- if champ.geometry?
|
- if champ.geometry?
|
||||||
= react_component("MapReader", { featureCollection: champ.to_feature_collection } )
|
= react_component("MapReader", { featureCollection: champ.to_feature_collection } )
|
||||||
.geo-areas
|
.geo-areas
|
||||||
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, error: false }
|
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ }
|
||||||
|
|
|
@ -1,14 +1,5 @@
|
||||||
- if feature_enabled?(:new_map_editor)
|
|
||||||
- preview = !champ.persisted?
|
- preview = !champ.persisted?
|
||||||
= react_component("MapEditor", { featureCollection: champ.to_feature_collection, hasCadastres: champ.has_cadastres?, url: champs_carte_features_path(preview ? 'preview' : champ), preview: preview }, class: "carte-#{champ.id}")
|
= react_component("MapEditor", { featureCollection: champ.to_feature_collection, url: champs_carte_features_path(preview ? 'preview' : champ), preview: preview, hasCadastres: !!champ.cadastres? }, class: "carte-#{champ.id}")
|
||||||
- else
|
|
||||||
.toolbar
|
|
||||||
%button.button.primary.new-area Ajouter une zone
|
|
||||||
%select.select2.adresse{ data: { address: true }, placeholder: 'Saisissez une adresse ou positionner la carte' }
|
|
||||||
.carte.edit{ data: { geo: geo_data(champ) }, class: "carte-#{form.index}" }
|
|
||||||
|
|
||||||
= form.hidden_field :value,
|
|
||||||
data: { remote: true, feature_collection_id: champ.stable_id, url: champs_carte_path(form.index), params: champ_carte_params(champ).to_query, method: 'post' }
|
|
||||||
|
|
||||||
.geo-areas
|
.geo-areas
|
||||||
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, error: false }
|
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ }
|
||||||
|
|
|
@ -31,7 +31,6 @@ features = [
|
||||||
:insee_api_v3,
|
:insee_api_v3,
|
||||||
:instructeur_bypass_email_login_token,
|
:instructeur_bypass_email_login_token,
|
||||||
:autosave_dossier_draft,
|
:autosave_dossier_draft,
|
||||||
:new_map_editor,
|
|
||||||
:maintenance_mode,
|
:maintenance_mode,
|
||||||
:mini_profiler,
|
:mini_profiler,
|
||||||
:operation_log_serialize_subject,
|
:operation_log_serialize_subject,
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
"@reach/combobox": "^0.10.2",
|
"@reach/combobox": "^0.10.2",
|
||||||
"@sentry/browser": "^5.15.5",
|
"@sentry/browser": "^5.15.5",
|
||||||
"@tmcw/togeojson": "^4.0.0",
|
"@tmcw/togeojson": "^4.0.0",
|
||||||
"@turf/area": "^6.0.1",
|
|
||||||
"babel-plugin-macros": "^2.8.0",
|
"babel-plugin-macros": "^2.8.0",
|
||||||
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
|
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
|
||||||
"chartkick": "^3.2.0",
|
"chartkick": "^3.2.0",
|
||||||
|
@ -23,8 +22,6 @@
|
||||||
"highcharts": "^8.1.0",
|
"highcharts": "^8.1.0",
|
||||||
"intersection-observer": "^0.10.0",
|
"intersection-observer": "^0.10.0",
|
||||||
"jquery": "^3.5.1",
|
"jquery": "^3.5.1",
|
||||||
"leaflet": "^1.6.0",
|
|
||||||
"leaflet-freedraw": "^2.12.0",
|
|
||||||
"mapbox-gl": "^1.10.0",
|
"mapbox-gl": "^1.10.0",
|
||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
|
|
|
@ -18,6 +18,7 @@ describe Champs::CarteController, type: :controller do
|
||||||
cadastres: true
|
cadastres: true
|
||||||
}).champ.create(dossier: dossier)
|
}).champ.create(dossier: dossier)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'features' do
|
describe 'features' do
|
||||||
let(:feature) { attributes_for(:geo_area, :polygon) }
|
let(:feature) { attributes_for(:geo_area, :polygon) }
|
||||||
let(:geo_area) { create(:geo_area, :selection_utilisateur, :polygon, champ: champ) }
|
let(:geo_area) { create(:geo_area, :selection_utilisateur, :polygon, champ: champ) }
|
||||||
|
@ -138,103 +139,4 @@ describe Champs::CarteController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #show' do
|
|
||||||
render_views
|
|
||||||
|
|
||||||
context 'when the API is available' do
|
|
||||||
render_views
|
|
||||||
|
|
||||||
before do
|
|
||||||
sign_in user
|
|
||||||
|
|
||||||
allow_any_instance_of(ApiCarto::CadastreAdapter)
|
|
||||||
.to receive(:results)
|
|
||||||
.and_return([{ code: "QPCODE1234", surface_parcelle: 4, geometry: { type: "MultiPolygon", coordinates: [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061], [2.38724851642620, 48.8721392348064], [2.38715792094576, 48.8723062632126]]]] } }])
|
|
||||||
|
|
||||||
post :show, params: params, format: 'js'
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when coordinates are empty' do
|
|
||||||
let(:value) do
|
|
||||||
{
|
|
||||||
type: 'FeatureCollection',
|
|
||||||
features: []
|
|
||||||
}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
it {
|
|
||||||
expect(assigns(:error)).to eq(nil)
|
|
||||||
expect(champ.reload.value).to eq(nil)
|
|
||||||
expect(champ.reload.geo_areas).to eq([])
|
|
||||||
expect(response.body).to include("DS.fire('carte:update'")
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when coordinates are informed' do
|
|
||||||
let(:value) do
|
|
||||||
{
|
|
||||||
type: 'FeatureCollection',
|
|
||||||
features: [
|
|
||||||
{
|
|
||||||
type: 'Feature',
|
|
||||||
properties: {
|
|
||||||
source: 'selection_utilisateur'
|
|
||||||
},
|
|
||||||
geometry: { type: 'Polygon', coordinates: [[[2.3859214782714844, 48.87442541960633], [2.3850631713867183, 48.87273183590832], [2.3809432983398438, 48.87081237174292], [2.377510070800781, 48.8712640169951], [2.3859214782714844, 48.87442541960633]]] }
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
it {
|
|
||||||
expect(response.body).not_to be_nil
|
|
||||||
expect(response.body).to include('MultiPolygon')
|
|
||||||
expect(response.body).to include('[2.38715792094576,48.8723062632126]')
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when error' do
|
|
||||||
let(:value) { '' }
|
|
||||||
|
|
||||||
it {
|
|
||||||
expect(assigns(:error)).to eq(true)
|
|
||||||
expect(champ.reload.value).to eq(nil)
|
|
||||||
expect(champ.reload.geo_areas).to eq([])
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the API is unavailable' do
|
|
||||||
before do
|
|
||||||
sign_in user
|
|
||||||
|
|
||||||
allow_any_instance_of(ApiCarto::CadastreAdapter)
|
|
||||||
.to receive(:results)
|
|
||||||
.and_raise(ApiCarto::API::ResourceNotFound)
|
|
||||||
|
|
||||||
post :show, params: params, format: 'js'
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:value) do
|
|
||||||
{
|
|
||||||
type: 'FeatureCollection',
|
|
||||||
features: [
|
|
||||||
{
|
|
||||||
type: 'Feature',
|
|
||||||
properties: {
|
|
||||||
source: 'selection_utilisateur'
|
|
||||||
},
|
|
||||||
geometry: { type: 'Polygon', coordinates: [[[2.3859214782714844, 48.87442541960633], [2.3850631713867183, 48.87273183590832], [2.3809432983398438, 48.87081237174292], [2.377510070800781, 48.8712640169951], [2.3859214782714844, 48.87442541960633]]] }
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
it {
|
|
||||||
expect(response.status).to eq 503
|
|
||||||
expect(response.body).to include('Les données cartographiques sont temporairement indisponibles')
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,34 +15,6 @@ describe Champs::CarteChamp do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#to_render_data' do
|
|
||||||
subject { champ.to_render_data }
|
|
||||||
|
|
||||||
let(:render_data) {
|
|
||||||
{
|
|
||||||
position: champ.position,
|
|
||||||
selection: selection,
|
|
||||||
cadastres: [],
|
|
||||||
parcellesAgricoles: [],
|
|
||||||
quartiersPrioritaires: []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
context 'when has no geo_areas' do
|
|
||||||
let(:geo_areas) { [] }
|
|
||||||
let(:selection) { nil }
|
|
||||||
|
|
||||||
it { is_expected.to eq(render_data) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when has one geo_area' do
|
|
||||||
let(:geo_areas) { [build(:geo_area, :selection_utilisateur, geometry: geo_json)] }
|
|
||||||
let(:selection) { legacy_geo_json }
|
|
||||||
|
|
||||||
it { is_expected.to eq(render_data) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#to_feature_collection' do
|
describe '#to_feature_collection' do
|
||||||
subject { champ.to_feature_collection }
|
subject { champ.to_feature_collection }
|
||||||
|
|
||||||
|
|
59
yarn.lock
59
yarn.lock
|
@ -1193,14 +1193,6 @@
|
||||||
resolved "https://registry.yarnpkg.com/@tmcw/togeojson/-/togeojson-4.0.0.tgz#ee111e4e5b2b5d498d43e27a6c9bf546ce4041cc"
|
resolved "https://registry.yarnpkg.com/@tmcw/togeojson/-/togeojson-4.0.0.tgz#ee111e4e5b2b5d498d43e27a6c9bf546ce4041cc"
|
||||||
integrity sha512-JZXGC1myBPPYb/moq03cYPtErqZKzVR74Cv9C85IuqATHCxHCNOxw4D45vVcYHQnnxG2TQTIR+igzpbFiu/O6Q==
|
integrity sha512-JZXGC1myBPPYb/moq03cYPtErqZKzVR74Cv9C85IuqATHCxHCNOxw4D45vVcYHQnnxG2TQTIR+igzpbFiu/O6Q==
|
||||||
|
|
||||||
"@turf/area@^6.0.1":
|
|
||||||
version "6.0.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/@turf/area/-/area-6.0.1.tgz#50ed63c70ef2bdb72952384f1594319d94f3b051"
|
|
||||||
integrity sha512-Zv+3N1ep9P5JvR0YOYagLANyapGWQBh8atdeR3bKpWcigVXFsEKNUw03U/5xnh+cKzm7yozHD6MFJkqQv55y0g==
|
|
||||||
dependencies:
|
|
||||||
"@turf/helpers" "6.x"
|
|
||||||
"@turf/meta" "6.x"
|
|
||||||
|
|
||||||
"@turf/bbox@4.7.3":
|
"@turf/bbox@4.7.3":
|
||||||
version "4.7.3"
|
version "4.7.3"
|
||||||
resolved "https://registry.yarnpkg.com/@turf/bbox/-/bbox-4.7.3.tgz#e3ad4f10a7e9b41b522880d33083198199059067"
|
resolved "https://registry.yarnpkg.com/@turf/bbox/-/bbox-4.7.3.tgz#e3ad4f10a7e9b41b522880d33083198199059067"
|
||||||
|
@ -1213,18 +1205,6 @@
|
||||||
resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-4.7.3.tgz#bc312ac43cab3c532a483151c4c382c5649429e9"
|
resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-4.7.3.tgz#bc312ac43cab3c532a483151c4c382c5649429e9"
|
||||||
integrity sha1-vDEqxDyrPFMqSDFRxMOCxWSUKek=
|
integrity sha1-vDEqxDyrPFMqSDFRxMOCxWSUKek=
|
||||||
|
|
||||||
"@turf/helpers@6.x":
|
|
||||||
version "6.1.4"
|
|
||||||
resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-6.1.4.tgz#d6fd7ebe6782dd9c87dca5559bda5c48ae4c3836"
|
|
||||||
integrity sha512-vJvrdOZy1ngC7r3MDA7zIGSoIgyrkWcGnNIEaqn/APmw+bVLF2gAW7HIsdTxd12s5wQMqEpqIQrmrbRRZ0xC7g==
|
|
||||||
|
|
||||||
"@turf/meta@6.x":
|
|
||||||
version "6.0.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-6.0.2.tgz#eb92951126d24a613ac1b7b99d733fcc20fd30cf"
|
|
||||||
integrity sha512-VA7HJkx7qF1l3+GNGkDVn2oXy4+QoLP6LktXAaZKjuT1JI0YESat7quUkbCMy4zP9lAUuvS4YMslLyTtr919FA==
|
|
||||||
dependencies:
|
|
||||||
"@turf/helpers" "6.x"
|
|
||||||
|
|
||||||
"@turf/meta@^4.7.3":
|
"@turf/meta@^4.7.3":
|
||||||
version "4.7.4"
|
version "4.7.4"
|
||||||
resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-4.7.4.tgz#6de2f1e9890b8f64b669e4b47c09b20893063977"
|
resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-4.7.4.tgz#6de2f1e9890b8f64b669e4b47c09b20893063977"
|
||||||
|
@ -2444,11 +2424,6 @@ cli-width@^2.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.1.tgz#b0433d0b4e9c847ef18868a4ef16fd5fc8271c48"
|
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.1.tgz#b0433d0b4e9c847ef18868a4ef16fd5fc8271c48"
|
||||||
integrity sha512-GRMWDxpOB6Dgk2E5Uo+3eEBvtOOlimMmpbFiKuLFnQzYDavtLFY3K5ona41jgN/WdRZtG7utuVSVTL4HbZHGkw==
|
integrity sha512-GRMWDxpOB6Dgk2E5Uo+3eEBvtOOlimMmpbFiKuLFnQzYDavtLFY3K5ona41jgN/WdRZtG7utuVSVTL4HbZHGkw==
|
||||||
|
|
||||||
clipper-lib@~6.2.1:
|
|
||||||
version "6.2.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/clipper-lib/-/clipper-lib-6.2.1.tgz#266d8ec7575c589f05f23e9cd003de50e23117b6"
|
|
||||||
integrity sha1-Jm2Ox1dcWJ8F8j6c0APeUOIxF7Y=
|
|
||||||
|
|
||||||
cliui@^4.0.0:
|
cliui@^4.0.0:
|
||||||
version "4.1.0"
|
version "4.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/cliui/-/cliui-4.1.0.tgz#348422dbe82d800b3022eef4f6ac10bf2e4d1b49"
|
resolved "https://registry.yarnpkg.com/cliui/-/cliui-4.1.0.tgz#348422dbe82d800b3022eef4f6ac10bf2e4d1b49"
|
||||||
|
@ -5391,11 +5366,6 @@ jsprim@^1.2.2:
|
||||||
json-schema "0.2.3"
|
json-schema "0.2.3"
|
||||||
verror "1.10.0"
|
verror "1.10.0"
|
||||||
|
|
||||||
jsts@1.1.2:
|
|
||||||
version "1.1.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/jsts/-/jsts-1.1.2.tgz#d205d2cc8393081d9e484ae36282110695edc230"
|
|
||||||
integrity sha1-0gXSzIOTCB2eSErjYoIRBpXtwjA=
|
|
||||||
|
|
||||||
jsx-ast-utils@^2.2.3:
|
jsx-ast-utils@^2.2.3:
|
||||||
version "2.2.3"
|
version "2.2.3"
|
||||||
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-2.2.3.tgz#8a9364e402448a3ce7f14d357738310d9248054f"
|
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-2.2.3.tgz#8a9364e402448a3ce7f14d357738310d9248054f"
|
||||||
|
@ -5482,21 +5452,6 @@ lead@^1.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
flush-write-stream "^1.0.2"
|
flush-write-stream "^1.0.2"
|
||||||
|
|
||||||
leaflet-freedraw@^2.12.0:
|
|
||||||
version "2.13.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/leaflet-freedraw/-/leaflet-freedraw-2.13.0.tgz#aa5b621eaadaabe2ef34f474bb8ab2b4a645ffa1"
|
|
||||||
integrity sha512-OJ/PBkb71x9Ja29CvE2BAMq4tK8LuNy86Nx8ta6AYWGUu4p47rDanxZ4s0bo7TTo609ophbrsO0LObz6yLFPSQ==
|
|
||||||
dependencies:
|
|
||||||
clipper-lib "~6.2.1"
|
|
||||||
regenerator-runtime "^0.13.2"
|
|
||||||
turf-intersect "~3.0.12"
|
|
||||||
turf-polygon "~1.0.3"
|
|
||||||
|
|
||||||
leaflet@^1.6.0:
|
|
||||||
version "1.6.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.6.0.tgz#aecbb044b949ec29469eeb31c77a88e2f448f308"
|
|
||||||
integrity sha512-CPkhyqWUKZKFJ6K8umN5/D2wrJ2+/8UIpXppY7QDnUZW5bZL5+SEI2J7GBpwh4LIupOKqbNSQXgqmrEJopHVNQ==
|
|
||||||
|
|
||||||
leven@^3.1.0:
|
leven@^3.1.0:
|
||||||
version "3.1.0"
|
version "3.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2"
|
resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2"
|
||||||
|
@ -7845,7 +7800,7 @@ regenerate@^1.4.0:
|
||||||
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11"
|
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11"
|
||||||
integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg==
|
integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg==
|
||||||
|
|
||||||
regenerator-runtime@^0.13.2, regenerator-runtime@^0.13.4, regenerator-runtime@^0.13.5:
|
regenerator-runtime@^0.13.4, regenerator-runtime@^0.13.5:
|
||||||
version "0.13.5"
|
version "0.13.5"
|
||||||
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz#d878a1d094b4306d10b9096484b33ebd55e26697"
|
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz#d878a1d094b4306d10b9096484b33ebd55e26697"
|
||||||
integrity sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA==
|
integrity sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA==
|
||||||
|
@ -9182,18 +9137,6 @@ tunnel-agent@^0.6.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
safe-buffer "^5.0.1"
|
safe-buffer "^5.0.1"
|
||||||
|
|
||||||
turf-intersect@~3.0.12:
|
|
||||||
version "3.0.12"
|
|
||||||
resolved "https://registry.yarnpkg.com/turf-intersect/-/turf-intersect-3.0.12.tgz#c0d7fb305843a19275670057a39d268b17830d83"
|
|
||||||
integrity sha1-wNf7MFhDoZJ1ZwBXo50mixeDDYM=
|
|
||||||
dependencies:
|
|
||||||
jsts "1.1.2"
|
|
||||||
|
|
||||||
turf-polygon@~1.0.3:
|
|
||||||
version "1.0.3"
|
|
||||||
resolved "https://registry.yarnpkg.com/turf-polygon/-/turf-polygon-1.0.3.tgz#671dd34849864509281af18e236f67a7448c6363"
|
|
||||||
integrity sha1-Zx3TSEmGRQkoGvGOI29np0SMY2M=
|
|
||||||
|
|
||||||
tweetnacl@^0.14.3, tweetnacl@~0.14.0:
|
tweetnacl@^0.14.3, tweetnacl@~0.14.0:
|
||||||
version "0.14.5"
|
version "0.14.5"
|
||||||
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
|
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
|
||||||
|
|
Loading…
Reference in a new issue