Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/components/map/OlMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
</template>

<script>
import { format } from 'date-fns';

import BiodivInformation from './BiodivInformation';
import SwissProtectionAreaInformation from './SwissProtectionAreaInformation';
import { cartoLayers, dataLayers, protectionAreasLayers } from './map-layers';
Expand Down Expand Up @@ -306,7 +308,7 @@ export default {
// if, for any reason, geomtry of edited document is set, center map on it
// * new value entered in text inputs
// * first click
// * new association to route (geomtry is copied from route to outing in this case)
// * new association to route (geometry is copied from route to outing in this case)
'editedDocument.geometry.geom': {
handler(to, from) {
if (from === null && to !== null) {
Expand Down Expand Up @@ -506,9 +508,36 @@ export default {
},

setDocumentGeometryFromFeature(feature) {
this.setDocumentGeometry(this.editedDocument, feature.get('geometry'));
const geometry = feature.get('geometry');
this.setDocumentGeometry(this.editedDocument, geometry);
this.drawDocumentMarkers();
this.setDrawInteraction();
this.setOutingStartDate(this.editedDocument, geometry);
},

setOutingStartDate(document, geometry) {
if (document.type !== 'o' || document.date_start !== null) {
return;
}

const firstCoordinate = geometry.getFirstCoordinate();
let timestamp;
switch (geometry.getLayout()) {
case 'XYZM':
timestamp = firstCoordinate[3];
break;
case 'XYM':
timestamp = firstCoordinate[2];
break;
default:
return;
}

if (!timestamp) {
return;
}

document.date_start = format(new Date(timestamp * 1000), 'yyyy-MM-dd');
},

setDocumentGeometry(document, geometry) {
Expand Down