Skip to content

Commit

Permalink
Merge pull request #262 from AgenceBio/maud/fix_modif_trace
Browse files Browse the repository at this point in the history
Modificaton tracé : affiche une erreur pour les parcelles avec des internal rings
  • Loading branch information
jillro authored Nov 16, 2023
2 parents 1864fe5 + ba0a3a6 commit 0b93bd5
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/pages/exploitations/[id]/modifier/[featureId].vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ meta:

<div class="fr-grid-row fr-grid-row--gutters">
<div class="fr-col-9">
<div v-if="loadingError" class="fr-alert fr-alert--error fr-my-3v">
<p>{{ loadingError }}</p>
</div>
<MapContainer v-if="recordStore.isSetup" :options="{ interactive: true }" class="map" :bounds="mapBounds" ref="map" >
<GeojsonLayer :style="baseStyle" name="base" />
<GeojsonLayer :data="otherCollection" name="parcellaire-operateur" />
Expand All @@ -34,15 +37,15 @@ meta:
<button
class="fr-btn fr-btn--tertiary-no-outline fr-btn--icon-left fr-icon-arrow-go-back-fill fr-mb-4w"
@click="reset"
:disabled="feature === null"
:disabled="loadingError || feature === null"
>
Réinitialiser le tracé</button>
<div v-if="error" class="fr-alert fr-alert--error">
<div v-if="!loadingError && error" class="fr-alert fr-alert--error">
<p>{{ error }}</p>
</div>
<button
class="fr-btn fr-btn--primary fr-btn--icon-left fr-icon-save-fill"
:disabled="error !== ''"
:disabled="error !== '' || loadingError !== ''"
@click="showConfirmModal = true"
>
Enregistrer le tracé
Expand Down Expand Up @@ -107,7 +110,7 @@ const permissions = usePermissions()
const messages = useMessages()
const router = useRouter()
const otherCollection = computed(() => featureCollection(
const otherCollection = computed(() => loadingError.value ? featureStore.collection : featureCollection(
featureStore.collection.features.filter(f => f.id !== Number(props.featureId)))
)
const modifiedFeature = ref(null)
Expand All @@ -122,6 +125,7 @@ const mapBounds = computed(() => {
const map = ref(null) // MapContainer instance
let draw // TerraDraw instance
const loadingError = ref('')
const error = ref('')
const showConfirmModal = ref(false)
Expand Down Expand Up @@ -183,7 +187,15 @@ function loadFeature () {
coord => coord.map(c => c.map(n => Number(n.toFixed(COORDINATE_PRECISION - 1))))
)
terraDrawFeature.properties.mode = 'polygon'
draw.addFeatures([terraDrawFeature])
try {
draw.addFeatures([terraDrawFeature])
} catch (e) {
if (e.message.startsWith('Feature is not')) {
loadingError.value = 'La modification de contour n’est pas encore disponible pour les parcelles évidées. Veuillez nous en excuser.'
} else {
throw e
}
}
// Clone feature to avoid modifying the featureStore
modifiedFeature.value = JSON.parse(JSON.stringify(featureStore.getFeatureById(Number(props.featureId))))
Expand Down

0 comments on commit 0b93bd5

Please sign in to comment.