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: account for no dasharray property in the simplelinesybol #131

Merged
merged 2 commits into from
Feb 6, 2025
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
34 changes: 33 additions & 1 deletion src/lib/legend/symbol-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,44 @@ export function createLineSymbol(symbolizers: Symbolizer[]): __esri.Symbol {
"stroke-dasharray": strokeDasharray,
} = lineSymbolizer;

/**
* The following code addresses the issue of mapping dasharray patterns to ArcGIS SimpleLineSymbol styles.
* Because the SLD spec uses dasharray patterns that are not directly supported by the ArcGIS JS API,
* the code maps the dasharray patterns to the closest supported style in ArcGIS JS API.
* See the style options at: https://developers.arcgis.com/javascript/latest/api-reference/esri-symbols-SimpleLineSymbol.html?#style
* If new patterns are needed, they need to be added to the map below.
*/

type LineSymbolStyle = "solid" | "dash" | "dash-dot" | "dot" | "long-dash" | "long-dash-dot" | "long-dash-dot-dot" | "none" | "short-dash" | "short-dash-dot" | "short-dash-dot-dot" | "short-dot";


// Explicitly typing the dashMap to be a Record with string keys and string values
const dashMap: Record<string, LineSymbolStyle> = {
'8.0,2.0': 'short-dash',
'3.0,3.0': 'short-dot',
'4.0,4.0': 'long-dash',
'1.0,1.0': 'dot',
// Add more patterns as needed
};

// Function to map dasharray to the style using the lookup object
function mapDashArrayToStyle(dasharray: string[]): LineSymbolStyle {
// Create a key by joining the dasharray values (which now include decimals)
const dashKey = dasharray.join(',');

// Return the corresponding style from the object, or default to 'solid' if not found
return dashMap[dashKey] || 'solid';
}

// Map the dash array to one of the GeoServer styles
const style = strokeDasharray ? mapDashArrayToStyle(strokeDasharray) : 'solid';

return new SimpleLineSymbol({
color: stroke,
width: strokeWidth,
cap: strokeLinecap,
join: strokeLinejoin,
style: strokeDasharray ? "dash" : "solid",
style: style, // Use the mapped style here
miterLimit: 2,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types/geoserver-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface StrokeSymbolizer {
"stroke-opacity": string,
"stroke-linecap": LineCap,
"stroke-linejoin": LineJoin,
"stroke-dasharray": string,
"stroke-dasharray": string[],
"stroke-dashoffset": string
}

Expand Down