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 #9653 with cesium marker #9776

Merged
merged 2 commits into from
Nov 30, 2023
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
4 changes: 2 additions & 2 deletions web/client/utils/styleparser/CesiumStyleParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ const getGraphics = ({
const symbolizer = parseSymbolizerExpressions(_symbolizer, { properties });
if (symbolizer.kind === 'Mark') {
modifyPointHeight({ entity, symbolizer });
const { image, width, height } = images.find(({ id }) => id === getImageIdFromSymbolizer(symbolizer)) || {};
const { image, width, height } = images.find(({ id }) => id === getImageIdFromSymbolizer(symbolizer, _symbolizer)) || {};
if (image) {
const side = width > height ? width : height;
const scale = (symbolizer.radius * 2) / side;
Expand Down Expand Up @@ -375,7 +375,7 @@ const getGraphics = ({
}
if (symbolizer.kind === 'Icon') {
modifyPointHeight({ entity, symbolizer });
const { image, width, height } = images.find(({ id }) => id === getImageIdFromSymbolizer(symbolizer)) || {};
const { image, width, height } = images.find(({ id }) => id === getImageIdFromSymbolizer(symbolizer, _symbolizer)) || {};
if (image) {
const side = width > height ? width : height;
const scale = symbolizer.size / side;
Expand Down
6 changes: 3 additions & 3 deletions web/client/utils/styleparser/LeafletStyleParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function getStyleFuncFromRules({ rules: geoStylerStyleRules = [] }) {
const pointToLayer = ({ symbolizer: _symbolizer, latlng, feature }) => {
const symbolizer = parseSymbolizerExpressions(_symbolizer, feature);
if (symbolizer.kind === 'Mark') {
const { image, src, width, height } = images.find(({ id }) => id === getImageIdFromSymbolizer(symbolizer)) || {};
const { image, src, width, height } = images.find(({ id }) => id === getImageIdFromSymbolizer(symbolizer, _symbolizer)) || {};
if (image) {
const aspect = width / height;
const size = symbolizer.radius * 2;
Expand All @@ -125,7 +125,7 @@ function getStyleFuncFromRules({ rules: geoStylerStyleRules = [] }) {
}
}
if (symbolizer.kind === 'Icon') {
const { image, src, width, height } = images.find(({ id }) => id === getImageIdFromSymbolizer(symbolizer)) || {};
const { image, src, width, height } = images.find(({ id }) => id === getImageIdFromSymbolizer(symbolizer, _symbolizer)) || {};
if (image) {
const aspect = width / height;
let iconSizeW = symbolizer.size;
Expand Down Expand Up @@ -158,7 +158,7 @@ function getStyleFuncFromRules({ rules: geoStylerStyleRules = [] }) {
font-style: ${symbolizer.fontStyle || 'normal'};
font-weight: ${symbolizer.fontWeight || 'normal'};
font-size: ${symbolizer.size}px;

position: absolute;
transform: translate(calc(${anchorH} + ${symbolizer?.offset?.[0] ?? 0}px), calc(${anchorV} + ${symbolizer?.offset?.[1] ?? 0}px)) rotateZ(${symbolizer?.rotate ?? 0}deg);

Expand Down
8 changes: 4 additions & 4 deletions web/client/utils/styleparser/OLStyleParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ export class OlStyleParser {
const olStyle = ({ map, features } = {}) => drawIcons(geoStylerStyle, { features })
.then((images) => {
this._getImages = () => images;
this._computeIconScaleBasedOnSymbolizer = (symbolizer) => {
const { image, width, height } = images.find(({ id }) => id === getImageIdFromSymbolizer(symbolizer)) || {};
this._computeIconScaleBasedOnSymbolizer = (symbolizer, _symbolizer) => {
const { image, width, height } = images.find(({ id }) => id === getImageIdFromSymbolizer(symbolizer, _symbolizer)) || {};
if (image && width && height) {
const side = width > height ? width : height;
const scale = symbolizer.size / side;
Expand Down Expand Up @@ -557,7 +557,7 @@ export class OlStyleParser {
}
const geometryFunc = getGeometryFunction(markSymbolizer, feature, this._getMap());
const images = this._getImages();
const { image, width, height } = images.find(({ id }) => id === getImageIdFromSymbolizer(markSymbolizer)) || {};
const { image, width, height } = images.find(({ id }) => id === getImageIdFromSymbolizer(markSymbolizer, _markSymbolizer)) || {};
if (image) {
const side = width > height ? width : height;
const scale = (markSymbolizer.radius * 2) / side;
Expand Down Expand Up @@ -597,7 +597,7 @@ export class OlStyleParser {
src: symbolizer.image,
crossOrigin: 'anonymous',
opacity: symbolizer.opacity,
scale: this._computeIconScaleBasedOnSymbolizer(_symbolizer),
scale: this._computeIconScaleBasedOnSymbolizer(symbolizer, _symbolizer),
// Rotation in openlayers is radians while we use degree
rotation: (typeof (symbolizer.rotate) === 'number' ? symbolizer.rotate * Math.PI / 180 : undefined),
displacement: symbolizer.offset,
Expand Down
11 changes: 10 additions & 1 deletion web/client/utils/styleparser/StyleParserUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ let imagesCache = {};
* @param {object} symbolizer mark symbolizer
* @returns {string} an id for the mark symbolizer
*/
export const getImageIdFromSymbolizer = ({
export const _getImageIdFromSymbolizer = ({
image,
color,
fillOpacity,
Expand All @@ -509,6 +509,15 @@ export const getImageIdFromSymbolizer = ({
}
return [wellKnownName, color, fillOpacity, strokeColor, strokeOpacity, (strokeDasharray || []).join('_'), strokeWidth, radius].join(':');
};
/**
* generate an id based on a Mark symbolizer
* @param {object} parsedSymbolizer the parsed mark symbolizer
* @param {object} originalSymbolizer the original mark symbolizer
* @returns {string} an id for the mark symbolizer
*/
export const getImageIdFromSymbolizer = (parsedSymbolizer, originalSymbolizer) => {
return _getImageIdFromSymbolizer(originalSymbolizer?.image?.name === 'msMarkerIcon' ? originalSymbolizer : parsedSymbolizer);
};

/**
* prefetch images of a icon symbolizer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ describe("StyleParserUtils ", () => {
size: 32,
rotate: 90
})).toBe('path/to/image');
const parsedSymbolizer = {"symbolizerId": "df2715d2-8ecb-11ee-909e-8bd5d708e385", "kind": "Icon", "image": "data:image/png;base64,iVBORcmGtfaAAAAABJRU5ErkJggg==", "opacity": 1, "size": 46, "rotate": 0, "msBringToFront": false, "anchor": "bottom", "msHeightReference": "none"};
const originalSymbolizer = {"symbolizerId": "df2715d2-8ecb-11ee-909e-8bd5d708e385", "kind": "Icon", "image": {"name": "msMarkerIcon", "args": [{"glyph": "power-off", "color": "purple", "shape": "square"}]}, "opacity": 1, "size": 46, "rotate": 0, "msBringToFront": false, "anchor": "bottom", "msHeightReference": "none"};
expect(getImageIdFromSymbolizer(parsedSymbolizer, originalSymbolizer)).toEqual("msMarkerIcon:purple:square:power-off");

});

Expand Down
Loading