Merge pull request #5205 from betagouv/feat/5195
feat/5195 - Add 2 cards style for MapEditor + optim import gpx kml
This commit is contained in:
commit
946c564f59
3 changed files with 19 additions and 19 deletions
|
@ -8,7 +8,9 @@ import SearchInput from './SearchInput';
|
||||||
import { getJSON, ajax } from '@utils';
|
import { getJSON, ajax } from '@utils';
|
||||||
import { gpx, kml } from '@tmcw/togeojson/dist/togeojson.es.js';
|
import { gpx, kml } from '@tmcw/togeojson/dist/togeojson.es.js';
|
||||||
import ortho from '../MapStyles/ortho.json';
|
import ortho from '../MapStyles/ortho.json';
|
||||||
|
import orthoCadastre from '../MapStyles/orthoCadastre.json';
|
||||||
import vector from '../MapStyles/vector.json';
|
import vector from '../MapStyles/vector.json';
|
||||||
|
import vectorCadastre from '../MapStyles/vectorCadastre.json';
|
||||||
import { polygonCadastresFill, polygonCadastresLine } from './utils';
|
import { polygonCadastresFill, polygonCadastresLine } from './utils';
|
||||||
import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css';
|
import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css';
|
||||||
|
|
||||||
|
@ -25,7 +27,7 @@ function filterFeatureCollection(featureCollection, source) {
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
function MapEditor({ featureCollection, url, preview }) {
|
function MapEditor({ featureCollection, url, preview, hasCadastres }) {
|
||||||
const drawControl = useRef(null);
|
const drawControl = useRef(null);
|
||||||
const [style, setStyle] = useState('ortho');
|
const [style, setStyle] = useState('ortho');
|
||||||
const [coords, setCoords] = useState([1.7, 46.9]);
|
const [coords, setCoords] = useState([1.7, 46.9]);
|
||||||
|
@ -33,7 +35,12 @@ function MapEditor({ featureCollection, url, preview }) {
|
||||||
const [currentMap, setCurrentMap] = useState({});
|
const [currentMap, setCurrentMap] = useState({});
|
||||||
const [bbox, setBbox] = useState(featureCollection.bbox);
|
const [bbox, setBbox] = useState(featureCollection.bbox);
|
||||||
const [importInputs, setImportInputs] = useState([]);
|
const [importInputs, setImportInputs] = useState([]);
|
||||||
const mapStyle = style === 'ortho' ? ortho : vector;
|
let mapStyle = style === 'ortho' ? ortho : vector;
|
||||||
|
|
||||||
|
if (hasCadastres) {
|
||||||
|
mapStyle = style === 'ortho' ? orthoCadastre : vectorCadastre;
|
||||||
|
}
|
||||||
|
|
||||||
const cadastresFeatureCollection = filterFeatureCollection(
|
const cadastresFeatureCollection = filterFeatureCollection(
|
||||||
featureCollection,
|
featureCollection,
|
||||||
'cadastre'
|
'cadastre'
|
||||||
|
@ -170,26 +177,14 @@ function MapEditor({ featureCollection, url, preview }) {
|
||||||
const draw = drawControl.current.draw;
|
const draw = drawControl.current.draw;
|
||||||
const featureCollection = draw.getAll();
|
const featureCollection = draw.getAll();
|
||||||
let inputs = [...importInputs];
|
let inputs = [...importInputs];
|
||||||
let drawFeatureIdToRemove;
|
|
||||||
const inputToRemove = inputs.find((input) => input.id === inputId);
|
const inputToRemove = inputs.find((input) => input.id === inputId);
|
||||||
|
|
||||||
for (const feature of featureCollection.features) {
|
for (const feature of featureCollection.features) {
|
||||||
if (inputToRemove.featureId === feature.properties.id) {
|
if (inputToRemove.featureId === feature.properties.id) {
|
||||||
drawFeatureIdToRemove = feature.id;
|
const featureToRemove = draw.get(feature.id);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inputToRemove.featureId) {
|
|
||||||
try {
|
|
||||||
await getJSON(`${url}/${inputToRemove.featureId}`, null, 'delete');
|
await getJSON(`${url}/${inputToRemove.featureId}`, null, 'delete');
|
||||||
draw.delete(drawFeatureIdToRemove).getAll();
|
draw.delete(feature.id).getAll();
|
||||||
} catch (e) {
|
updateFeaturesList([featureToRemove]);
|
||||||
throw new Error(
|
|
||||||
`La feature ${inputToRemove.featureId} a déjà été supprimée manuellement`,
|
|
||||||
e
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
updateImportInputs(inputs, inputId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateImportInputs(inputs, inputId);
|
updateImportInputs(inputs, inputId);
|
||||||
|
@ -322,7 +317,8 @@ MapEditor.propTypes = {
|
||||||
id: PropTypes.number
|
id: PropTypes.number
|
||||||
}),
|
}),
|
||||||
url: PropTypes.string,
|
url: PropTypes.string,
|
||||||
preview: PropTypes.bool
|
preview: PropTypes.bool,
|
||||||
|
hasCadastres: PropTypes.bool
|
||||||
};
|
};
|
||||||
|
|
||||||
export default MapEditor;
|
export default MapEditor;
|
||||||
|
|
|
@ -80,6 +80,10 @@ 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
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
- if feature_enabled?(:new_map_editor)
|
- if feature_enabled?(:new_map_editor)
|
||||||
- preview = !champ.persisted?
|
- preview = !champ.persisted?
|
||||||
= react_component("MapEditor", { featureCollection: champ.to_feature_collection, url: champs_carte_features_path(preview ? 'preview' : champ), preview: preview }, class: "carte-#{champ.id}")
|
= 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}")
|
||||||
- else
|
- else
|
||||||
.toolbar
|
.toolbar
|
||||||
%button.button.primary.new-area Ajouter une zone
|
%button.button.primary.new-area Ajouter une zone
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue