Skip to content

Commit

Permalink
Support ppen's ratio attributes in CourseAppearance
Browse files Browse the repository at this point in the history
  • Loading branch information
perliedman committed Aug 31, 2022
1 parent 080add3 commit 29b4eb2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
28 changes: 20 additions & 8 deletions src/course-feature-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function useStyle(
layer,
featuresRef,
objScale,
courseAppearance,
courseOverPrintColor = courseOverPrintRgb,
styleWrapper
) {
Expand All @@ -28,11 +29,12 @@ export default function useStyle(
courseFeatureStyle(
featuresRef,
objScale,
courseAppearance,
courseOverPrintColor,
feature,
resolution
),
[featuresRef, objScale, courseOverPrintColor]
[featuresRef, objScale, courseAppearance, courseOverPrintColor]
);
useEffect(() => {
layer.setStyle(
Expand All @@ -46,6 +48,7 @@ export default function useStyle(
export function courseFeatureStyle(
featuresRef,
objScale,
courseAppearance,
courseOverPrintColor,
feature,
resolution
Expand All @@ -55,6 +58,11 @@ export function courseFeatureStyle(
? palette[feature.get("color")]
: courseOverPrintColor;
let style;
const {
controlCircleSizeRatio = 1,
lineWidthRatio = 1,
numberSizeRatio = 1,
} = courseAppearance;

// Note: where applicable, always use setRadius *last*, since that is what
// forces OL to actually update the style of circles.
Expand All @@ -63,14 +71,16 @@ export function courseFeatureStyle(
if (kind === "normal") {
const image = controlStyle.getImage();
const stroke = image.getStroke();
stroke.setWidth(dimension(overprintLineWidth));
stroke.setWidth(dimension(overprintLineWidth * controlCircleSizeRatio));
stroke.setColor(color);
image.setRadius(dimension(controlCircleOutsideDiameter / 2));
image.setRadius(
dimension(controlCircleOutsideDiameter / 2) * controlCircleSizeRatio
);
style = controlStyle;
} else if (kind === "start") {
style = getStartStyle(color);
const image = style.getImage();
image.setScale(dimension(0.05));
image.setScale(dimension(0.05 * controlCircleSizeRatio));

const next = featuresRef.current[feature.get("index") + 1];
if (next) {
Expand All @@ -85,20 +95,22 @@ export function courseFeatureStyle(
finishStyle.forEach((style, i) => {
const image = style.getImage();
const stroke = image.getStroke();
stroke.setWidth(dimension(overprintLineWidth));
stroke.setWidth(dimension(overprintLineWidth) * controlCircleSizeRatio);
stroke.setColor(color);
image.setRadius(dimension(2 + i));
image.setRadius(dimension(2 + i) * controlCircleSizeRatio);
});
style = finishStyle;
} else if (kind === "line") {
const stroke = lineStyle.getStroke();
stroke.setWidth(dimension(feature.get("lineWidth") || overprintLineWidth));
stroke.setWidth(
dimension(feature.get("lineWidth") || overprintLineWidth) * lineWidthRatio
);
stroke.setColor(color);
style = lineStyle;
} else if (kind === "number") {
const text = numberStyle.getText();
text.setText(feature.get("label"));
text.setScale(dimension(0.6));
text.setScale(dimension(0.6) * numberSizeRatio);
style = numberStyle;
} else if (kind === "white-out") {
style = whiteOutStyle;
Expand Down
6 changes: 6 additions & 0 deletions src/models/course-appearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export function create(options?: CourseAppearance): CourseAppearance {
scaleSizesCircleGaps: true,
autoLegGapSize: 0,
blendPurple: true,
controlCircleSizeRatio: 1,
lineWidthRatio: 1,
numberSizeRatio: 1,
...options,
};
}
Expand All @@ -13,4 +16,7 @@ export interface CourseAppearance {
scaleSizesCircleGaps: boolean;
autoLegGapSize: number;
blendPurple: boolean;
controlCircleSizeRatio: number;
lineWidthRatio: number;
numberSizeRatio: number;
}
8 changes: 8 additions & 0 deletions src/services/ppen.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ export function parsePPen(doc) {
autoLegGapSize:
Number(courseAppearanceTag.getAttribute("auto-leg-gap-size")) || 0,
blendPurple: courseAppearanceTag.getAttribute("blend-purple") === "true",
controlCircleSizeRatio:
Number(courseAppearanceTag.getAttribute("control-circle-size-ratio")) ||
1,
lineWidthRatio:
Number(courseAppearanceTag.getAttribute("line-width-ratio")) || 1,

numberSizeRatio:
Number(courseAppearanceTag.getAttribute("number-size-ratio")) || 1,
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/tools/EditControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ export default function EditControls() {
return courseFeatureStyle(
featuresRef,
f * objScale,
courseAppearance,
selectedOverPrintRgb,
feature,
resolution
);
},
[crs, featuresRef, objScale]
[crs, featuresRef, objScale, courseAppearance]
);

const highlightFeatureRef = useRef();
Expand Down
4 changes: 3 additions & 1 deletion src/tools/use-other-controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default function useOtherControls({
return courseFeatureStyle(
{ current: [] },
f * objScale,
courseAppearance,
selectedOverPrintRgb,
feature,
resolution
Expand All @@ -83,7 +84,7 @@ export default function useOtherControls({
return fallbackStyleFn(feature, resolution);
}
},
[highlightFeatureRef, f, objScale]
[highlightFeatureRef, f, objScale, courseAppearance]
);

const controlFeaturesRef = useRef(controlFeatures);
Expand All @@ -92,6 +93,7 @@ export default function useOtherControls({
controlsLayer,
controlFeaturesRef,
f * objScale,
courseAppearance,
"rgba(182, 44, 152, 0.5)",
highlighStyleFn
);
Expand Down

0 comments on commit 29b4eb2

Please sign in to comment.