diff --git a/src/services/edition-service.js b/src/services/edition-service.js index 850bc21f9808eaf4082f4e122c9084955d0ed913..2b25a85e1ab6d97cb56daba3c53cf11de377cc19 100644 --- a/src/services/edition-service.js +++ b/src/services/edition-service.js @@ -1,4 +1,4 @@ -import { Draw } from 'ol/interaction'; +import { Draw, Snap } from 'ol/interaction'; import GeometryType from 'ol/geom/GeometryType'; import Modify from 'ol/interaction/Modify'; import Select from 'ol/interaction/Select'; @@ -267,6 +267,28 @@ const editionService = { removeActiveFeatures() { this.drawnFeature = null; this.featureToEdit = null; + }, + + addSnapInteraction(map) { + // The snap interaction must be added after the Modify and Draw interactions + // in order for its map browser event handlers to be fired first. Its handlers + // are responsible of doing the snapping. + + // Since we can't give a list of source to snap, + // we use this workaround, an interaction collection: https://github.com/openlayers/openlayers/issues/7100 + let interactions = []; + map.getLayers().forEach((layer) => { + if (layer instanceof VectorLayer) { + let interaction = new Snap({ + source: layer.getSource() + }); + interactions.push(interaction); + } + }); + + for(let snap of interactions ) { + map.addInteraction(snap); + } } }; diff --git a/src/services/map-service.js b/src/services/map-service.js index 63e4204c00689cba3b4120faf5aa77b7abc72ef1..c9f696e6a9d43d3ddcfcf928057d173bd10e2ebc 100644 --- a/src/services/map-service.js +++ b/src/services/map-service.js @@ -554,7 +554,7 @@ const mapService = { Statut : ${status} </div> <div> - Type : <a id="goToFeatureTypeDetail" class="pointer"> ${feature_type.title} </a> + Type : ${ feature_type ? '<a id="goToFeatureTypeDetail" class="pointer">' + feature_type.title + '</a>' : 'Type de signalement inconnu' } </div> <div> Dernière mise à jour : ${date_maj} diff --git a/src/views/Feature/FeatureEdit.vue b/src/views/Feature/FeatureEdit.vue index 6059ea53eff334338c572a54415fadaac7b9905b..45a27e77dee91061d9e130e3abdd18173f0c32e3 100644 --- a/src/views/Feature/FeatureEdit.vue +++ b/src/views/Feature/FeatureEdit.vue @@ -888,6 +888,7 @@ export default { )[0]; editionService.setFeatureToEdit(currentFeature); this.updateMap(currentFeature); + editionService.addSnapInteraction(this.map); } } this.mapLoading = false;