Skip to content
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

Fix/1450 arrow save #1454

Merged
merged 2 commits into from
Jan 18, 2024
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
54 changes: 37 additions & 17 deletions new-client/src/models/DrawModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,21 +416,32 @@ class DrawModel {
};

#setFeatureZIndex = (feature, zIndex) => {
let style = feature.getStyle();
style = Array.isArray(style) ? style[0] : style;
if (style) {
style.setZIndex(zIndex);
feature.setStyle(style);
let styles = feature.getStyle();

if (styles) {
styles = Array.isArray(styles) ? styles : [styles];
styles.map((style) => {
style.setZIndex(zIndex);
return style;
});

feature.setStyle(styles);
}
};

#getFeatureZIndex = (feature) => {
let style = feature.getStyle();
if (style) {
style = Array.isArray(style) ? style[0] : style;
return style.getZIndex() || 0;
let styles = feature.getStyle();
let zIndex = 0;
if (styles) {
styles = Array.isArray(styles) ? styles : [styles];
styles.forEach((style) => {
let zi = style.getZIndex() || 0;
if (zi > zIndex) {
zIndex = zi;
}
});
}
return 0;
return zIndex;
};

// Returns the style that should be used on the drawn features
Expand Down Expand Up @@ -641,6 +652,14 @@ class DrawModel {
})
);
});

const zIndex = this.#getFeatureZIndex(feature);
styles.map((style) => {
// make sure we get the correct zIndex for all styles.
style.setZIndex(zIndex);
return style;
});

// And finally return the style-array.
return styles;
};
Expand Down Expand Up @@ -1100,7 +1119,12 @@ class DrawModel {
// If no feature was supplied, or if we're unable to extract the style,
// we return null.
if (!featureStyle) {
return { fillStyle: null, strokeStyle: null, imageStyle: null };
return {
fillStyle: null,
strokeStyle: null,
imageStyle: null,
zIndex: 0,
};
}
// If we were able to extract the style we can continue by extracting
// the fill- and stroke-style.
Expand Down Expand Up @@ -1904,13 +1928,9 @@ class DrawModel {
if (extractedStyle) {
// apply style
let style = this.#getFeatureStyle(feature, extractedStyle);
if (!style.getZIndex()) {
// getZIndex() returns 0 if not set
// force a zIndex if missing, for later use.
style.setZIndex(this.#lastZIndex);
this.#lastZIndex++;
}
feature.setStyle(style);
// Set correct zIndex or fallback to 0.
this.#setFeatureZIndex(feature, extractedStyle.zIndex || 0);
}

// When we're done styling we can add the feature.
Expand Down