Skip to content

Commit

Permalink
fix: reference legacy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ger-benjamin committed Nov 1, 2024
1 parent 311485a commit 2c6a239
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 42 deletions.
8 changes: 8 additions & 0 deletions src/esri/types/labeling/CIMSymbolReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
31 changes: 15 additions & 16 deletions src/processSymbolLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
31 changes: 17 additions & 14 deletions src/processSymbolReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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,
};
}
Expand Down Expand Up @@ -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',
};
};

Expand All @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions src/toGeostyler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 &&
Expand All @@ -281,16 +281,17 @@ 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,
haloOpacity: 1,
});
}

// @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 &&
Expand Down
11 changes: 4 additions & 7 deletions src/wktGeometries.ts
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2c6a239

Please sign in to comment.