mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
faster distance calc
This commit is contained in:
parent
2e9b332012
commit
34f98fb08b
8 changed files with 101 additions and 80 deletions
|
@ -18,7 +18,7 @@ import {
|
|||
LatLngLiteral,
|
||||
} from 'leaflet';
|
||||
|
||||
import { distKm, distToSegment, getPolyLength, pointInArea } from '~/utils/geom';
|
||||
import { distKmHaversine, distToSegment, getPolyLength, pointInArea } from '~/utils/geom';
|
||||
|
||||
interface InteractivePolylineOptions extends PolylineOptions {
|
||||
maxMarkers?: number;
|
||||
|
@ -268,11 +268,11 @@ export class InteractivePoly extends Polyline {
|
|||
const prev = this.markers[index];
|
||||
const next = this.markers[index + 1];
|
||||
|
||||
const initial_distance = distKm(prev.getLatLng(), next.getLatLng());
|
||||
const initial_distance = distKmHaversine(prev.getLatLng(), next.getLatLng());
|
||||
|
||||
const current_distance =
|
||||
((prev && distKm(prev.getLatLng(), current)) || 0) +
|
||||
((next && distKm(next.getLatLng(), current)) || 0);
|
||||
((prev && distKmHaversine(prev.getLatLng(), current)) || 0) +
|
||||
((next && distKmHaversine(next.getLatLng(), current)) || 0);
|
||||
|
||||
this.distance += current_distance - initial_distance;
|
||||
|
||||
|
@ -369,12 +369,12 @@ export class InteractivePoly extends Polyline {
|
|||
const next = index <= this.markers.length + 1 ? this.markers[index + 1] : null;
|
||||
|
||||
const initial_distance =
|
||||
((prev && distKm(prev.getLatLng(), initial)) || 0) +
|
||||
((next && distKm(next.getLatLng(), initial)) || 0);
|
||||
((prev && distKmHaversine(prev.getLatLng(), initial)) || 0) +
|
||||
((next && distKmHaversine(next.getLatLng(), initial)) || 0);
|
||||
|
||||
const current_distance =
|
||||
((prev && distKm(prev.getLatLng(), current)) || 0) +
|
||||
((next && distKm(next.getLatLng(), current)) || 0);
|
||||
((prev && distKmHaversine(prev.getLatLng(), current)) || 0) +
|
||||
((next && distKmHaversine(next.getLatLng(), current)) || 0);
|
||||
|
||||
this.distance += current_distance - initial_distance;
|
||||
|
||||
|
@ -448,7 +448,7 @@ export class InteractivePoly extends Polyline {
|
|||
|
||||
const point = this.drawing_direction === 'forward' ? latlngs[latlngs.length - 1] : latlngs[0];
|
||||
|
||||
this.distance += distKm(point, latlng);
|
||||
this.distance += distKmHaversine(point, latlng);
|
||||
this.fire('distancechange', { distance: this.distance });
|
||||
};
|
||||
|
||||
|
@ -493,9 +493,9 @@ export class InteractivePoly extends Polyline {
|
|||
const next = index <= latlngs.length + 1 ? latlngs[index + 1] : null;
|
||||
|
||||
const initial_distance =
|
||||
((prev && distKm(prev, current)) || 0) + ((next && distKm(next, current)) || 0);
|
||||
((prev && distKmHaversine(prev, current)) || 0) + ((next && distKmHaversine(next, current)) || 0);
|
||||
|
||||
const current_distance = (prev && next && distKm(prev, next)) || 0;
|
||||
const current_distance = (prev && next && distKmHaversine(prev, next)) || 0;
|
||||
|
||||
this.distance += current_distance - initial_distance;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue