传单折线不会在拖动/缩放上移动

时间:2015-07-02 05:45:32

标签: dictionary leaflet polyline

我正在使用带有自定义CRS.Simple投影的传单。如果我在页面上绘制一条折线,那么它或多或少被绘制好了(虽然在firefox中比在chrome中更准确)但是如果我拖动地图,折线仍然在浏览器窗口的同一位置,那么就会出现转移尊重背景地图。

实施例: 初始加载 initial load

After drag the map, the map moves but the polyline remains in the same place

拖动地图后,地图会移动,但折线仍保留在同一个地方

要添加折线,我将坐标转换为CRS.Simple投影。我不认为这里存在问题,因为每个其他地图标记或文本都正确显示

.....
//initialize leaflet map
map = L.map('map', {
    maxZoom: mapMaxZoom,
    minZoom: mapMinZoom,
    zoomControl: false,
    crs: L.CRS.Simple  //simple coordinates system
}).setView([0, 0], mapMaxZoom);

//set the bounds of the map to the current dimension
var mapBounds = new L.LatLngBounds(
    map.unproject([0, mapHeight], mapMaxZoom),
    map.unproject([mapWidth, 0], mapMaxZoom)
 );

//load the tiles       
map.fitBounds(mapBounds);
L.tileLayer(mapData.info.tiles+'/{z}/{x}/{y}.png', {
    minZoom: mapMinZoom,
    maxZoom: mapMaxZoom,
    bounds: mapBounds,
    attribution: '',
    noWrap: true,
    continuousWorld: true    
}).addTo(map);
.....
var pointList = [getMapCoordinates(1750,1750),
                getMapCoordinates(1520,1764),
                getMapCoordinates(1300,1560),
                getMapCoordinates(1132,1258),
                 getMapCoordinates(1132,1060),
                 getMapCoordinates(926,960)];

polyline = new L.Polyline(pointList, {
    color: 'red',
    weight: 3,
    opacity: 0.5,
    smoothFactor: 1
});
polyline.addTo(map);
....

function getMapCoordinates(px,py)
{
    //as we use simple system, transform the point (based on pixel) on map coordinates that leaflet understand
    return map.unproject([px, py], map.getMaxZoom());
}

知道我做错了什么,或者它是一个错误?任何解决方法都将不胜感激

1 个答案:

答案 0 :(得分:0)

好吧,似乎问题出现在稳定版本(0.7.3)使用dev版本(1.0-dev)工作正常甚至可以解决不同浏览器绘图的问题