Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
Leaflet map: Interrupt route line drawn using an array of coordinate, if the array values are 0

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:

enter image description here

and the route should look like this:

enter image description here

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;
            }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!