首页 文章

传单折线不起作用

提问于
浏览
1

我似乎工作了 . 我错过了什么或......?附:坐标对 not 包含相同的值,因此它应该产生线...

//this adds markers to the map, which works
var d = {};
d.coordinates = [[lat,lng],[lat,lng]]

var latLngs = d.coordinates.map(function (c) {
    var marker = L.marker(c).addTo(map);
    return {
        lat: c[0],
        lng: c[1]
    };
});

//This 'should' add polylines but doesn't ... 
var polyline = L.polyline(d.coordinates, { color: 'red', weight: 12 }).addTo(map);

我尝试了上面代码的各种变体,随实例化/工厂方法而变化,如: new L.polyline() vs L.polyline() 并尝试大写和小写 P olyline . 我尝试传递 [double, double][L.LatLng, L.LatLng] 甚至 [{lat:lat,lng:lng}] 的数组,但似乎没有任何作用...我真的必须忽略一个简单的事情......

我正在使用Leaflet 0.7 .

Edit:

如gsFiddle所显示的ghybs它应该工作 . 我将我的代码更新为以下内容:

var firstpolyline = L.polyline(d.coordinates, {
    color: 'red',
    weight: 12
}).addTo(map);

我还在jsFiddle和我的解决方案中添加了相同的日志记录语句 .

console.log(firstpolyline); // jsFiddle console.log的polyline(map);的console.log(d.coordinates);

那些产生这个(左边是自定义解决方案,它是 not 显示一条线,右边是jsFiddle,显示一条线) . 手动将我的解决方案的不同坐标对复制粘贴到jsFiddle只是起作用...:

我真的迷失在这里:(

enter image description here

1 回答

  • 0

    没有理由在工厂 L.polyline() 之后添加额外的 .polyline .

    var polyline2 = L.polyline(d.coordinates, {color: 'red', weight: 12}).addTo(map);
    

    演示:http://jsfiddle.net/ve2huzxw/48/

    附注:您应该在 d.coordinates == [[lat,lng],[lat,lng]] 中使用单个等号( = )进行分配

相关问题