From 2c6a23965fd88c3b091c27f4eda57738c5661dbf Mon Sep 17 00:00:00 2001 From: Benjamin Gerber Date: Fri, 1 Nov 2024 15:49:12 +0100 Subject: [PATCH] fix: reference legacy issues --- src/esri/types/labeling/CIMSymbolReference.ts | 8 +++++ src/processSymbolLayer.ts | 31 +++++++++---------- src/processSymbolReference.ts | 31 ++++++++++--------- src/toGeostyler.ts | 11 ++++--- src/wktGeometries.ts | 11 +++---- 5 files changed, 50 insertions(+), 42 deletions(-) diff --git a/src/esri/types/labeling/CIMSymbolReference.ts b/src/esri/types/labeling/CIMSymbolReference.ts index 6858644..298e47d 100644 --- a/src/esri/types/labeling/CIMSymbolReference.ts +++ b/src/esri/types/labeling/CIMSymbolReference.ts @@ -3,11 +3,19 @@ import { CIMSymbol } from '../symbols/index.ts'; type CIMPrimitiveOverride = {}; type CIMScaleDependentSizeVariation = {}; + +export type Geometry = { + rings?: number[][][]; + paths?: number[][][]; + curveRings?: { a?: number[][]; c?: number[][] }[][]; +}; + /** * Represents a symbol reference. * */ export type CIMSymbolReference = { + geometry: Geometry; /** * Gets or sets the primitive overrides. Typically set by renderers at draw time. */ diff --git a/src/processSymbolLayer.ts b/src/processSymbolLayer.ts index 24016af..b538443 100644 --- a/src/processSymbolLayer.ts +++ b/src/processSymbolLayer.ts @@ -181,19 +181,18 @@ const processSymbolVectorMarker = (layer: SymbolLayer): MarkSymbolizer => { } else if ( ['CIMLineSymbol', 'CIMPolygonSymbol'].includes(markerGraphic.symbol.type) ) { - // @ts-ignore TODO fix me, it should exist. const geometry = markerGraphic.geometry; - let shape = toWKT( - geometry !== undefined ? geometry : undefined - ); - wellKnownName = shape.wellKnownName; - maxX = ptToPxProp(shape, 'maxX', 0); - maxY = ptToPxProp(shape, 'maxY', 0); + if (geometry) { + const shape = toWKT(geometry); + wellKnownName = shape.wellKnownName; + maxX = ptToPxProp(shape, 'maxX', 0); + maxY = ptToPxProp(shape, 'maxY', 0); + } } } } - // FIXME marker should support outlineDasharray ? + // TODO marker should support outlineDasharray ? const marker: MarkSymbolizer= { opacity: 1, rotate: 0, @@ -207,11 +206,11 @@ const processSymbolVectorMarker = (layer: SymbolLayer): MarkSymbolizer => { fillOpacity: 1, }; if (maxX !== null) { - // @ts-ignore TODO this should be fixed. + // @ts-ignore FIXME see issue #62 marker.maxX = maxX; } if (maxY !== null) { - // @ts-ignore TODO this should be fixed. + // @ts-ignore FIXME see issue #62 marker.maxY = maxY; } @@ -222,13 +221,13 @@ const processSymbolVectorMarker = (layer: SymbolLayer): MarkSymbolizer => { : undefined; // Conversion of dash arrays is made on a case-by-case basis if (JSON.stringify(markerPlacement) === JSON.stringify([12, 3])) { - // @ts-ignore TODO this should be fixed. + // @ts-ignore FIXME see issue #63 marker.outlineDasharray = '4 0 4 7'; marker.radius = 3; - // @ts-ignore TODO this should be fixed. + // @ts-ignore FIXME see issue #63 marker.perpendicularOffset = -3.5; } else if (JSON.stringify(markerPlacement) === JSON.stringify([15])) { - // @ts-ignore TODO this should be fixed. + // @ts-ignore FIXME see issue #63 marker.outlineDasharray = '0 5 9 1'; marker.radius = 5; } @@ -284,7 +283,7 @@ const processSymbolHatchFill = (layer: SymbolLayer): Symbolizer => { let effects = extractEffect(symbolLayers[0]); if ('dasharray' in effects) { - // @ts-ignore TODO this should be fixed. + // @ts-ignore FIXME see issue #63 fillSymbolizer.graphicFill!.outlineDasharray = effects.dasharray; // In case of dash array, the size must be at least as long as the dash pattern sum. @@ -295,10 +294,10 @@ const processSymbolHatchFill = (layer: SymbolLayer): Symbolizer => { // To keep the "original size" given by the separation value, we play with a negative margin. let negativeMargin = ((neededSize - separation) / 2) * -1; if (wellKnowName === getStraightHatchMarker()[0]) { - // @ts-ignore TODO this should be fixed. + // @ts-ignore FIXME see issue #64 fillSymbolizer.graphicFillMargin = [negativeMargin, 0, negativeMargin, 0]; } else { - // @ts-ignore TODO this should be fixed. + // @ts-ignore FIXME see issue #64 fillSymbolizer.graphicFillMargin = [0, negativeMargin, 0, negativeMargin]; } } else { diff --git a/src/processSymbolReference.ts b/src/processSymbolReference.ts index 8e30f72..248fcc9 100644 --- a/src/processSymbolReference.ts +++ b/src/processSymbolReference.ts @@ -111,7 +111,7 @@ const formatLineSymbolizer = (symbolizer: PointSymbolizer): LineSymbolizer => { opacity: 1.0, perpendicularOffset: 0.0, graphicStroke: symbolizer, - // @ts-ignore TODO this property should probably be added into geostyler-style. + // @ts-ignore FIXME see issue #65 graphicStrokeInterval: ptToPxProp(symbolizer, 'size', 0) * 2, graphicStrokeOffset: 0.0, @@ -132,7 +132,7 @@ const formatPolygonSymbolizer = ( kind: 'Fill', opacity: 1.0, graphicFill: symbolizer, - // @ts-ignore TODO this property should probably be added into geostyler-style. + // @ts-ignore FIXME see issue #64 graphicFillMargin: margin, }; } @@ -208,17 +208,17 @@ const processOrientedMarkerAtEndOfLine = ( strokeColor: strokeColor, strokeOpacity: strokeOpacity, strokeWidth: strokeWidth, - // TODO use markerRotationFnc ? Previous code was: + // FIXME see issue #66 use markerRotationFnc ? Previous code was: // rotate: ['Add', [markerRotationFnc, ['PropertyName', 'shape']], rotation], rotate: { args: [fProperty, rotation], name: 'add' }, kind: 'Mark', color: fillColor, wellKnownName: name, radius: ptToPxProp(layer, 'size', 10), - // TODO Support geometry ? - // Geometry: [markerPositionFnc, ['PropertyName', 'shape']], - // TODO support inclusion ? - // inclusion: 'mapOnly', + // @ts-ignore FIXME see issue #66 + geometry: [markerPositionFnc, ['PropertyName', 'shape']], + // @ts-ignore FIXME see issue #66 + inclusion: 'mapOnly', }; }; @@ -234,13 +234,16 @@ const processMarkerPlacementInsidePolygon = ( const size = Math.round(radius * resizeFactor) || 1; symbolizer.radius = size; - const maxX = size / 2; - const maxY = size / 2; - // TODO this property should probably be added into geostyler-style. - // if (symbolizer?.maxX && symbolizer?.maxY) { - // maxX = Math.floor(symbolizer.maxX * resizeFactor) || 1; - // maxY = Math.floor(symbolizer.maxY * resizeFactor) || 1; - // } + let maxX = size / 2; + let maxY = size / 2; + // @ts-ignore FIXME see issue #62 + const symMaxX = symbolizer?.maxX ?? maxX; + // @ts-ignore FIXME see issue #62 + const symMaxY = symbolizer?.maxY ?? maxY; + if (symMaxX && symMaxY) { + maxX = Math.floor(symMaxX * resizeFactor) || 1; + maxY = Math.floor(symMaxY * resizeFactor) || 1; + } let stepX = ptToPxProp(markerPlacement, 'stepX', 0); let stepY = ptToPxProp(markerPlacement, 'stepY', 0); diff --git a/src/toGeostyler.ts b/src/toGeostyler.ts index eeb2cc8..8973d64 100644 --- a/src/toGeostyler.ts +++ b/src/toGeostyler.ts @@ -219,7 +219,7 @@ const processLabelClass = ( ); const fontFamily = textSymbol?.fontFamilyName || 'Arial'; const fontSize = ptToPxProp(textSymbol, 'height', 12, true); - // @ts-ignore TODO fix me, cast make no sens. + // @ts-ignore FIXME see issue #68 const color = extractFillColor(textSymbol?.symbol?.symbolLayers ?? []); const fontWeight = extractFontWeight(textSymbol); const rotationProps = @@ -254,7 +254,7 @@ const processLabelClass = ( maplexPlacementType === LabelFeatureType.Line ) { const primaryOffset = ptToPxProp(textSymbol, 'primaryOffset', 0); - // @ts-ignore TODO add it to text symbolizer or fix it with existing definition. + // @ts-ignore FIXME see issue #63 symbolizer.perpendicularOffset = primaryOffset + fontSize; } else if ( maplexPlacementType === LabelFeatureType.Point && @@ -281,8 +281,9 @@ const processLabelClass = ( const haloSize = ptToPxProp(textSymbol, 'haloSize', 0); if (haloSize && textSymbol.haloSymbol) { - // @ts-ignore TODO fix me, cast make no sens. - const haloColor = extractFillColor(textSymbol?.haloSymbol?.symbolLayers ?? []); + // @ts-ignore FIXME see issue #68 + const haloColor = extractFillColor(textSymbol?.haloSymbol?.symbolLayers ?? [] + ); Object.assign(symbolizer, { haloColor: haloColor, haloSize: haloSize, @@ -290,7 +291,7 @@ const processLabelClass = ( }); } - // @ts-ignore TODO add it to text symbolizer or fix it with existing definition. + // @ts-ignore FIXME see issue #67 symbolizer.group = labelClass.maplexLabelPlacementProperties?.thinDuplicateLabels || (maplexPlacementType === LabelFeatureType.Polygon && diff --git a/src/wktGeometries.ts b/src/wktGeometries.ts index ab6b4fe..4c8de1f 100644 --- a/src/wktGeometries.ts +++ b/src/wktGeometries.ts @@ -1,10 +1,5 @@ import {WellKnownName} from 'geostyler-style'; - -type Geometry = { - rings?: number[][][]; - paths?: number[][][]; - curveRings?: { a?: number[][]; c?: number[][] }[][]; -}; +import {Geometry} from './esri/types'; export const toWKT = (geometry: Geometry): { wellKnownName: WellKnownName; maxX?: number; maxY?: number } => { const defaultMarker = {wellKnownName: 'circle' as WellKnownName}; @@ -32,7 +27,9 @@ export const toWKT = (geometry: Geometry): { wellKnownName: WellKnownName; maxX? if (!curve) {return defaultMarker;} const endPoint = curve[0]; const centerPoint = curve[1]; - if (endPoint !== startPoint) {return defaultMarker;} + if (endPoint !== startPoint) { + return defaultMarker; + } const radius = distanceBetweenPoints(startPoint as number[], centerPoint); return { wellKnownName: 'circle' as WellKnownName,