2020-04-07 18:17:30 +02:00
|
|
|
import React from 'react';
|
|
|
|
import ReactMapboxGl, { ZoomControl, GeoJSONLayer } from 'react-mapbox-gl';
|
2020-04-09 17:32:20 +02:00
|
|
|
import mapboxgl from 'mapbox-gl';
|
2020-04-07 18:17:30 +02:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
const Map = ReactMapboxGl({});
|
|
|
|
|
2020-04-09 17:32:20 +02:00
|
|
|
const MapReader = ({ featureCollection }) => {
|
|
|
|
const [a1, a2, b1, b2] = featureCollection.bbox;
|
|
|
|
const boundData = [
|
|
|
|
[a1, a2],
|
|
|
|
[b1, b2]
|
|
|
|
];
|
2020-04-07 18:17:30 +02:00
|
|
|
|
2020-04-09 17:32:20 +02:00
|
|
|
const selectionsFeatureCollection = {
|
|
|
|
type: 'FeatureCollection',
|
|
|
|
features: []
|
|
|
|
};
|
|
|
|
const cadastresFeatureCollection = {
|
|
|
|
type: 'FeatureCollection',
|
|
|
|
features: []
|
2020-04-07 18:17:30 +02:00
|
|
|
};
|
|
|
|
|
2020-04-09 17:32:20 +02:00
|
|
|
for (let feature of featureCollection.features) {
|
|
|
|
switch (feature.properties.source) {
|
|
|
|
case 'selection_utilisateur':
|
|
|
|
selectionsFeatureCollection.features.push(feature);
|
|
|
|
break;
|
|
|
|
case 'cadastre':
|
|
|
|
cadastresFeatureCollection.features.push(feature);
|
|
|
|
break;
|
2020-04-07 18:17:30 +02:00
|
|
|
}
|
2020-04-09 17:32:20 +02:00
|
|
|
}
|
2020-04-07 18:17:30 +02:00
|
|
|
|
|
|
|
const polygonSelectionFill = {
|
|
|
|
'fill-color': '#EC3323',
|
|
|
|
'fill-opacity': 0.5
|
|
|
|
};
|
|
|
|
|
|
|
|
const polygonSelectionLine = {
|
|
|
|
'line-color': 'rgba(255, 0, 0, 1)',
|
|
|
|
'line-width': 4
|
|
|
|
};
|
|
|
|
|
|
|
|
const polygonCadastresFill = {
|
|
|
|
'fill-color': '#9CA090',
|
|
|
|
'fill-opacity': 0.5
|
|
|
|
};
|
|
|
|
|
|
|
|
const polygonCadastresLine = {
|
|
|
|
'line-color': 'rgba(156, 160, 144, 255)',
|
|
|
|
'line-width': 2,
|
|
|
|
'line-dasharray': [1, 1]
|
|
|
|
};
|
|
|
|
|
2020-04-07 18:20:53 +02:00
|
|
|
if (!mapboxgl.supported()) {
|
|
|
|
return (
|
|
|
|
<p>
|
|
|
|
Nous ne pouvons pas afficher la carte car elle est imcompatible avec
|
|
|
|
votre navigateur. Nous vous conseillons de le mettre à jour ou utiliser
|
|
|
|
les dernières versions de Chrome, Firefox ou Safari
|
|
|
|
</p>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-07 18:17:30 +02:00
|
|
|
return (
|
|
|
|
<Map
|
|
|
|
fitBounds={boundData}
|
|
|
|
fitBoundsOptions={{ padding: 100 }}
|
|
|
|
style="https://openmaptiles.geo.data.gouv.fr/styles/osm-bright/style.json"
|
|
|
|
containerStyle={{
|
|
|
|
height: '400px',
|
|
|
|
width: '100%'
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<GeoJSONLayer
|
2020-04-09 17:32:20 +02:00
|
|
|
data={selectionsFeatureCollection}
|
2020-04-07 18:17:30 +02:00
|
|
|
fillPaint={polygonSelectionFill}
|
|
|
|
linePaint={polygonSelectionLine}
|
|
|
|
/>
|
|
|
|
<GeoJSONLayer
|
2020-04-09 17:32:20 +02:00
|
|
|
data={cadastresFeatureCollection}
|
2020-04-07 18:17:30 +02:00
|
|
|
fillPaint={polygonCadastresFill}
|
|
|
|
linePaint={polygonCadastresLine}
|
|
|
|
/>
|
|
|
|
<ZoomControl />
|
|
|
|
</Map>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
MapReader.propTypes = {
|
2020-04-09 17:32:20 +02:00
|
|
|
featureCollection: PropTypes.shape({
|
|
|
|
type: PropTypes.string,
|
|
|
|
bbox: PropTypes.array,
|
|
|
|
features: PropTypes.array
|
2020-04-07 18:17:30 +02:00
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
export default MapReader;
|