-
Notifications
You must be signed in to change notification settings - Fork 1
feat: snap to vector tile basemap features #75
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
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c0db6b7
snapping test
johnrees 510450b
remove unused feature
johnrees 0d38559
remove circular imports
johnrees 64d0c8a
change min zoom level for snaps
johnrees 705fd76
tweaks
johnrees c1b9508
zoom and tolerance tweaks
johnrees 4e6acdb
pixelTolerance
johnrees 23e509f
minzoom
johnrees 4442488
maxZoom
johnrees b2b8379
rebase to main, tidy up
jessicamcinchak 569b90d
fix conditional
jessicamcinchak 05831b6
simple styling, higher pixel tolerance
jessicamcinchak 54c33cd
clean up code comments
jessicamcinchak fbfe408
try crosshair cursor instead of dot
jessicamcinchak f80bccb
fix linter
jessicamcinchak 577ac9a
slightly better crosshair
jessicamcinchak 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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { Feature } from "ol"; | ||
| import Point from "ol/geom/Point"; | ||
| import { Vector as VectorLayer } from "ol/layer"; | ||
| import VectorTileLayer from "ol/layer/VectorTile"; | ||
| import VectorSource from "ol/source/Vector"; | ||
| import { Fill, Style } from "ol/style"; | ||
| import CircleStyle from "ol/style/Circle"; | ||
| import { splitEvery } from "rambda"; | ||
|
|
||
| export const pointsSource = new VectorSource({ | ||
| features: [], | ||
| wrapX: false, | ||
| }); | ||
|
|
||
| export const pointsLayer = new VectorLayer({ | ||
| source: pointsSource, | ||
| style: new Style({ | ||
| image: new CircleStyle({ | ||
| radius: 3, | ||
| fill: new Fill({ | ||
| color: "black", | ||
| }), | ||
| }), | ||
| }), | ||
| }); | ||
|
|
||
| /** | ||
| * Extract points that are available to snap to when a VectorTileLayer basemap is displayed | ||
| * @param basemap - a VectorTileLayer | ||
| * @param extent - an array of 4 points | ||
| * @returns - a VectorSource populated with points within the extent | ||
| */ | ||
| export function getSnapPointsFromVectorTiles( | ||
| basemap: VectorTileLayer, | ||
| extent: number[] | ||
| ) { | ||
| const points = basemap | ||
| .getSource() | ||
| .getFeaturesInExtent(extent) | ||
| .filter((feature) => feature.getGeometry().getType() !== "Point") | ||
| .flatMap((feature: any) => feature.flatCoordinates_); | ||
|
|
||
| return (splitEvery(2, points) as [number, number][]).forEach((pair, i) => { | ||
| pointsSource.addFeature( | ||
| new Feature({ | ||
| geometry: new Point(pair), | ||
| i, | ||
| }) | ||
| ); | ||
| }); | ||
| } |
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 |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| "emitDeclarationOnly": true, | ||
| "experimentalDecorators": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "lib": ["es2017", "dom", "dom.iterable"], | ||
| "lib": ["es2019", "dom", "dom.iterable"], | ||
|
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. Can we keep |
||
| "module": "es2020", | ||
| "moduleResolution": "node", | ||
| "noFallthroughCasesInSwitch": true, | ||
|
|
||
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.
Is this timeout really necessay?
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.
the timeout helps keep the zoom & pan interactions feeling a lot smoother in my opinion, and a bit more performant to only extract the snap points once a user has settled on location rather than mid-drag