-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GSLUX-704: Save drawn features #135
Conversation
GitHub Pages links: * Luxembourg-geoportail: https://geoportail-luxembourg.github.io/luxembourg-geoportail/GSLUX-704-draw-end/ |
f6f570c
to
46ae810
Compare
Style decoding form short URL format to mymaps format is done via helper file. |
src/composables/draw/draw-utils.ts
Outdated
// TODO 3D | ||
// const ARROW_MODEL_URL = import.meta.env.VITE_ARROW_MODEL_URL | ||
|
||
export function createStyleFunction(curMap: OlMap) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rework this, seperate default style, style for point and style for label, style for selectiion, etc... the v3 code is not very clear, it is hard to tell what style is for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
partly done,
common state of type DrawnFeature[]
feature.set('shape', 'circle') | ||
feature.set('isLabel', drawStateActive.value === 'drawLabel') | ||
feature.setStyle(createStyleFunction(map)) | ||
feature.set('display_order', nbFeatures) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: put all this definition in a wrapper dedicated to v4 containing these info and the ol feature geom. To be discussed together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work! working great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rquesting changes after a second review. There is rework todoregarding the implementation, we should not use ol objects to store infos (name, width, etc...). Plus, there is a lot of copy/paste from v3, the goal of v4 is to make things clearer and simpler, using vue states/stores etc...
b75683d
to
9fc0e3e
Compare
for demo, the link below can be used: It contains some styled features created with v3 and some features created with v4.
|
src/services/state-persistor/state-persistor-features.mapper.ts
Outdated
Show resolved
Hide resolved
src/services/state-persistor/state-persistor-features.mapper.ts
Outdated
Show resolved
Hide resolved
src/services/state-persistor/state-persistor-features.mapper.ts
Outdated
Show resolved
Hide resolved
src/services/state-persistor/state-persistor-features.service.ts
Outdated
Show resolved
Hide resolved
src/services/state-persistor/state-persistor-features.service.ts
Outdated
Show resolved
Hide resolved
import Style from 'ol/style/Style.js' | ||
import { createStyleFunction } from '@/composables/draw/draw-utils' | ||
|
||
const GeometryTypeValues = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redefining types again? src/services/state-persistor/utils/GeometryTypes.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inline because it is a non reusable v3 component
|
||
/** | ||
* @type {Object.<ol.geom.GeometryType, FeatureHashStyleType>} | ||
* @private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why @private
?
* @type {Object.<string, string>} | ||
* @private | ||
*/ | ||
let FeatureHashLegacyProperties: any = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we provide a better typing than any? what about the jsdoc above saying <string, string>?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the moment, I made a linter exception because it was a big piece of code to port to TS
…s and in the map layer
8161c5d
to
1ae46a7
Compare
class DrawnFeature extends Feature
* fix circle e2e test * fix the e2e tests * re-fix * fix types
*/ | ||
public getType(feature: Feature) { | ||
const geometry = feature.getGeometry() | ||
console.assert(geometry, 'Geometry should be thruthy') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use console.assert in v4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does is matter ?
it was a goog assert and I wanted to preserve the verification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes code quality matters
…ding algorithm, to be able to add guards or useful help comments later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your huge effort on refactoring and finishing this PR @mki-c2c !
// // TODO: to improve saving | ||
// const geomType = feature.getGeometry()?.getType() | ||
|
||
// const newFeature = createDrawnFeature(feature) | ||
|
||
// // if (geomType) { | ||
// // const newFeature = { | ||
// // // TODO: improve feat. creation, move this creation elsewhere | ||
// // id: Math.floor(Math.random() * Date.now()), | ||
// // label: `${geomType as string} ${drawnFeatures.value.length + 1}`, | ||
// // featureType: feature.get('isCircle') | ||
// // ? 'drawnCircle' | ||
// // : feature.get('isLabel') | ||
// // ? 'drawnLabel' | ||
// // : `drawn${geomType.replace('String', '')}`, | ||
// // olFeature: feature, | ||
// // } as unknown as DrawFeature | ||
// if (newFeature) { | ||
// drawnFeatures.value = [...drawnFeatures.value, newFeature] | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get rid of this now?
// function getName(feature: Feature<Geometry>) { | ||
// if (feature?.getGeometry()?.getType() === 'Circle') { | ||
// const featureGeom = feature.getGeometry() as Circle | ||
// feature.set('isCircle', true) | ||
// feature.setGeometry(fromCircle(featureGeom, 64)) | ||
// } | ||
|
||
// let name | ||
// switch (feature.getGeometry()?.getType()) { | ||
// case 'Point': { | ||
// if (drawStateActive.value === 'drawLabel') { | ||
// name = t('Label', { ns: 'client' }) | ||
// } else { | ||
// name = t('Point', { ns: 'client' }) | ||
// } | ||
// break | ||
// } | ||
// case 'LineString': { | ||
// const curLineStringGeom = feature.getGeometry() as LineString | ||
// const curLineStringCooridnates = curLineStringGeom.getCoordinates() | ||
// if (curLineStringCooridnates.length < 2) { | ||
// return | ||
// } | ||
// const prevCoord = | ||
// curLineStringCooridnates[curLineStringCooridnates.length - 1] | ||
// const antePrevCoord = | ||
// curLineStringCooridnates[curLineStringCooridnates.length - 2] | ||
// if ( | ||
// prevCoord[0] === antePrevCoord[0] && | ||
// prevCoord[1] === antePrevCoord[1] | ||
// ) { | ||
// curLineStringCooridnates.pop() | ||
// if (curLineStringCooridnates.length < 2) { | ||
// return | ||
// } | ||
// curLineStringGeom.setCoordinates(curLineStringCooridnates) | ||
// } | ||
// name = t('LineString', { ns: 'client' }) | ||
// break | ||
// } | ||
// case 'Polygon': { | ||
// if (feature.get('isCircle')) { | ||
// name = t('Circle', { ns: 'client' }) | ||
// } else { | ||
// const featureGeom = feature.getGeometry() as Polygon | ||
// if (featureGeom.getLinearRing(0)!.getCoordinates().length < 4) { | ||
// return | ||
// } | ||
// name = t('Polygon', { ns: 'client' }) | ||
// } | ||
// break | ||
// } | ||
// default: | ||
// name = feature.getGeometry()?.getType() | ||
// break | ||
// } | ||
// return name | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this remain a to-do?
JIRA issue
https://jira.camptocamp.com/browse/GSLUX-704
Description
This PR implements the logic for saving drawn features and persisting them in the URI. It is still WIP. Persisting and restoring is functional, except for a remaining issue that the restored feature is not yet displayed on the map according to its properties. The persist step can also be tested by copying the
features=...
queryParam to the prod instance where the features are displayed in the according "style". (Note that the style encoding/decoding in the code is not used for this, but the style should work based on the properties).To-dos for this PR include:
utils
folder was taken and adapted from v3. It could possibly be better integrated into the v4 architecture.FeatureHash
FeatureHash
and to let state persistor take care of this.Future to-dos that depend on other features and can not yet be covered by this PR are:
selectedFeatures
) => GSLUX-705