mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
dist and time
finishing route
This commit is contained in:
parent
102328a1b2
commit
b8545105c8
15 changed files with 195 additions and 37 deletions
21
src/utils/simplify.js
Normal file
21
src/utils/simplify.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import L from 'leaflet';
|
||||
|
||||
export const simplify = ({ map, latlngs }) => {
|
||||
const points = [];
|
||||
const target = [];
|
||||
const zoom = 12;
|
||||
const mul = 0.7; // 0 - not simplifying, 1 - very rude.
|
||||
// its better to estimate mul value by route length
|
||||
|
||||
for (let i = 0; i < latlngs.length; i += 1) {
|
||||
points.push(map.project({ lat: latlngs[i].lat, lng: latlngs[i].lng }, zoom));
|
||||
}
|
||||
|
||||
const simplified = L.LineUtil.simplify(points, mul);
|
||||
|
||||
for (let i = 0; i < simplified.length; i += 1) {
|
||||
target.push(map.unproject(simplified[i], zoom));
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue