如何使用像素坐标在Leaflet中绘制折线? [英] How do I draw a polyline in Leaflet using pixel coordinates?
问题描述
我的地图已经设置好,标记已经到位,并且工作正常.我现在想在标记之间添加线条;因此我使用了Leaflet的代码示例,并添加了几个标记的坐标,但是该线未显示在地图上.
My map is set up and the markers are in place, and it's working perfectly. I now want to add lines between the markers; so I used the code example from Leaflet and added the coords from a couple markers, but the line isn't showing on the map.
var polylinePoints = [
[3474, 12427],
[2298, 11596],
];
var polyline = L.polyline(polylinePoints).addTo(map);
然后我尝试了...
var pointA = new L.LatLng(3474, 12427);
var pointB = new L.LatLng(2298, 11596);
var pointList = [pointA, pointB];
var firstpolyline = new L.Polyline(pointList, {
color: 'red',
weight: 3,
opacity: 0.5,
smoothFactor: 1
});
firstpolyline.addTo(map);
...但该行仍未显示.
...and the line still isn't showing.
问题可能出在我使用的是像素坐标,而不是实际的经纬度坐标吗?如果是这样,如何使用像素坐标在标记之间绘制线条?
Could the problem be that I'm using pixel coordinates and not actual lat and lng coords? If so, how do I draw lines between markers using pixel coordinates?
推荐答案
问题可能出在我使用的是像素坐标,而不是实际的经纬度坐标吗?如果是这样,如何使用像素坐标在标记之间绘制线条?
Could the problem be that I'm using pixel coordinates and not actual lat and lng coords? If so, how do I draw lines between markers using pixel coordinates?
当然.
尝试一下:
var pointA = map.layerPointToLatLng(L.point(3474, 12427));
var pointB = map.layerPointToLatLng(L.point(2298, 11596));
var pointList = [pointA, pointB];
var firstpolyline = new L.Polyline(pointList, {
color: 'red',
weight: 3,
opacity: 0.5,
smoothFactor: 1
});
firstpolyline.addTo(map);
接下来,您可能会遇到起源问题,请参见 map.getPixelOrigin()
You may run in to problems with origin next, though, see map.getPixelOrigin()
这篇关于如何使用像素坐标在Leaflet中绘制折线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!