Leaflet 为什么不显示此传单多段线?

Leaflet 为什么不显示此传单多段线?,leaflet,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 ©

我是传单的新手。尝试在传单地图中绘制多段线。我可以看到地图,但看不到多段线,是否有明显的错误?以下是我尝试过的

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);
var-map=newl.map('map');
//创建具有正确属性的平铺层
var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib='Map data©contributors';
var osm=new L.TileLayer(osmUrl,{minZoom:8,maxZoom:20,attribution:osmAttrib});
赛特维尤地图(新L.LatLng(36.037794380614635,-78.96096701410059),15);
map.addLayer(osm);
常数坐标=[
[
-78.936167,
36.0203309
],
[
-78.9363688,
36.0203325
],
[
-78.9364922,
36.0203341
],
[
-78.9366325,
36.0203357
]
];
var多段线选项={
颜色:'黑色',
体重:6,
不透明度:0.9
};
var polyline=新的L.多段线(坐标,多段线选项).addTo(地图);
我的代码在这里:
您的代码运行正常;您只需在
setView
函数或多段线坐标中交换lat/long,具体取决于您尝试执行的操作。交换坐标会使线条更靠近地图的初始位置:

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

这可能就是你要找的。你必须将地图向东南移动一点才能找到你的路线。:)

您的代码运行良好;您只需在
setView
函数或多段线坐标中交换lat/long,具体取决于您尝试执行的操作。交换坐标会使线条更靠近地图的初始位置:

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

这可能就是你要找的。你必须将地图向东南移动一点才能找到你的路线。:)

谢谢!这是有效的,有时这是最愚蠢的事情,让你在圈子里跑来跑去。
map.fitBounds(polyline.getBounds())可能有助于根据多段线的尺寸重新居中。谢谢!这是有效的,有时这是最愚蠢的事情,让你在圈子里跑来跑去。
map.fitBounds(polyline.getBounds())可能有助于基于多段线的尺寸重新居中。