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

发布于 2024-10-20 03:11:09 字数 825 浏览 7 评论 0原文

我一直在研究一种让用户无需拖动即可移动标记的方法。基本上,用户单击标记并打开信息窗口气泡。气泡中是一个指向 javascript 函数的链接,该函数在地图上设置单击事件。当用户单击地图上的某个位置时,应该将标记移动到单击的点。

在我的地图中,我有 18 个缩放级别。在缩放级别 15 下,此过程完美运行。如果我在单击一次后放大,标记仍然会准确地移动到我单击的位置。但是,如果我刷新并以缩放级别 16 重新开始并尝试单击某处,则标记会移动到更高且更靠左的位置。在更高的缩放级别重复此过程,标记会在地图上进一步向上和向左移动(距离)。

在低于 15 的缩放级别执行上述操作也可以正常工作。

以下是代码片段:

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);
});

我已通过控制台注销了 clientX 和 clientY 单击,并且它们确实从浏览器的左边缘和上边缘注册了正确的 x/y 坐标。但 OL 似乎在缩放级别高于 15 时错误计算了 moveTo。

有什么想法吗?

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. 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. At zoom level 15, this process works perfectly. 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. 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.

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. But it seems that OL is miscalculating the moveTo at the zoom levels above 15.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜夜流光相皎洁 2024-10-27 03:11:09

等待错误修正时的一个小解决方法

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);
});

干杯,
J。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文