пропадали кружки при клике
Gitea Actions Demo / build_and_push (push) Successful in 1m17s
Details
Gitea Actions Demo / build_and_push (push) Successful in 1m17s
Details
This commit is contained in:
parent
e2a4c54358
commit
794b74cadb
|
|
@ -28,16 +28,17 @@
|
|||
<yandex-map-listener
|
||||
:settings="{
|
||||
onClick: (_: any, e: any) => {
|
||||
const xIndex = coordWithIndex.get(
|
||||
getKey(e.coordinates[0], e.coordinates[1]),
|
||||
const xIndex = findNearestTrackIndex(
|
||||
e.coordinates[0],
|
||||
e.coordinates[1],
|
||||
);
|
||||
if (mapX.length >= 2 || xIndex == undefined) {
|
||||
if (mapX.length >= 2 || xIndex < 0) {
|
||||
mapX = [];
|
||||
clickCoordinates = [];
|
||||
group.redrawAll();
|
||||
}
|
||||
if (xIndex !== undefined) {
|
||||
clickCoordinates.push(e.coordinates);
|
||||
if (xIndex >= 0) {
|
||||
clickCoordinates.push(lineCoordinates[xIndex] as LngLat);
|
||||
mapX.push(xIndex);
|
||||
group.redrawAll();
|
||||
}
|
||||
|
|
@ -81,7 +82,7 @@
|
|||
] as LngLat,
|
||||
onClick: (_: unknown, __: unknown) => openPhoto(photo),
|
||||
}"
|
||||
position="bottom-center"
|
||||
position="top-center left-center"
|
||||
>
|
||||
<div class="photo-single">1</div>
|
||||
</yandex-map-marker>
|
||||
|
|
@ -518,17 +519,30 @@ const group = new ChartGroup([]);
|
|||
const mapX = ref<Array<number>>([]);
|
||||
let currentCoordinates = ref<Array<number> | null>([]);
|
||||
let clickCoordinates = ref<LngLat[]>([]);
|
||||
let coordWithIndex: Map<string, number> = new Map();
|
||||
let showModalTitle = ref(false);
|
||||
const showModalLink = ref(false);
|
||||
const getKey = (x: number, y: number) => {
|
||||
x = Math.round(x * 1000) / 1000;
|
||||
y = Math.round(y * 1000) / 1000;
|
||||
return `${x}-${y}`;
|
||||
};
|
||||
const CLICK_TRACK_RADIUS_M = 40;
|
||||
/**
|
||||
* Finds the nearest track point index within CLICK_TRACK_RADIUS_M (metres)
|
||||
* of the clicked lng/lat using an equirectangular approximation. Returns -1
|
||||
* when the click is farther than the radius from every track point.
|
||||
*/
|
||||
const findNearestTrackIndex = (lng: number, lat: number): number => {
|
||||
let bestIdx = -1;
|
||||
let bestDist = Infinity;
|
||||
for (let i = 0; i < lineCoordinates.length; i++) {
|
||||
coordWithIndex.set(getKey(lineCoordinates[i][0], lineCoordinates[i][1]), i);
|
||||
const [pLng, pLat] = lineCoordinates[i];
|
||||
const midLatRad = ((lat + pLat) / 2) * (Math.PI / 180);
|
||||
const dx = (pLng - lng) * 111320 * Math.cos(midLatRad);
|
||||
const dy = (pLat - lat) * 110540;
|
||||
const dist = Math.hypot(dx, dy);
|
||||
if (dist < bestDist) {
|
||||
bestDist = dist;
|
||||
bestIdx = i;
|
||||
}
|
||||
}
|
||||
return bestDist <= CLICK_TRACK_RADIUS_M ? bestIdx : -1;
|
||||
};
|
||||
ChartJS.register(
|
||||
Title,
|
||||
Tooltip,
|
||||
|
|
|
|||
Loading…
Reference in New Issue