I am drawing a route based on an array of coordinates. If the array has elements with coordinates of "[0,0]" I want to interrupt that line for that period and then continue the route when the values are non zero. The array looks like this:
and the route should look like this:
The code:
function lineDistance(x1, y1, x2, y2) {
var xs = 0,
ys = 0;
xs = x2 - x1;
xs = xs * xs;
ys = y2 - y1;
ys = ys * ys;
return Math.sqrt(xs + ys);
}
function nearest_point(lat, lng) {
var dist = Number.POSITIVE_INFINITY;
var it;
for (var i = 0, e = point_locs.length; i < e; ++i) {
var ld = lineDistance(lng.toString(), lat.toString(), point_locs[i].x, point_locs[i].y);
if (ld < dist) {
dist = ld
it = point_locs[i];
}
}
return it;
}
var marker = L.marker(new L.LatLng(point_locs[0][1], point_locs[0][0]), {
icon: L.icon({
iconUrl: 'https://tracking.dailyroads.com/dailyroads_assets/dailyroads_images/pin.png',
iconSize: [29, 39],
}),
draggable: false
}).addTo(map);
marker.on('dragend', function(event) {
var marker = event.target;
var result = marker.getLatLng();
video.get(0).currentTime = nearest_point(result.lat, result.lng).sec;
});
function set_marker(point) {
const lat = parseFloat(point[1]);
const long = parseFloat(point[0]);
marker.setLatLng(L.latLng(lat, long));
set_marker.now = point;
}
set_marker.now = point_locs[0];
// handle for marker location based on video time
function point_at_time(timeindex_sec) {
var it = point_locs[0];
var min_dt = Number.POSITIVE_INFINITY;
const index = Math.round(timeindex_sec);
return point_locs[index];
var e = point_locs.length
for (var i = 0; i < e; ++i) {
var dt = Math.abs(i - timeindex_sec);
if (dt < min_dt) {
it = point_locs[i];
min_dt = dt;
}
}
return it;
}