Skip to content

Commit

Permalink
feat(yeti): Preserve current route
Browse files Browse the repository at this point in the history
  • Loading branch information
iamvdo committed Nov 7, 2024
1 parent 701fd89 commit 7e93c68
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/components/yeti/Yetix.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import axios from 'axios';
import Vue from 'vue';
import ol from '@/js/libs/ol';
let defaultState = {
API_URL: 'https://api.ensg.eu/',
BLEND_MODES_CLASS_NAME: 'areas',
Expand Down Expand Up @@ -310,9 +312,24 @@ export default new Vue({
},
setFeatures(features) {
state.features = features;
// store features in localstorage
let coords = features.map((feature) => {
return feature
.getGeometry()
.getCoordinates()
.map((coords) => {
// round coords to 1 meter
return [Math.round(coords[0]), Math.round(coords[1]), Math.round(coords[2])];
});
});
this.$localStorage.set('yeti-map-features', coords);
},
setFeaturesTitle(featuresTitle) {
state.featuresTitle = featuresTitle;
// store features title in localstorage
this.$localStorage.set('yeti-map-features-title', featuresTitle);
},
setFeaturesLength(featuresLength) {
state.featuresLength = featuresLength;
Expand Down Expand Up @@ -439,6 +456,18 @@ export default new Vue({
this.setShowRomma(mapOverlays.romma);
this.setShowFlowcapt(mapOverlays.flowcapt);
this.setShowFfvl(mapOverlays.ffvl);
// features (routeLayer)
// first, get saved features
let savedFeatures = this.$localStorage
.get('yeti-map-features', [])
.map((feature) => new ol.Feature(new ol.geom.LineString(feature)));
// if data, set features/featuresTitle
if (savedFeatures.length) {
this.setFeatures(savedFeatures);
let featuresTitle = this.$localStorage.get('yeti-map-features-title', state.featuresTitle);
this.setFeaturesTitle(featuresTitle);
}
},
setOverlaysToLocalStorage(overlay) {
let overlays = this.$localStorage.get('yeti-map-layers-overlays', {});
Expand Down
6 changes: 6 additions & 0 deletions src/components/yeti/map-layers/RouteLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ export default {
Yetix.$on('simplify', this.simplify);
Yetix.$on('featureUpdated', this.updateFeaturesFromStore);
Yetix.$on('fit-map-to-features', this.fitMapToFeatures);
// already features to add?
// but not a c2c document
if (!doc && this.features.length) {
this.featuresLayerSource.addFeatures(this.features);
}
},
methods: {
getLayer() {
Expand Down

0 comments on commit 7e93c68

Please sign in to comment.