Skip to content

Commit

Permalink
#10342: Fix issue of markers are not printed correctly (#10395) (#10413)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoudadel54 authored Jun 10, 2024
1 parent 71ba5ad commit 6e0d492
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
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 @@ -931,3 +931,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);
});
});

0 comments on commit 6e0d492

Please sign in to comment.