Fix long click behaviour

pull/147/head
Candid Dauth 2021-04-08 18:27:46 +02:00
rodzic 1087b7cd64
commit 283a9a8cc1
2 zmienionych plików z 6 dodań i 19 usunięć

Wyświetl plik

@ -64,26 +64,13 @@ export default class ClickMarker extends Vue {
async handleMapLongClick(pos: Point): Promise<void> {
const now = Date.now();
if (now - this.lastClick < 500) {
// Hacky solution to avoid markers being created when the user double-clicks the map. If multiple clicks happen less than 500 ms from each
// other, all those clicks are ignored.
this.lastClick = now;
return;
}
this.lastClick = now;
const [results] = await Promise.all([
this.client.find({
query: `geo:${round(pos.lat, 5)},${round(pos.lon, 5)}?z=${this.mapContext.zoom}`,
loadUrls: false,
elevation: true
}),
new Promise((resolve) => {
// Specify the minimum time the search will take to allow for some time for the double-click detection
setTimeout(resolve, 500);
})
]);
const results = await this.client.find({
query: `geo:${round(pos.lat, 5)},${round(pos.lon, 5)}?z=${this.mapContext.zoom}`,
loadUrls: false,
elevation: true
});
if (now !== this.lastClick) {
// There has been another click since the one we are reacting to.

Wyświetl plik

@ -153,7 +153,7 @@ async function _findOsmObject(type: string, id: string, loadElevation = false):
async function _findLonLat(lonlatWithZoom: PointWithZoom, loadElevation = false): Promise<Array<SearchResult>> {
const [body, elevation] = await Promise.all([
request({
url: `${nameFinderUrl}/reverse?format=json&addressdetails=1&polygon_geojson=1&extratags=1&namedetails=1&lat=${encodeURIComponent(lonlatWithZoom.lat)}&lon=${encodeURIComponent(lonlatWithZoom.lon)}&zoom=${encodeURIComponent(lonlatWithZoom.zoom != null ? (lonlatWithZoom.zoom >= 12 ? lonlatWithZoom.zoom+2 : lonlatWithZoom.zoom) : 17)}`,
url: `${nameFinderUrl}/reverse?format=json&addressdetails=1&polygon_geojson=0&extratags=1&namedetails=1&lat=${encodeURIComponent(lonlatWithZoom.lat)}&lon=${encodeURIComponent(lonlatWithZoom.lon)}&zoom=${encodeURIComponent(lonlatWithZoom.zoom != null ? (lonlatWithZoom.zoom >= 12 ? lonlatWithZoom.zoom+2 : lonlatWithZoom.zoom) : 17)}`,
json: true
}),
...(loadElevation ? [getElevationForPoint(lonlatWithZoom)] : [])