Skip to content
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
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/>
</head>
<body>
<my-map zoom="18" maxZoom="23" drawMode drawPointer="dot" id="example-map" />
<my-map zoom="20" maxZoom="23" drawMode drawPointer="dot" id="example-map" />

<script>
const map = document.querySelector("my-map");
Expand Down
20 changes: 16 additions & 4 deletions src/my-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,23 +381,35 @@ export class MyMap extends LitElement {
});
}

// show snapping points when in drawMode, with vector tile basemap enabled, and at zoom > 20
// show snapping points when in drawMode, with vector tile basemap enabled, and at qualifying zoom
if (
this.drawMode &&
Boolean(this.osVectorTilesApiKey) &&
!this.disableVectorTiles
) {
// define zoom threshold for showing snaps (not @property yet because computationally expensive!)
const snapsZoom: number = 20;
Comment on lines +390 to +391
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree that making this accessible would be a bad idea!


// display draw vertices on top of snap points
map.addLayer(pointsLayer);
drawingLayer.setZIndex(1001); // display draw vertices on top of snap points
drawingLayer.setZIndex(1001);

// extract snap-able points from the basemap, and display them as points on the map if initial render within zoom
if (this.zoom < snapsZoom) {
pointsSource.clear();
const extent = map.getView().calculateExtent(map.getSize());
getSnapPointsFromVectorTiles(osVectorTileBaseMap, extent);
}

// continue to fetch & update snaps as map moves
map.on("moveend", () => {
const currentZoom: number | undefined = map.getView().getZoom();
if (currentZoom && currentZoom < 20) {
if (currentZoom && currentZoom < snapsZoom) {
pointsSource.clear();
return;
}

// extract snap-able points from the basemap, and display them as points on the map
// timeout minimizes snap updates mid-pan/drag
setTimeout(() => {
pointsSource.clear();
const extent = map.getView().calculateExtent(map.getSize());
Expand Down