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

#10342: Fix issue of markers are not printed correctly #10395

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 11 additions & 9 deletions web/client/utils/styleparser/PrintStyleParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
geoStylerStyleFilter,
drawWellKnownNameImageFromSymbolizer,
drawIcons,
parseSymbolizerExpressions
parseSymbolizerExpressions,
getCachedImageById
} from './StyleParserUtils';
import { geometryFunctionsLibrary } from './GeometryFunctionsUtils';
import { circleToPolygon } from '../DrawGeometryUtils';
Expand Down Expand Up @@ -70,7 +71,7 @@ const anchorToLabelAlign = (anchor) => {
}
};

const symbolizerToPrintMSStyle = (symbolizer, feature, layer) => {
const symbolizerToPrintMSStyle = (symbolizer, feature, layer, originalSymbolizer) => {
const globalOpacity = layer.opacity === undefined ? 1 : layer.opacity;
if (symbolizer.kind === 'Mark') {
const { width, height, canvas } = drawWellKnownNameImageFromSymbolizer(symbolizer);
Expand All @@ -85,7 +86,7 @@ const symbolizerToPrintMSStyle = (symbolizer, feature, layer) => {
};
}
if (symbolizer.kind === 'Icon') {
const { width = symbolizer.size, height = symbolizer.size } = drawWellKnownNameImageFromSymbolizer(symbolizer);
const { width = symbolizer.size, height = symbolizer.size } = getCachedImageById(originalSymbolizer);
const aspect = width / height;
let iconSizeW = symbolizer.size;
let iconSizeH = iconSizeW / aspect;
Expand Down Expand Up @@ -207,11 +208,12 @@ export const getPrintStyleFuncFromRules = (geoStylerStyle) => {
: true)
)
);
const originalSymbolizer = circleGeometrySymbolizers[circleGeometrySymbolizers.length - 1]
|| pointGeometrySymbolizers[pointGeometrySymbolizers.length - 1]
|| polylineGeometrySymbolizers[polylineGeometrySymbolizers.length - 1]
|| polygonGeometrySymbolizers[polygonGeometrySymbolizers.length - 1];

const symbolizer = parseSymbolizerExpressions(circleGeometrySymbolizers[circleGeometrySymbolizers.length - 1]
|| pointGeometrySymbolizers[pointGeometrySymbolizers.length - 1]
|| polylineGeometrySymbolizers[polylineGeometrySymbolizers.length - 1]
|| polygonGeometrySymbolizers[polygonGeometrySymbolizers.length - 1], feature);
const symbolizer = parseSymbolizerExpressions(originalSymbolizer, feature);

let geometry = feature.geometry;
const geometryFunction = getGeometryFunction(symbolizer);
Expand All @@ -233,7 +235,7 @@ export const getPrintStyleFuncFromRules = (geoStylerStyle) => {
geometry,
properties: {
...feature?.properties,
ms_style: symbolizerToPrintMSStyle(symbolizer, feature, layer)
ms_style: symbolizerToPrintMSStyle(symbolizer, feature, layer, originalSymbolizer)
}
},
...additionalPointSymbolizers.map((_additionalSymbolizer) => {
Expand All @@ -250,7 +252,7 @@ export const getPrintStyleFuncFromRules = (geoStylerStyle) => {
},
properties: {
...feature?.properties,
ms_style: symbolizerToPrintMSStyle(additionalSymbolizer, feature, layer)
ms_style: symbolizerToPrintMSStyle(additionalSymbolizer, feature, layer, _additionalSymbolizer)
}
};
}
Expand Down
4 changes: 4 additions & 0 deletions web/client/utils/styleparser/StyleParserUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -933,3 +933,7 @@ export const drawIcons = (geoStylerStyle, options) => {
})
);
};
export const getCachedImageById = (symbolizer) => {
const id = getImageIdFromSymbolizer(symbolizer);
return imagesCache[id] || {};
};
29 changes: 27 additions & 2 deletions web/client/utils/styleparser/__tests__/StyleParserUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
drawIcons,
geoStylerStyleFilter,
getWellKnownNameImageFromSymbolizer,
parseSymbolizerExpressions
parseSymbolizerExpressions,
getCachedImageById
} from '../StyleParserUtils';

describe("StyleParserUtils ", () => {
Expand Down Expand Up @@ -236,5 +237,29 @@ describe("StyleParserUtils ", () => {
outlineDasharray: [ 10, 10 ]
});
});

it('test getCachedImageById method for Icon annotationSymbolizer to return width, height = size in case of returning undefined from getCachedImageById', () => {
const annotationSymbolizer = {
"symbolizerId": "5ba7eae188a0",
"kind": "Icon",
"image": {
"name": "msMarkerIcon",
"args": [
{
"color": "blue",
"shape": "circle",
"glyph": "comment"
}
]
},
"opacity": 1,
"size": 46,
"rotate": 0,
"msBringToFront": false,
"anchor": "bottom",
"msHeightReference": "none"
};
const { width = annotationSymbolizer.size, height = annotationSymbolizer.size } = getCachedImageById(annotationSymbolizer);
expect(width).toBe(annotationSymbolizer.size);
expect(height).toBe(annotationSymbolizer.size);
});
});
Loading