dist and time

finishing route
This commit is contained in:
muerwre 2018-08-24 12:36:36 +07:00
parent 102328a1b2
commit b8545105c8
15 changed files with 195 additions and 37 deletions

21
src/utils/simplify.js Normal file
View 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;
};