Fix map apercu

This commit is contained in:
Paul Chavard 2020-05-14 13:36:25 +02:00
parent e2d72724d4
commit d44df9cc2a
2 changed files with 11 additions and 7 deletions

View file

@ -23,7 +23,9 @@ function filterFeatureCollection(featureCollection, source) {
}; };
} }
const MapEditor = ({ featureCollection, url }) => { function noop() {}
function MapEditor({ featureCollection, url, preview }) {
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]);
@ -174,9 +176,9 @@ const MapEditor = ({ featureCollection, url }) => {
/> />
<DrawControl <DrawControl
ref={drawControl} ref={drawControl}
onDrawCreate={onDrawCreate} onDrawCreate={preview ? noop : onDrawCreate}
onDrawUpdate={onDrawUpdate} onDrawUpdate={preview ? noop : onDrawUpdate}
onDrawDelete={onDrawDelete} onDrawDelete={preview ? noop : onDrawDelete}
displayControlsDefault={false} displayControlsDefault={false}
controls={{ controls={{
point: true, point: true,
@ -202,7 +204,7 @@ const MapEditor = ({ featureCollection, url }) => {
</Map> </Map>
</> </>
); );
}; }
MapEditor.propTypes = { MapEditor.propTypes = {
featureCollection: PropTypes.shape({ featureCollection: PropTypes.shape({
@ -210,7 +212,8 @@ MapEditor.propTypes = {
features: PropTypes.array, features: PropTypes.array,
id: PropTypes.number id: PropTypes.number
}), }),
url: PropTypes.string url: PropTypes.string,
preview: PropTypes.bool
}; };
export default MapEditor; export default MapEditor;

View file

@ -1,5 +1,6 @@
- if feature_enabled?(:new_map_editor) - if feature_enabled?(:new_map_editor)
= react_component("MapEditor", { featureCollection: champ.to_feature_collection, url: champs_carte_features_path(champ) }, class: "carte-#{champ.id}") - 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}")
- else - else
.toolbar .toolbar
%button.button.primary.new-area Ajouter une zone %button.button.primary.new-area Ajouter une zone