From 881a4f14c1ec7f312ae280843cae08342914abc2 Mon Sep 17 00:00:00 2001 From: Benjamin Gerber Date: Fri, 23 Aug 2024 11:21:01 +0200 Subject: [PATCH] fix: text label expression --- data/lyrx/afu_gwn_02.lyrx | 1339 +++++++++++++++++++++++++++++++++++++ src/LyrxParser.spec.ts | 24 +- src/expressions.ts | 32 +- src/toGeostyler.ts | 2 +- 4 files changed, 1377 insertions(+), 20 deletions(-) create mode 100644 data/lyrx/afu_gwn_02.lyrx diff --git a/data/lyrx/afu_gwn_02.lyrx b/data/lyrx/afu_gwn_02.lyrx new file mode 100644 index 0000000..63a4d90 --- /dev/null +++ b/data/lyrx/afu_gwn_02.lyrx @@ -0,0 +1,1339 @@ +{ + "type" : "CIMLayerDocument", + "version" : "2.9.0", + "build" : 32739, + "layers" : [ + "CIMPATH=karte/trinkwasserfassungen2.xml" + ], + "layerDefinitions" : [ + { + "type" : "CIMFeatureLayer", + "name" : "Trinkwasserfassungen", + "uRI" : "CIMPATH=karte/trinkwasserfassungen2.xml", + "sourceModifiedTime" : { + "type" : "TimeInstant" + }, + "metadataURI" : "CIMPATH=Metadata/53b587d48a512831970f8c36e6b0442c.xml", + "useSourceMetadata" : false, + "layerElevation" : { + "type" : "CIMLayerElevationSurface", + "mapElevationID" : "{B8738572-F10E-4C41-880A-FE9843C82F35}" + }, + "expanded" : true, + "layerType" : "Operational", + "showLegends" : true, + "visibility" : true, + "displayCacheType" : "Permanent", + "maxDisplayCacheAge" : 5, + "showPopups" : true, + "serviceLayerID" : -1, + "refreshRate" : -1, + "refreshRateUnit" : "esriTimeUnitsSeconds", + "blendingMode" : "Alpha", + "allowDrapingOnIntegratedMesh" : true, + "autoGenerateFeatureTemplates" : true, + "featureElevationExpression" : "0", + "featureTable" : { + "type" : "CIMFeatureTable", + "definitionExpression" : "NUTZART = 1", + "displayField" : "NAME", + "editable" : true, + "fieldDescriptions" : [ + { + "type" : "CIMFieldDescription", + "alias" : "OBJECTID", + "fieldName" : "OBJECTID", + "numberFormat" : { + "type" : "CIMNumericFormat", + "alignmentOption" : "esriAlignRight", + "alignmentWidth" : 12, + "roundingOption" : "esriRoundNumberOfDecimals", + "roundingValue" : 0 + }, + "readOnly" : true, + "visible" : true, + "searchMode" : "Exact" + }, + { + "type" : "CIMFieldDescription", + "alias" : "ART", + "fieldName" : "ART", + "visible" : true, + "searchMode" : "Exact" + }, + { + "type" : "CIMFieldDescription", + "alias" : "NAME", + "fieldName" : "NAME", + "visible" : true, + "searchMode" : "Exact" + }, + { + "type" : "CIMFieldDescription", + "alias" : "BEW_NR", + "fieldName" : "BEW_NR", + "visible" : true, + "searchMode" : "Exact" + }, + { + "type" : "CIMFieldDescription", + "alias" : "NUTZART_TE", + "fieldName" : "NUTZART_TE", + "visible" : true, + "searchMode" : "Exact" + }, + { + "type" : "CIMFieldDescription", + "alias" : "NUTZART", + "fieldName" : "NUTZART", + "numberFormat" : { + "type" : "CIMNumericFormat", + "alignmentOption" : "esriAlignRight", + "alignmentWidth" : 12, + "roundingOption" : "esriRoundNumberOfDecimals", + "roundingValue" : 0 + }, + "visible" : true, + "searchMode" : "Exact" + }, + { + "type" : "CIMFieldDescription", + "alias" : "BEW_FOERDE", + "fieldName" : "BEW_FOERDE", + "numberFormat" : { + "type" : "CIMNumericFormat", + "alignmentOption" : "esriAlignRight", + "alignmentWidth" : 12, + "roundingOption" : "esriRoundNumberOfDecimals", + "roundingValue" : 6 + }, + "visible" : true, + "searchMode" : "Exact" + }, + { + "type" : "CIMFieldDescription", + "alias" : "BOHRTIEFE_", + "fieldName" : "BOHRTIEFE_", + "numberFormat" : { + "type" : "CIMNumericFormat", + "alignmentOption" : "esriAlignRight", + "alignmentWidth" : 12, + "roundingOption" : "esriRoundNumberOfDecimals", + "roundingValue" : 6 + }, + "visible" : true, + "searchMode" : "Exact" + }, + { + "type" : "CIMFieldDescription", + "alias" : "SHAPE", + "fieldName" : "Shape", + "visible" : true, + "searchMode" : "Exact" + }, + { + "type" : "CIMFieldDescription", + "alias" : "E_KOORD", + "fieldName" : "E_KOORD", + "numberFormat" : { + "type" : "CIMNumericFormat", + "alignmentOption" : "esriAlignRight", + "alignmentWidth" : 12, + "roundingOption" : "esriRoundNumberOfDecimals", + "roundingValue" : 6 + }, + "visible" : true, + "searchMode" : "Exact" + }, + { + "type" : "CIMFieldDescription", + "alias" : "N_KOORD", + "fieldName" : "N_KOORD", + "numberFormat" : { + "type" : "CIMNumericFormat", + "alignmentOption" : "esriAlignRight", + "alignmentWidth" : 12, + "roundingOption" : "esriRoundNumberOfDecimals", + "roundingValue" : 6 + }, + "visible" : true, + "searchMode" : "Exact" + } + ], + "timeFields" : { + "type" : "CIMTimeTableDefinition" + }, + "timeDefinition" : { + "type" : "CIMTimeDataDefinition", + "hasLiveData" : true + }, + "timeDisplayDefinition" : { + "type" : "CIMTimeDisplayDefinition", + "timeInterval" : 0, + "timeIntervalUnits" : "esriTimeUnitsHours", + "timeOffsetUnits" : "esriTimeUnitsYears" + }, + "dataConnection" : { + "type" : "CIMStandardDataConnection", + "workspaceConnectionString" : "", + "workspaceFactory" : "SDE", + "dataset" : "AGIS.afu_gwn", + "datasetType" : "esriDTFeatureClass" + }, + "studyAreaSpatialRel" : "esriSpatialRelUndefined", + "searchOrder" : "esriSearchOrderSpatial" + }, + "featureTemplates" : [ + { + "type" : "CIMFeatureTemplate", + "name" : "unbekannt", + "tags" : "Punkt", + "toolProgID" : "2a8b3331-5238-4025-972e-452a69535b06", + "defaultValues" : { + "type" : "PropertySet", + "propertySetItems" : [ + "bew_foerde", + 0 + ] + } + }, + { + "type" : "CIMFeatureTemplate", + "name" : "< 90 l/min", + "tags" : "Punkt", + "toolProgID" : "2a8b3331-5238-4025-972e-452a69535b06", + "defaultValues" : { + "type" : "PropertySet", + "propertySetItems" : [ + "bew_foerde", + 0.75 + ] + } + }, + { + "type" : "CIMFeatureTemplate", + "name" : "91 - 300 l/min", + "tags" : "Punkt", + "toolProgID" : "2a8b3331-5238-4025-972e-452a69535b06", + "defaultValues" : { + "type" : "PropertySet", + "propertySetItems" : [ + "bew_foerde", + 3.25 + ] + } + }, + { + "type" : "CIMFeatureTemplate", + "name" : "301 - 3000 l/min", + "tags" : "Punkt", + "toolProgID" : "2a8b3331-5238-4025-972e-452a69535b06", + "defaultValues" : { + "type" : "PropertySet", + "propertySetItems" : [ + "bew_foerde", + 27.5 + ] + } + }, + { + "type" : "CIMFeatureTemplate", + "name" : "> 3000 l/min", + "tags" : "Punkt", + "toolProgID" : "2a8b3331-5238-4025-972e-452a69535b06", + "defaultValues" : { + "type" : "PropertySet", + "propertySetItems" : [ + "bew_foerde", + 10025 + ] + } + } + ], + "htmlPopupEnabled" : true, + "htmlPopupFormat" : { + "type" : "CIMHtmlPopupFormat", + "htmlUseCodedDomainValues" : true, + "htmlPresentationStyle" : "TwoColumnTable" + }, + "isFlattened" : true, + "selectable" : true, + "selectionSymbol" : { + "type" : "CIMSymbolReference", + "symbol" : { + "type" : "CIMPointSymbol", + "symbolLayers" : [ + { + "type" : "CIMVectorMarker", + "enable" : true, + "anchorPointUnits" : "Relative", + "dominantSizeAxis3D" : "Z", + "size" : 8, + "billboardMode3D" : "FaceNearPlane", + "frame" : { + "xmin" : -2, + "ymin" : -2, + "xmax" : 2, + "ymax" : 2 + }, + "markerGraphics" : [ + { + "type" : "CIMMarkerGraphic", + "geometry" : { + "curveRings" : [ + [ + [ + 1.2246467991473532e-16, + 2 + ], + { + "a" : [ + [ + 1.2246467991473532e-16, + 2 + ], + [ + 1.2246467991473532e-16, + 0 + ], + 0, + 1 + ] + } + ] + ] + }, + "symbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 0, + 255, + 255, + 100 + ] + } + } + ] + } + } + ], + "respectFrame" : true + } + ], + "haloSize" : 1, + "scaleX" : 1, + "angleAlignment" : "Map" + } + }, + "featureCacheType" : "None", + "displayFiltersType" : "ByScale", + "featureBlendingMode" : "Alpha", + "labelClasses" : [ + { + "type" : "CIMLabelClass", + "expression" : "[BEW_NR] + \" / \" + [BEW_FOERDE] + \" l/s\"", + "expressionEngine" : "VBScript", + "featuresToLabel" : "AllVisibleFeatures", + "maplexLabelPlacementProperties" : { + "type" : "CIMMaplexLabelPlacementProperties", + "featureType" : "Point", + "avoidPolygonHoles" : true, + "canOverrunFeature" : true, + "canPlaceLabelOutsidePolygon" : true, + "canRemoveOverlappingLabel" : true, + "canStackLabel" : true, + "connectionType" : "Unambiguous", + "constrainOffset" : "NoConstraint", + "contourAlignmentType" : "Page", + "contourLadderType" : "Straight", + "contourMaximumAngle" : 90, + "enableConnection" : true, + "enablePointPlacementPriorities" : true, + "featureWeight" : 0, + "fontHeightReductionLimit" : 4, + "fontHeightReductionStep" : 0.5, + "fontWidthReductionLimit" : 90, + "fontWidthReductionStep" : 5, + "graticuleAlignmentType" : "Straight", + "keyNumberGroupName" : "Default", + "labelBuffer" : 15, + "labelLargestPolygon" : true, + "labelPriority" : -1, + "labelStackingProperties" : { + "type" : "CIMMaplexLabelStackingProperties", + "stackAlignment" : "ChooseBest", + "maximumNumberOfLines" : 3, + "minimumNumberOfCharsPerLine" : 3, + "maximumNumberOfCharsPerLine" : 24, + "separators" : [ + { + "type" : "CIMMaplexStackingSeparator", + "separator" : " ", + "splitAfter" : true + }, + { + "type" : "CIMMaplexStackingSeparator", + "separator" : ",", + "visible" : true, + "splitAfter" : true + } + ], + "trimStackingSeparators" : true + }, + "lineFeatureType" : "General", + "linePlacementMethod" : "OffsetCurvedFromLine", + "maximumLabelOverrun" : 36, + "maximumLabelOverrunUnit" : "Point", + "minimumFeatureSizeUnit" : "Map", + "multiPartOption" : "OneLabelPerPart", + "offsetAlongLineProperties" : { + "type" : "CIMMaplexOffsetAlongLineProperties", + "placementMethod" : "BestPositionAlongLine", + "labelAnchorPoint" : "CenterOfLabel", + "distanceUnit" : "Percentage", + "useLineDirection" : true + }, + "pointExternalZonePriorities" : { + "type" : "CIMMaplexExternalZonePriorities", + "aboveLeft" : 4, + "aboveCenter" : 2, + "aboveRight" : 1, + "centerRight" : 3, + "belowRight" : 5, + "belowCenter" : 7, + "belowLeft" : 0, + "centerLeft" : 6 + }, + "pointPlacementMethod" : "AroundPoint", + "polygonAnchorPointType" : "GeometricCenter", + "polygonBoundaryWeight" : 0, + "polygonExternalZones" : { + "type" : "CIMMaplexExternalZonePriorities", + "aboveLeft" : 4, + "aboveCenter" : 2, + "aboveRight" : 1, + "centerRight" : 3, + "belowRight" : 5, + "belowCenter" : 7, + "belowLeft" : 8, + "centerLeft" : 6 + }, + "polygonFeatureType" : "General", + "polygonInternalZones" : { + "type" : "CIMMaplexInternalZonePriorities", + "center" : 1 + }, + "polygonPlacementMethod" : "CurvedInPolygon", + "primaryOffset" : 1, + "primaryOffsetUnit" : "Point", + "removeExtraWhiteSpace" : true, + "repetitionIntervalUnit" : "Map", + "rotationProperties" : { + "type" : "CIMMaplexRotationProperties", + "rotationType" : "Arithmetic", + "alignmentType" : "Straight" + }, + "secondaryOffset" : 100, + "strategyPriorities" : { + "type" : "CIMMaplexStrategyPriorities", + "stacking" : 1, + "overrun" : 2, + "fontCompression" : 3, + "fontReduction" : 4, + "abbreviation" : 5 + }, + "thinningDistanceUnit" : "Point", + "truncationMarkerCharacter" : ".", + "truncationMinimumLength" : 1, + "truncationPreferredCharacters" : "aeiou", + "polygonAnchorPointPerimeterInsetUnit" : "Point" + }, + "minimumScale" : 25000, + "name" : "Standard", + "priority" : 6, + "standardLabelPlacementProperties" : { + "type" : "CIMStandardLabelPlacementProperties", + "featureType" : "Line", + "featureWeight" : "None", + "labelWeight" : "High", + "numLabelsOption" : "OneLabelPerName", + "lineLabelPosition" : { + "type" : "CIMStandardLineLabelPosition", + "above" : true, + "inLine" : true, + "parallel" : true + }, + "lineLabelPriorities" : { + "type" : "CIMStandardLineLabelPriorities", + "aboveStart" : 3, + "aboveAlong" : 3, + "aboveEnd" : 3, + "centerStart" : 3, + "centerAlong" : 3, + "centerEnd" : 3, + "belowStart" : 3, + "belowAlong" : 3, + "belowEnd" : 3 + }, + "pointPlacementMethod" : "AroundPoint", + "pointPlacementPriorities" : { + "type" : "CIMStandardPointPlacementPriorities", + "aboveLeft" : 2, + "aboveCenter" : 2, + "aboveRight" : 1, + "centerLeft" : 3, + "centerRight" : 2, + "belowLeft" : 3, + "belowCenter" : 3, + "belowRight" : 2 + }, + "rotationType" : "Arithmetic", + "polygonPlacementMethod" : "AlwaysHorizontal" + }, + "textSymbol" : { + "type" : "CIMSymbolReference", + "symbol" : { + "type" : "CIMTextSymbol", + "blockProgression" : "TTB", + "compatibilityMode" : true, + "depth3D" : 1, + "drawSoftHyphen" : true, + "extrapolateBaselines" : true, + "flipAngle" : 90, + "fontEffects" : "Normal", + "fontEncoding" : "Unicode", + "fontFamilyName" : "Arial", + "fontStyleName" : "Bold", + "fontType" : "Unspecified", + "haloSize" : 1, + "haloSymbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 255, + 255, + 255, + 100 + ] + } + } + ] + }, + "height" : 9, + "hinting" : "Default", + "horizontalAlignment" : "Center", + "kerning" : true, + "letterWidth" : 100, + "ligatures" : true, + "lineGapType" : "ExtraLeading", + "shadowColor" : { + "type" : "CIMRGBColor", + "values" : [ + 0, + 0, + 0, + 100 + ] + }, + "symbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + } + ] + }, + "textCase" : "Normal", + "textDirection" : "LTR", + "verticalAlignment" : "Bottom", + "verticalGlyphOrientation" : "Right", + "wordSpacing" : 100, + "billboardMode3D" : "FaceNearPlane" + } + }, + "useCodedValue" : true, + "visibility" : true, + "iD" : -1 + } + ], + "labelVisibility" : true, + "renderer" : { + "type" : "CIMClassBreaksRenderer", + "barrierWeight" : "None", + "breaks" : [ + { + "type" : "CIMClassBreak", + "label" : "unbekannt", + "patch" : "Default", + "symbol" : { + "type" : "CIMSymbolReference", + "symbol" : { + "type" : "CIMPointSymbol", + "symbolLayers" : [ + { + "type" : "CIMCharacterMarker", + "enable" : true, + "anchorPointUnits" : "Relative", + "dominantSizeAxis3D" : "Y", + "size" : 10, + "billboardMode3D" : "FaceNearPlane", + "characterIndex" : 34, + "fontFamilyName" : "ESRI Default Marker", + "fontStyleName" : "Regular", + "fontType" : "TrueType", + "scaleX" : 1, + "symbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidStroke", + "enable" : true, + "capStyle" : "Round", + "joinStyle" : "Round", + "lineStyle3D" : "Strip", + "miterLimit" : 10, + "width" : 1, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + }, + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 240, + 240, + 240, + 0 + ] + } + } + ] + }, + "respectFrame" : true + } + ], + "haloSize" : 1, + "scaleX" : 1, + "angleAlignment" : "Map" + } + } + }, + { + "type" : "CIMClassBreak", + "label" : "< 90 l/min", + "patch" : "Default", + "symbol" : { + "type" : "CIMSymbolReference", + "symbol" : { + "type" : "CIMPointSymbol", + "symbolLayers" : [ + { + "type" : "CIMCharacterMarker", + "enable" : true, + "colorLocked" : true, + "anchorPoint" : { + "x" : 0, + "y" : 0, + "z" : 0 + }, + "anchorPointUnits" : "Absolute", + "dominantSizeAxis3D" : "Y", + "offsetX" : 1.5, + "offsetY" : 1.5, + "size" : 4, + "billboardMode3D" : "FaceNearPlane", + "characterIndex" : 34, + "fontFamilyName" : "ESRI Default Marker", + "fontStyleName" : "Regular", + "fontType" : "Unspecified", + "scaleX" : 1, + "symbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidStroke", + "enable" : true, + "capStyle" : "Round", + "joinStyle" : "Round", + "lineStyle3D" : "Strip", + "miterLimit" : 4, + "width" : 1, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + }, + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + } + ] + }, + "scaleSymbolsProportionally" : true, + "respectFrame" : true + }, + { + "type" : "CIMCharacterMarker", + "enable" : true, + "colorLocked" : true, + "anchorPointUnits" : "Relative", + "dominantSizeAxis3D" : "Y", + "size" : 10, + "billboardMode3D" : "FaceNearPlane", + "characterIndex" : 34, + "fontFamilyName" : "ESRI Default Marker", + "fontStyleName" : "Regular", + "fontType" : "Unspecified", + "scaleX" : 1, + "symbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidStroke", + "enable" : true, + "capStyle" : "Round", + "joinStyle" : "Round", + "lineStyle3D" : "Strip", + "miterLimit" : 10, + "width" : 1, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + }, + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 240, + 240, + 240, + 0 + ] + } + } + ] + }, + "respectFrame" : true + } + ], + "haloSize" : 1, + "scaleX" : 1, + "angleAlignment" : "Map" + } + }, + "upperBound" : 1.5 + }, + { + "type" : "CIMClassBreak", + "label" : "91 - 300 l/min", + "patch" : "Default", + "symbol" : { + "type" : "CIMSymbolReference", + "symbol" : { + "type" : "CIMPointSymbol", + "symbolLayers" : [ + { + "type" : "CIMCharacterMarker", + "enable" : true, + "colorLocked" : true, + "anchorPoint" : { + "x" : 0, + "y" : 0, + "z" : 0 + }, + "anchorPointUnits" : "Absolute", + "dominantSizeAxis3D" : "Y", + "offsetX" : 1.5, + "offsetY" : -1.5, + "size" : 4, + "billboardMode3D" : "FaceNearPlane", + "characterIndex" : 34, + "fontFamilyName" : "ESRI Default Marker", + "fontStyleName" : "Regular", + "fontType" : "Unspecified", + "scaleX" : 1, + "symbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidStroke", + "enable" : true, + "capStyle" : "Round", + "joinStyle" : "Round", + "lineStyle3D" : "Strip", + "miterLimit" : 4, + "width" : 1, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + }, + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + } + ] + }, + "scaleSymbolsProportionally" : true, + "respectFrame" : true + }, + { + "type" : "CIMCharacterMarker", + "enable" : true, + "colorLocked" : true, + "anchorPoint" : { + "x" : 0, + "y" : 0, + "z" : 0 + }, + "anchorPointUnits" : "Absolute", + "dominantSizeAxis3D" : "Y", + "offsetX" : 1.5, + "offsetY" : 1.5, + "size" : 4, + "billboardMode3D" : "FaceNearPlane", + "characterIndex" : 34, + "fontFamilyName" : "ESRI Default Marker", + "fontStyleName" : "Regular", + "fontType" : "Unspecified", + "scaleX" : 1, + "symbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidStroke", + "enable" : true, + "capStyle" : "Round", + "joinStyle" : "Round", + "lineStyle3D" : "Strip", + "miterLimit" : 4, + "width" : 1, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + }, + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + } + ] + }, + "scaleSymbolsProportionally" : true, + "respectFrame" : true + }, + { + "type" : "CIMCharacterMarker", + "enable" : true, + "colorLocked" : true, + "anchorPointUnits" : "Relative", + "dominantSizeAxis3D" : "Y", + "size" : 10, + "billboardMode3D" : "FaceNearPlane", + "characterIndex" : 34, + "fontFamilyName" : "ESRI Default Marker", + "fontStyleName" : "Regular", + "fontType" : "Unspecified", + "scaleX" : 1, + "symbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidStroke", + "enable" : true, + "capStyle" : "Round", + "joinStyle" : "Round", + "lineStyle3D" : "Strip", + "miterLimit" : 10, + "width" : 1, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + }, + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 240, + 240, + 240, + 0 + ] + } + } + ] + }, + "respectFrame" : true + } + ], + "haloSize" : 1, + "scaleX" : 1, + "angleAlignment" : "Map" + } + }, + "upperBound" : 5 + }, + { + "type" : "CIMClassBreak", + "label" : "301 - 3000 l/min", + "patch" : "Default", + "symbol" : { + "type" : "CIMSymbolReference", + "symbol" : { + "type" : "CIMPointSymbol", + "symbolLayers" : [ + { + "type" : "CIMCharacterMarker", + "enable" : true, + "colorLocked" : true, + "anchorPoint" : { + "x" : 0, + "y" : 0, + "z" : 0 + }, + "anchorPointUnits" : "Absolute", + "dominantSizeAxis3D" : "Y", + "offsetX" : -1.5, + "offsetY" : -1.5, + "size" : 4, + "billboardMode3D" : "FaceNearPlane", + "characterIndex" : 34, + "fontFamilyName" : "ESRI Default Marker", + "fontStyleName" : "Regular", + "fontType" : "Unspecified", + "scaleX" : 1, + "symbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidStroke", + "enable" : true, + "capStyle" : "Round", + "joinStyle" : "Round", + "lineStyle3D" : "Strip", + "miterLimit" : 4, + "width" : 1, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + }, + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + } + ] + }, + "scaleSymbolsProportionally" : true, + "respectFrame" : true + }, + { + "type" : "CIMCharacterMarker", + "enable" : true, + "colorLocked" : true, + "anchorPoint" : { + "x" : 0, + "y" : 0, + "z" : 0 + }, + "anchorPointUnits" : "Absolute", + "dominantSizeAxis3D" : "Y", + "offsetX" : 1.5, + "offsetY" : -1.5, + "size" : 4, + "billboardMode3D" : "FaceNearPlane", + "characterIndex" : 34, + "fontFamilyName" : "ESRI Default Marker", + "fontStyleName" : "Regular", + "fontType" : "Unspecified", + "scaleX" : 1, + "symbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidStroke", + "enable" : true, + "capStyle" : "Round", + "joinStyle" : "Round", + "lineStyle3D" : "Strip", + "miterLimit" : 4, + "width" : 1, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + }, + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + } + ] + }, + "scaleSymbolsProportionally" : true, + "respectFrame" : true + }, + { + "type" : "CIMCharacterMarker", + "enable" : true, + "colorLocked" : true, + "anchorPoint" : { + "x" : 0, + "y" : 0, + "z" : 0 + }, + "anchorPointUnits" : "Absolute", + "dominantSizeAxis3D" : "Y", + "offsetX" : 1.5, + "offsetY" : 1.5, + "size" : 4, + "billboardMode3D" : "FaceNearPlane", + "characterIndex" : 34, + "fontFamilyName" : "ESRI Default Marker", + "fontStyleName" : "Regular", + "fontType" : "Unspecified", + "scaleX" : 1, + "symbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidStroke", + "enable" : true, + "capStyle" : "Round", + "joinStyle" : "Round", + "lineStyle3D" : "Strip", + "miterLimit" : 4, + "width" : 1, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + }, + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + } + ] + }, + "scaleSymbolsProportionally" : true, + "respectFrame" : true + }, + { + "type" : "CIMCharacterMarker", + "enable" : true, + "colorLocked" : true, + "anchorPointUnits" : "Relative", + "dominantSizeAxis3D" : "Y", + "size" : 10, + "billboardMode3D" : "FaceNearPlane", + "characterIndex" : 34, + "fontFamilyName" : "ESRI Default Marker", + "fontStyleName" : "Regular", + "fontType" : "Unspecified", + "scaleX" : 1, + "symbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidStroke", + "enable" : true, + "capStyle" : "Round", + "joinStyle" : "Round", + "lineStyle3D" : "Strip", + "miterLimit" : 10, + "width" : 1, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + }, + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 240, + 240, + 240, + 0 + ] + } + } + ] + }, + "respectFrame" : true + } + ], + "haloSize" : 1, + "scaleX" : 1, + "angleAlignment" : "Map" + } + }, + "upperBound" : 50 + }, + { + "type" : "CIMClassBreak", + "label" : "> 3000 l/min", + "patch" : "Default", + "symbol" : { + "type" : "CIMSymbolReference", + "symbol" : { + "type" : "CIMPointSymbol", + "symbolLayers" : [ + { + "type" : "CIMCharacterMarker", + "enable" : true, + "anchorPointUnits" : "Relative", + "dominantSizeAxis3D" : "Y", + "size" : 10, + "billboardMode3D" : "FaceNearPlane", + "characterIndex" : 34, + "fontFamilyName" : "ESRI Default Marker", + "fontStyleName" : "Regular", + "fontType" : "Unspecified", + "scaleX" : 1, + "symbol" : { + "type" : "CIMPolygonSymbol", + "symbolLayers" : [ + { + "type" : "CIMSolidStroke", + "enable" : true, + "capStyle" : "Round", + "joinStyle" : "Round", + "lineStyle3D" : "Strip", + "miterLimit" : 4, + "width" : 1, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + }, + { + "type" : "CIMSolidFill", + "enable" : true, + "color" : { + "type" : "CIMRGBColor", + "values" : [ + 230, + 0, + 0, + 100 + ] + } + } + ] + }, + "scaleSymbolsProportionally" : true, + "respectFrame" : true + } + ], + "haloSize" : 1, + "scaleX" : 1, + "angleAlignment" : "Map" + } + }, + "upperBound" : 20000 + } + ], + "classBreakType" : "GraduatedColor", + "classificationMethod" : "Manual", + "colorRamp" : { + "type" : "CIMPolarContinuousColorRamp", + "colorSpace" : { + "type" : "CIMICCColorSpace", + "url" : "Default RGB" + }, + "fromColor" : { + "type" : "CIMHSVColor", + "values" : [ + 0, + 30, + 100, + 100 + ] + }, + "toColor" : { + "type" : "CIMHSVColor", + "values" : [ + 0, + 100, + 50, + 100 + ] + }, + "interpolationSpace" : "HSV", + "polarDirection" : "Auto" + }, + "field" : "BEW_FOERDE", + "numberFormat" : { + "type" : "CIMNumericFormat", + "alignmentOption" : "esriAlignLeft", + "alignmentWidth" : 12, + "roundingOption" : "esriRoundNumberOfDecimals", + "roundingValue" : 6, + "zeroPad" : true + }, + "showInAscendingOrder" : true, + "heading" : "Bewilligte Entnahmeleistung", + "sampleSize" : 10000, + "defaultSymbolPatch" : "Default", + "polygonSymbolColorTarget" : "Fill", + "normalizationTotal" : 1, + "normalizationType" : "Nothing", + "useExclusionSymbol" : false, + "exclusionSymbolPatch" : "Default" + }, + "scaleSymbols" : true, + "snappable" : true + } + ], + "binaryReferences" : [ + { + "type" : "CIMBinaryReference", + "uRI" : "CIMPATH=Metadata/53b587d48a512831970f8c36e6b0442c.xml", + "data" : "\r\n20221103025254001.0TRUETrinkwasserfassungen\r\n" + } + ], + "rGBColorProfile" : "sRGB IEC61966-2.1", + "cMYKColorProfile" : "U.S. Web Coated (SWOP) v2" +} diff --git a/src/LyrxParser.spec.ts b/src/LyrxParser.spec.ts index 2d116e6..5bf657b 100644 --- a/src/LyrxParser.spec.ts +++ b/src/LyrxParser.spec.ts @@ -1,7 +1,7 @@ import { expect, it, describe, beforeAll } from 'vitest'; import fs from 'fs'; import { LyrxParser } from './LyrxParser'; -import { ReadStyleResult, Rule } from 'geostyler-style'; +import {ReadStyleResult, Rule, TextSymbolizer} from 'geostyler-style'; describe('LyrxParser should parse ae_netzbetreiber.lyrx', () => { let lyrx: any; @@ -141,3 +141,25 @@ describe('LyrxParser should parse feature-layer-point-graduated-colors-renderer. expect(symbolizer.strokeOpacity).toEqual(1); }); }); + +describe('LyrxParser should parse afu_gwn_02.lyrx', () => { + let lyrx: any; + let lyrxParser: LyrxParser; + let geostylerStyle: ReadStyleResult; + + beforeAll(async () => { + lyrxParser = new LyrxParser(); + lyrx = JSON.parse( + fs.readFileSync('./data/lyrx/afu_gwn_02.lyrx', 'utf8') + ); + geostylerStyle = await lyrxParser.readStyle(lyrx); + }); + + it('should have parse label expression', () => { + const rules = geostylerStyle.output!.rules; + expect(rules.length).toEqual(6); + const textSymbolizer = rules[5].symbolizers[0] as TextSymbolizer; + expect(textSymbolizer.kind).toEqual('Text'); + expect(textSymbolizer.label).toEqual('{{bew_nr}} / {{bew_foerde}} l/s'); + }); +}); \ No newline at end of file diff --git a/src/expressions.ts b/src/expressions.ts index c0084eb..57dbcd7 100644 --- a/src/expressions.ts +++ b/src/expressions.ts @@ -1,35 +1,31 @@ import {WellKnownText} from './customProperties'; import { LabelExpressionEngine } from './esri/types'; -export const convertExpression = (rawExpression: string, engine: LabelExpressionEngine, toLowerCase: boolean) => { +export const convertExpression = ( + rawExpression: string, engine: LabelExpressionEngine, + toLowerCase: boolean +): string => { let expression: string = rawExpression; if (engine === LabelExpressionEngine.Arcade) { expression = convertArcadeExpression(rawExpression); } - if (toLowerCase) { expression = rawExpression.toLowerCase(); } - if (expression.includes('+') || expression.includes('&')) { - let tokens: string[] = expression.includes('+') ? expression.split('+').reverse() : expression.split('&').reverse(); - let addends = []; - for (let token of tokens) { + const tokens = expression.includes('+') ? expression.split('+') : expression.split('&'); + const parsedExpression = tokens.map((token) => { + token = token.trimStart().trimEnd(); if (token.includes('[')) { - addends.push(['PropertyName', processPropertyName(token)]); + return processPropertyName(token); } else { - let literal = token.replaceAll('"', ''); - addends.push(replaceSpecialLiteral(literal)); - } - let allOps: any = addends[0]; - for (let attr of addends.slice(1)) { - allOps = ['Concatenate', attr, allOps]; + const literal = token.replaceAll('"', ''); + return replaceSpecialLiteral(literal); } - expression = allOps; - } - return expression; + }); + return parsedExpression.join(''); } - return ['PropertyName', processPropertyName(expression)]; + return processPropertyName(expression); }; @@ -116,7 +112,7 @@ const replaceSpecialLiteral = (literal: string): string => { }; const processPropertyName = (token: string): string => { - return token.replace('[', '').replace(']', '').trim(); + return token.replace('[', '{{').replace(']', '}}').trim(); }; const convertArcadeExpression = (expression: string): string => { diff --git a/src/toGeostyler.ts b/src/toGeostyler.ts index c499985..594518b 100644 --- a/src/toGeostyler.ts +++ b/src/toGeostyler.ts @@ -200,7 +200,7 @@ const processLabelClass = ( rotate: 0.0, color: color, font: fontFamily, - label: Array.isArray(expression) ? expression.join('-') : expression, // FIXME + label: expression, size: fontSize, weight: fontWeight, };