mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
km marks initial
This commit is contained in:
parent
c853d656b8
commit
d4c839a422
5 changed files with 186 additions and 34 deletions
|
@ -33,8 +33,8 @@ export class Component extends Polyline {
|
|||
|
||||
this.constraintsStyle = { ...this.constraintsStyle, ...options.constraintsStyle };
|
||||
this.maxMarkers = options.maxMarkers || this.maxMarkers;
|
||||
this.kmMarksEnabled = options.kmMarksEnabled || this.kmMarksEnabled;
|
||||
this.kmMarksStep = options.kmMarksStep || this.kmMarksStep;
|
||||
// this.kmMarksEnabled = options.kmMarksEnabled || this.kmMarksEnabled;
|
||||
// this.kmMarksStep = options.kmMarksStep || this.kmMarksStep;
|
||||
|
||||
this.constrLine = new Polyline([], this.constraintsStyle);
|
||||
|
||||
|
@ -49,7 +49,7 @@ export class Component extends Polyline {
|
|||
this.setLatLngs(latlngs);
|
||||
this.recreateMarkers();
|
||||
this.recalcDistance();
|
||||
this.recalcKmMarks();
|
||||
// this.recalcKmMarks();
|
||||
this.touchHinter.setLatLngs(latlngs);
|
||||
this.fire('latlngschange', { latlngs });
|
||||
};
|
||||
|
@ -483,35 +483,35 @@ export class Component extends Polyline {
|
|||
|
||||
this.fire('distancechange', { distance: this.distance });
|
||||
};
|
||||
//
|
||||
// recalcKmMarks = () => {
|
||||
// if (!this.kmMarksEnabled) return;
|
||||
//
|
||||
// const latlngs = this.getLatLngs() as LatLngLiteral[];
|
||||
//
|
||||
// this.kmMarks = { };
|
||||
//
|
||||
// let last_km_mark = 0;
|
||||
//
|
||||
// latlngs.reduce((dist, latlng, index) => {
|
||||
// if (index >= latlngs.length - 1) return;
|
||||
//
|
||||
// const next = latlngs[index + 1];
|
||||
// const sum = dist + distKm(latlng, next);
|
||||
// const rounded = Math.floor(dist / this.kmMarksStep) * this.kmMarksStep;
|
||||
//
|
||||
// if (rounded > last_km_mark) {
|
||||
// last_km_mark = rounded;
|
||||
// this.kmMarks[rounded] = latlng;
|
||||
// }
|
||||
//
|
||||
// return sum;
|
||||
// }, 0);
|
||||
// };
|
||||
|
||||
recalcKmMarks = () => {
|
||||
if (!this.kmMarksEnabled) return;
|
||||
|
||||
const latlngs = this.getLatLngs() as LatLngLiteral[];
|
||||
|
||||
this.kmMarks = { };
|
||||
|
||||
let last_km_mark = 0;
|
||||
|
||||
latlngs.reduce((dist, latlng, index) => {
|
||||
if (index >= latlngs.length - 1) return;
|
||||
|
||||
const next = latlngs[index + 1];
|
||||
const sum = dist + distKm(latlng, next);
|
||||
const rounded = Math.floor(dist / this.kmMarksStep) * this.kmMarksStep;
|
||||
|
||||
if (rounded > last_km_mark) {
|
||||
last_km_mark = rounded;
|
||||
this.kmMarks[rounded] = latlng;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}, 0);
|
||||
};
|
||||
|
||||
kmMarksEnabled?: InteractivePolylineOptions['kmMarksEnabled'] = true;
|
||||
kmMarksStep?: InteractivePolylineOptions['kmMarksStep'] = 5;
|
||||
kmMarks?: { [x: number]: LatLngLiteral };
|
||||
// kmMarksEnabled?: InteractivePolylineOptions['kmMarksEnabled'] = true;
|
||||
// kmMarksStep?: InteractivePolylineOptions['kmMarksStep'] = 5;
|
||||
// kmMarks?: { [x: number]: LatLngLiteral };
|
||||
// kmMarksLayer?: LayerGroup = new LayerGroup();
|
||||
|
||||
markers: Marker[] = [];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue