Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have some custom polyline on OSM with this code(我在OSM上使用此代码有一些自定义折线)

var polyline1 = [
        [44.772142, 17.208980],
        [44.774753, 17.207644],
        [44.773964, 17.199587],
        [44.770823, 17.199207],
        [44.771399, 17.195699],
    ];

    for (var i = 0; i < polyline1.length; i++) {
                var polyline = L.polyline(polyline1, {
                    color: 'red'
                }).addTo(map);;
            }

I need markers with popup on all this coordinates, this code cannot work with other:(我需要在所有这些坐标上带有弹出标记,此代码无法与其他代码一起使用:)

for (var i = 0; i < polyline1.length; i++) {
                var marker = L.marker([polyline1[i][1],polyline1[i][2]])
                .bindPopup(polyline1[i][0])
                .addTo(map);
            }

Is there any solution for this?(有什么解决办法吗?)

  ask by goran_bl translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
507 views
Welcome To Ask or Share your Answers For Others

1 Answer

It's much simpler than you're making it.(它比您制作的要简单得多。)

// Define the points

var polyline1 = [
        [44.772142, 17.208980],
        [44.774753, 17.207644],
        [44.773964, 17.199587],
        [44.770823, 17.199207],
        [44.771399, 17.195699],
    ];

// Add a marker at each point

polyline1.forEach(function(LatLng) {
    L.marker(LatLng).addTo(map);
});

// Add a polyline

L.polyline(polyline1, { color: 'red' }).addTo(map);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...