-
Notifications
You must be signed in to change notification settings - Fork 1
feat: enable drawing single point #232
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,28 +2,15 @@ import { MultiPoint, Polygon } from "ol/geom"; | |
| import { Draw, Modify, Snap } from "ol/interaction"; | ||
| import { Vector as VectorLayer } from "ol/layer"; | ||
| import { Vector as VectorSource } from "ol/source"; | ||
| import { Fill, RegularShape, Stroke, Style } from "ol/style"; | ||
| import { Circle, Fill, RegularShape, Stroke, Style } from "ol/style"; | ||
| import CircleStyle from "ol/style/Circle"; | ||
| import { StyleLike } from "ol/style/Style"; | ||
| import { pointsSource } from "./snapping"; | ||
|
|
||
| export type DrawTypeEnum = "Polygon" | "Point"; // ref https://openlayers.org/en/latest/apidoc/module-ol_geom_Geometry.html#~Type | ||
| export type DrawPointerEnum = "crosshair" | "dot"; | ||
|
|
||
| const redLineBase = { | ||
| color: "#ff0000", | ||
| width: 3, | ||
| }; | ||
|
|
||
| const redLineStroke = new Stroke(redLineBase); | ||
|
|
||
| const redDashedStroke = new Stroke({ | ||
| ...redLineBase, | ||
| lineDash: [2, 8], | ||
| }); | ||
|
|
||
| const redLineFill = new Fill({ | ||
| color: "rgba(255, 0, 0, 0.1)", | ||
| }); | ||
|
|
||
| // drawPointer styles | ||
| const crosshair = new RegularShape({ | ||
| stroke: new Stroke({ | ||
| color: "red", | ||
|
|
@@ -41,7 +28,24 @@ const dot = new CircleStyle({ | |
| }), | ||
| }); | ||
|
|
||
| const drawingVertices = new Style({ | ||
| // feature style: red-line site boundary | ||
| const redLineBase = { | ||
| color: "#ff0000", | ||
| width: 3, | ||
| }; | ||
|
|
||
| const redLineStroke = new Stroke(redLineBase); | ||
|
|
||
| const redDashedStroke = new Stroke({ | ||
| ...redLineBase, | ||
| lineDash: [2, 8], | ||
| }); | ||
|
|
||
| const redLineFill = new Fill({ | ||
| color: "rgba(255, 0, 0, 0.1)", | ||
| }); | ||
|
|
||
| const polygonVertices = new Style({ | ||
| image: new RegularShape({ | ||
| fill: new Fill({ | ||
| color: "#fff", | ||
|
|
@@ -66,28 +70,66 @@ const drawingVertices = new Style({ | |
| }, | ||
| }); | ||
|
|
||
| export const drawingSource = new VectorSource(); | ||
| const boundaryLayerStyle: StyleLike = [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there might be future scope for extracting these out into a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep totally fair, definitely getting a bit cluttered as-is ! |
||
| new Style({ | ||
| fill: redLineFill, | ||
| stroke: redLineStroke, | ||
| }), | ||
| polygonVertices, | ||
| ]; | ||
|
|
||
| function configureBoundaryDrawStyle(pointerStyle: DrawPointerEnum) { | ||
| return new Style({ | ||
| stroke: redDashedStroke, | ||
| fill: redLineFill, | ||
| image: pointerStyle === "crosshair" ? crosshair : dot, | ||
| }); | ||
| } | ||
|
|
||
| export const drawingLayer = new VectorLayer({ | ||
| source: drawingSource, | ||
| style: [ | ||
| new Style({ | ||
| fill: redLineFill, | ||
| stroke: redLineStroke, | ||
| // feature style: single point | ||
| function configurePointLayerStyle(pointColor: string) { | ||
| return new Style({ | ||
| image: new Circle({ | ||
| radius: 9, | ||
| fill: new Fill({ color: pointColor }), | ||
| }), | ||
| drawingVertices, | ||
| ], | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| function configurePointDrawStyle(pointColor: string) { | ||
| return new Style({ | ||
| fill: new Fill({ color: pointColor }), | ||
| }); | ||
| } | ||
|
|
||
| export function configureDraw(pointerStyle: DrawPointerEnum) { | ||
| export const drawingSource = new VectorSource(); | ||
|
|
||
| export function configureDrawingLayer( | ||
| drawType: DrawTypeEnum, | ||
| pointColor: string | ||
| ) { | ||
| return new VectorLayer({ | ||
| source: drawingSource, | ||
| style: | ||
| drawType === "Polygon" | ||
| ? boundaryLayerStyle | ||
| : configurePointLayerStyle(pointColor), | ||
| }); | ||
| } | ||
|
|
||
| // configure the key openlayers interactions | ||
| export function configureDraw( | ||
| drawType: DrawTypeEnum, | ||
| pointerStyle: DrawPointerEnum, | ||
| pointColor: string | ||
| ) { | ||
| return new Draw({ | ||
| source: drawingSource, | ||
| type: "Polygon", | ||
| style: new Style({ | ||
| stroke: redDashedStroke, | ||
| fill: redLineFill, | ||
| image: pointerStyle === "crosshair" ? crosshair : dot, | ||
| }), | ||
| type: drawType, | ||
| style: | ||
| drawType === "Polygon" | ||
| ? configureBoundaryDrawStyle(pointerStyle) | ||
| : configurePointDrawStyle(pointColor), | ||
| }); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍