Skip to content

Feature/draw ol#284

Merged
dannyleech merged 28 commits into
mainfrom
feature/draw-ol
May 19, 2026
Merged

Feature/draw ol#284
dannyleech merged 28 commits into
mainfrom
feature/draw-ol

Conversation

@dannyleech
Copy link
Copy Markdown
Contributor

No description provided.

@dannyleech dannyleech requested a review from markfee May 19, 2026 08:06

/** Get a GeoJSON feature by ID, or null. */
get (id) {
const feature = source.getFeatureById(String(id))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not this.getOL(id) - to avoid repeating this line throughout

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that, thanks

/** Add or replace a GeoJSON feature. Returns the OL Feature. */
add (geojsonFeature) {
const existing = source.getFeatureById(geojsonFeature.id)
if (existing) source.removeFeature(existing)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about:
const existing = this.getOL(geojsonFeature.id)

avoids repeating the line

const ctx = state.context
const pr = state.pixelRatio
const [cx, cy] = /** @type {number[]} */ (pixelCoordinates)
ctx.save()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// could you replace the following code with a function that draws the same thing but is reusable?
ctx.beginPath(); ctx.arc(cx, cy, outer * pr, 0, Math.PI * 2); ctx.fillStyle = colors.editActive; ctx.fill()
ctx.beginPath(); ctx.arc(cx, cy, mid * pr, 0, Math.PI * 2); ctx.fillStyle = colors.editHalo; ctx.fill()
ctx.beginPath(); ctx.arc(cx, cy, inner * pr, 0, Math.PI * 2); ctx.fillStyle = colors[innerKey]; ctx.fill()

drawContextPath(ctx, cx, cy, whateverThisShouldBeCalled, fillStyle) {
ctx.beginPath()
ctx.arc(cx, cy, whateverThisShouldBeCalled * pr, 0, Math.PI * 2)
ctx.fillStyle = fillStyle
ctx.fill()
}
// So you would have:
drawContextPath(ctx, cx, cy, outer, colors.editActive)
drawContextPath(ctx, cx, cy, mid, colors.editHalo)
drawContextPath(ctx, cx, cy, inner, colors[innerKey])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, much better

}

const nudge = (e) => {
const { selectedVertexIndex, selectedVertexType, vertecies, midpoints, olFeature } = getState()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vertecies spelling should be vertices

const offsets = { ArrowUp: [0, -step], ArrowDown: [0, step], ArrowLeft: [-step, 0], ArrowRight: [step, 0] }
const [dx, dy] = offsets[e.key]

if (selectedVertexType === 'midpoint') {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would a nudgeMidpoint method here be better, than a large if and early return

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// Escape if snap is preventing sufficient progress in the intended direction.
// Covers vertex-stuck (newCoord === current) and edge-hugging (vertex slides
// along edge instead of moving away from it).
if (snap) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see where snap is defined - should it be this.snap?

could this be a method snapCoord(...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It comes in through the function args

const numPairs = (end - start) / 2
const edgeCount = isClosedRing ? numPairs : numPairs - 1

for (let i = 0; i < numPairs; i++) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to a getBestPair method?

}
}

for (let i = 0; i < edgeCount; i++) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to a getBestEdge method

Copy link
Copy Markdown
Collaborator

@markfee markfee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few suggestions.
The HUGE prs are creeping in again, please try to keep them small.

a few suggestions inline,

Things like keyboardActions / touch actions might be better decoupled from the effect.
Ie - move the effect, such as nudgingPoints out, and just have the keyboardActions call the effect.

@sonarqubecloud
Copy link
Copy Markdown

@dannyleech dannyleech merged commit 40ff758 into main May 19, 2026
2 checks passed
@dannyleech dannyleech deleted the feature/draw-ol branch May 19, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants