简体   繁体   中英

L.multiPolyline does not show anything on map (leaflet)

This is my code to add a polyline to a map. The map works fine and I've used GeoJSON objects to display routes on the map.

var polyLine = L.multiPolyline(window.routeArray,{color: 'blue'});          
polyLine.addTo(map);

window.routeArray is an array of latLngs This is the output if I do an console.log(" " + window.array); (I'm using node.js with this.)

LatLng(49.24905, -123.11531),LatLng(49.24854, -123.07618),LatLng(49.24022, -123.07642),LatLng(49.24034, -123.09034),LatLng(49.23287, -123.09054),LatLng(49.23319, -123.10146),LatLng(49.24045, -123.10138)

The map doesn't show anything and I can't figure out why.

Any help would be appreciated.

Two suggestions, 1) what you've described is a polyline, not a multipolyline. 2) the points must be added as a javascript array as an array of arrays, for example

var line_points = [
    [38.893596444352134, -77.0381498336792],
    [38.89337933372204, -77.03792452812195],
    [38.89316222242831, -77.03761339187622],
    [38.89302861514842, -77.03731298446655],
    [38.892920059048464, -77.03691601753235]
];

var line = L.polyline(line_points).addTo(map);

This example may help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM