1

I am struggling with the AntPath Plugin ( link to GitHub ) for Leaflet and the documentation is limited and difficult to read. This setup works well(se code-snippet in the end), but instead I want to add multipolylines. To do that I must change it to:L.MultiPolyline.MultiAntPath(path) and modify JSON-file to my array of polylines.

The valid and working JSON-file for current polyline looks like this:

[[-3.748494, -38.460304],[-3.74845, -38.4603],[-3.7482748, -38.46086]]

But I want something like this(Example for 2 paths):

[[55.778659,12.151137  ], [55.779807,12.158085  ], [55.773663,12.163626  ], [55.769615,12.16311  ]], [[55.766945,12.158487  ], [55.767806,12.154152  ], [55.769787,12.150391  ], [55.772687,12.147922  ]]

How does the setup look like when adding multiple polylines with lat/lon in my new JSON-file (see 2 paths-example)?

    $http.get('newsingle.json').then(function (res) {
                path = res.data;

                L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
                    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                }).addTo(map);

                layer = new L.Polyline.AntPath(path);
                map.addLayer(layer);
                map.fitBounds(layer.getBounds());
            });

            scope.$watch('options', function (opts) {
                if (layer !== null) {
                    map.removeLayer(layer);
                    layer = new L.Polyline.AntPath(path, opts);
                    map.addLayer(layer);
                }
1

Found the answer. This is an example of 3 paths in JSON:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.