From 6e0d492f0077410a6836b394475c9a1b4967efc9 Mon Sep 17 00:00:00 2001 From: mahmoud adel <58145645+mahmoudadel54@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:50:29 +0300 Subject: [PATCH] #10342: Fix issue of markers are not printed correctly (#10395) (#10413) --- .../utils/styleparser/PrintStyleParser.js | 20 +++++++------ .../utils/styleparser/StyleParserUtils.js | 4 +++ .../__tests__/StyleParserUtils-test.js | 29 +++++++++++++++++-- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/web/client/utils/styleparser/PrintStyleParser.js b/web/client/utils/styleparser/PrintStyleParser.js index 97981556c3..61b83ee14e 100644 --- a/web/client/utils/styleparser/PrintStyleParser.js +++ b/web/client/utils/styleparser/PrintStyleParser.js @@ -13,7 +13,8 @@ import { geoStylerStyleFilter, drawWellKnownNameImageFromSymbolizer, drawIcons, - parseSymbolizerExpressions + parseSymbolizerExpressions, + getCachedImageById } from './StyleParserUtils'; import { geometryFunctionsLibrary } from './GeometryFunctionsUtils'; import { circleToPolygon } from '../DrawGeometryUtils'; @@ -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); @@ -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; @@ -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); @@ -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) => { @@ -250,7 +252,7 @@ export const getPrintStyleFuncFromRules = (geoStylerStyle) => { }, properties: { ...feature?.properties, - ms_style: symbolizerToPrintMSStyle(additionalSymbolizer, feature, layer) + ms_style: symbolizerToPrintMSStyle(additionalSymbolizer, feature, layer, _additionalSymbolizer) } }; } diff --git a/web/client/utils/styleparser/StyleParserUtils.js b/web/client/utils/styleparser/StyleParserUtils.js index a14efc5735..44ebbef85a 100644 --- a/web/client/utils/styleparser/StyleParserUtils.js +++ b/web/client/utils/styleparser/StyleParserUtils.js @@ -931,3 +931,7 @@ export const drawIcons = (geoStylerStyle, options) => { }) ); }; +export const getCachedImageById = (symbolizer) => { + const id = getImageIdFromSymbolizer(symbolizer); + return imagesCache[id] || {}; +}; diff --git a/web/client/utils/styleparser/__tests__/StyleParserUtils-test.js b/web/client/utils/styleparser/__tests__/StyleParserUtils-test.js index 8a8e0847c0..3340e09b9e 100644 --- a/web/client/utils/styleparser/__tests__/StyleParserUtils-test.js +++ b/web/client/utils/styleparser/__tests__/StyleParserUtils-test.js @@ -12,7 +12,8 @@ import { drawIcons, geoStylerStyleFilter, getWellKnownNameImageFromSymbolizer, - parseSymbolizerExpressions + parseSymbolizerExpressions, + getCachedImageById } from '../StyleParserUtils'; describe("StyleParserUtils ", () => { @@ -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); + }); });