简体   繁体   English

openlayers marker moveTo仅在特定缩放级别准确

[英]openlayers marker moveTo only accurate at a specific zoom level

I have been working on a way for users to move a marker without dragging. 我一直在努力让用户在不拖动的情况下移动标记。 Basically, the user clicks on the marker and it opens the info window bubble. 基本上,用户点击标记并打开信息窗口气泡。 In the bubble is a link to a javascript function that sets a click event on the map. 泡泡是指向地图上设置点击事件的javascript函数的链接。 When the user clicks somewhere on the map it is supposed to move the marker to the point clicked. 当用户点击地图上的某个位置时,应该将标记移动到点击的点。

In my map, I have 18 zoom levels. 在我的地图中,我有18个缩放级别。 At zoom level 15, this process works perfectly. 在缩放级别15,此过程完美地运行。 If I zoom in AFTER clicking once, the marker still moves to exactly where I click. 如果我在单击一次后放大,标记仍会移动到我单击的位置。 But then, if I refresh and start over at zoom level 16 and try to click somewhere, the marker is moved to a position higher and more to the left. 但是,如果我刷新并在缩放级别16重新开始并尝试单击某处,标记将移动到更高,更左侧的位置。 Repeating this process at higher zoom levels, the marker is moved even further up and to the left on the map (in distance). 在更高的缩放级别重复此过程,标记会在地图上向上和向左移动(距离)。

Doing the above at zoom levels lower than 15 work just fine as well. 在缩放级别低于15的情况下执行上述操作也可以正常工作。

Here's a snippet of the code: 这是代码的片段:

lmLayer = new OpenLayers.Layer.Markers("Landmark Creation");
map.addLayer(lmLayer);
var marker = landmark['landmark_1234'];// this just pulls the marker out of storage
map.events.register("click", lmLayer, function(evt){
    var pixel = new OpenLayers.Pixel(evt.clientX,evt.clientY);
    marker.moveTo(pixel);
    OpenLayers.Event.stop(evt);
});

I have console logged out the clientX and clientY clicks and they do register the right x/y coordinates from left and top edges of the browser. 我有控制台注销了clientX和clientY点击,他们确实从浏览器的左上边缘注册了正确的x / y坐标。 But it seems that OL is miscalculating the moveTo at the zoom levels above 15. 但似乎OL在15以上的缩放级别上错误地计算了move。

Any ideas? 有任何想法吗?

a little workaround while waiting to bug correction 在等待错误纠正时稍微解决一下

lmLayer = new OpenLayers.Layer.Markers("Landmark Creation");
map.addLayer(lmLayer);
var marker = landmark['landmark_1234'];

map.events.register("click", lmLayer, function(evt){
    var pixel = new OpenLayers.Pixel(evt.clientX,evt.clientY);
    marker.lonlat = pixel;
    marker.moveTo(pixel);
    // workaround
    marker.draw();
    lmLayer.redraw();
    OpenLayers.Event.stop(evt);
});

Cheers, J. 干杯,J。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM