Put IGN map behind a feature flag

This commit is contained in:
Paul Chavard 2020-07-30 17:10:26 +02:00
parent f1cbc9846e
commit 4c87e547b3
6 changed files with 24 additions and 16 deletions

View file

@ -23,7 +23,7 @@ import {
const Map = ReactMapboxGl({}); const Map = ReactMapboxGl({});
function MapEditor({ featureCollection, url, preview, hasCadastres }) { function MapEditor({ featureCollection, url, preview, hasCadastres, ign }) {
const drawControl = useRef(null); const drawControl = useRef(null);
const [currentMap, setCurrentMap] = useState(null); const [currentMap, setCurrentMap] = useState(null);
@ -313,7 +313,7 @@ function MapEditor({ featureCollection, url, preview, hasCadastres }) {
trash: true trash: true
}} }}
/> />
<SwitchMapStyle style={style} setStyle={setStyle} /> <SwitchMapStyle style={style} setStyle={setStyle} ign={ign} />
<ZoomControl /> <ZoomControl />
</Map> </Map>
</> </>
@ -328,7 +328,8 @@ MapEditor.propTypes = {
}), }),
url: PropTypes.string, url: PropTypes.string,
preview: PropTypes.bool, preview: PropTypes.bool,
hasCadastres: PropTypes.bool hasCadastres: PropTypes.bool,
ign: PropTypes.bool
}; };
export default MapEditor; export default MapEditor;

View file

@ -16,7 +16,7 @@ import {
const Map = ReactMapboxGl({}); const Map = ReactMapboxGl({});
const MapReader = ({ featureCollection }) => { const MapReader = ({ featureCollection, ign }) => {
const [currentMap, setCurrentMap] = useState(null); const [currentMap, setCurrentMap] = useState(null);
const [style, setStyle] = useState('ortho'); const [style, setStyle] = useState('ortho');
const cadastresFeatureCollection = useMemo( const cadastresFeatureCollection = useMemo(
@ -184,7 +184,7 @@ const MapReader = ({ featureCollection }) => {
/> />
) : null} ) : null}
<SwitchMapStyle style={style} setStyle={setStyle} /> <SwitchMapStyle style={style} setStyle={setStyle} ign={ign} />
<ZoomControl /> <ZoomControl />
</Map> </Map>
); );
@ -195,7 +195,8 @@ MapReader.propTypes = {
type: PropTypes.string, type: PropTypes.string,
bbox: PropTypes.array, bbox: PropTypes.array,
features: PropTypes.array features: PropTypes.array
}) }),
ign: PropTypes.bool
}; };
export default MapReader; export default MapReader;

View file

@ -13,7 +13,11 @@ const STYLES = {
title: 'Vectoriel', title: 'Vectoriel',
preview: vector, preview: vector,
color: '#000' color: '#000'
}, }
};
const IGN_STYLES = {
...STYLES,
ign: { ign: {
title: 'Carte IGN', title: 'Carte IGN',
preview: vector, preview: vector,
@ -21,8 +25,8 @@ const STYLES = {
} }
}; };
function getNextStyle(style) { function getNextStyle(style, ign) {
const styles = Object.keys(STYLES); const styles = Object.keys(ign ? IGN_STYLES : STYLES);
let index = styles.indexOf(style) + 1; let index = styles.indexOf(style) + 1;
if (index === styles.length) { if (index === styles.length) {
return styles[0]; return styles[0];
@ -30,9 +34,9 @@ function getNextStyle(style) {
return styles[index]; return styles[index];
} }
export const SwitchMapStyle = ({ style, setStyle }) => { export const SwitchMapStyle = ({ style, setStyle, ign }) => {
const nextStyle = getNextStyle(style); const nextStyle = getNextStyle(style, ign);
const { title, preview, color } = STYLES[nextStyle]; const { title, preview, color } = (ign ? IGN_STYLES : STYLES)[nextStyle];
const imgStyle = { const imgStyle = {
width: '100%', width: '100%',
@ -69,5 +73,6 @@ export const SwitchMapStyle = ({ style, setStyle }) => {
SwitchMapStyle.propTypes = { SwitchMapStyle.propTypes = {
style: PropTypes.string, style: PropTypes.string,
setStyle: PropTypes.func setStyle: PropTypes.func,
ign: PropTypes.bool
}; };

View file

@ -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, ign: feature_enabled_for?(:carte_ign, champ.procedure) } )
.geo-areas .geo-areas
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, editing: false } = render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, editing: false }

View file

@ -1,5 +1,5 @@
- preview = !champ.persisted? - preview = !champ.persisted?
= 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}") = react_component("MapEditor", { featureCollection: champ.to_feature_collection, url: champs_carte_features_path(preview ? 'preview' : champ), preview: preview, hasCadastres: !!champ.cadastres?, ign: feature_enabled_for?(:carte_ign, champ.procedure) }, class: "carte-#{champ.id}")
.geo-areas .geo-areas
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, editing: true } = render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, editing: true }

View file

@ -35,7 +35,8 @@ features = [
:mini_profiler, :mini_profiler,
:operation_log_serialize_subject, :operation_log_serialize_subject,
:pre_maintenance_mode, :pre_maintenance_mode,
:xray :xray,
:carte_ign
] ]
def database_exists? def database_exists?