Skip to content

Commit

Permalink
shrink requested bound in browse mode to fully fit markers
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Oct 13, 2023
1 parent e132d58 commit 6718579
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/fetch-dialog/browse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class NoteBrowseFetchDialog extends DynamicNoteFetchDialog {
this.updateNotesIfNeeded()
}
protected constructQuery(): NoteQuery | undefined {
const bboxValue=this.map.precisionBounds.wsen.join(',')
const bboxValue=this.map.precisionMarkerBounds.wsen.join(',')
return makeNoteBrowseQueryFromValues(
bboxValue,this.closedValue
)
Expand Down
15 changes: 15 additions & 0 deletions src/map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,24 @@ export default class NoteMap {
get bounds(): L.LatLngBounds {
return this.leafletMap.getBounds()
}
get markerBounds(): L.LatLngBounds {
const z=this.zoom
const bs=this.bounds
const [ne,sw]=NoteMarker.shrinkPixelBoundsToContainEntireMarkers(
this.leafletMap.project(bs.getNorthEast(),z),
this.leafletMap.project(bs.getSouthWest(),z)
)
return L.latLngBounds(
this.leafletMap.unproject(ne,z),
this.leafletMap.unproject(sw,z)
)
}
get precisionBounds(): NoteMapBounds {
return new NoteMapBounds(this.bounds,this.precision)
}
get precisionMarkerBounds(): NoteMapBounds {
return new NoteMapBounds(this.markerBounds,this.precision)
}
private fitBoundsIfNotFrozen(bounds: L.LatLngBoundsExpression): void {
if (this.freezeMode) return
this.leafletMap.fitBounds(bounds)
Expand Down
11 changes: 9 additions & 2 deletions src/map/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {escapeXml, makeEscapeTag} from '../util/escape'

const e=makeEscapeTag(escapeXml)

const width=25
const height=40

export default class NoteMarker extends L.Marker {
noteId: number
$a: HTMLAnchorElement
Expand All @@ -21,11 +24,15 @@ export default class NoteMarker extends L.Marker {
const icon=getNoteMarkerIcon(this.$a,web,note,isSelected)
this.setIcon(icon)
}
static shrinkPixelBoundsToContainEntireMarkers(ne: L.Point, sw: L.Point): [ne: L.Point, sw: L.Point] {
return [
L.point(ne.x-width/2,ne.y+height),
L.point(sw.x+width/2,sw.y),
]
}
}

function getNoteMarkerIcon($a: HTMLAnchorElement, web: WebProvider, note: Note, isSelected: boolean): L.DivIcon {
const width=25
const height=40
const auraThickness=4
const r=width/2
const widthWithAura=width+auraThickness*2
Expand Down

0 comments on commit 6718579

Please sign in to comment.