为什么这个传单折线没有显示?

时间:2018-06-13 19:38:43

标签: leaflet

我是传单的新手。尝试在传单地图中绘制折线。我可以看到地图而不是折线,有什么明显的做错了吗?以下是我的尝试。

var map = new L.map('map');
         // create the tile layer with correct attribution
        var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
        var osmAttrib='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors';
        var osm = new L.TileLayer(osmUrl, {minZoom: 8, maxZoom: 20, attribution: osmAttrib}); 

        map.setView( new L.LatLng(36.037794380614635, -78.96096701410059),15);
        map.addLayer(osm);

        const  coords =  [
            [
                -78.936167,
                36.0203309
            ],
            [
                -78.9363688,
                36.0203325
            ],
            [
                -78.9364922,
                36.0203341
            ],
            [
                -78.9366325,
                36.0203357
            ]
        ];

        var polylineOptions = {
               color: 'black',
                weight: 6,
               opacity: 0.9
             };

         var polyline = new L.polyline(coords, polylineOptions).addTo(map);

我的代码在这里:   enter link description here

1 个答案:

答案 0 :(得分:2)

您的代码工作正常;你只需要用你的setView函数或你的折线坐标替换lat / long,这取决于你想要做什么。交换坐标使线条更接近地图的初始位置:

    const  coords =  [
        [
            36.0203309,
            -78.936167
        ],
        [
            36.0203325,
            -78.9363688
        ],
        [
            36.0203341,
            -78.9364922
        ],
        [
            36.0203357,
            -78.9366325
        ]
    ];

这可能就是你要找的东西。你必须将地图稍微向东南移动以找到你的线。 :)