Openlayers engine markerOnly accurate at a certain zoom level

I am working on how users can move the marker without dragging. In principle, the user clicks on the marker and opens the bubble of the information window. In the bubble, this is a link to a javascript function that sets the event of a click on the map. When the user clicks somewhere on the map, he must move the marker to the point pressed.

On my map I have 18 zoom levels. With a zoom level of 15, this process works just fine. If I increase the time after clicking the click once, the marker still moves to where I click. But then, if I update and start at zoom level 16 and try to click somewhere, the marker moves to a position higher and more to the left. Repeating this process at higher zoom levels, the marker moves even further up and to the left on the map (at a distance).

Doing the above with zoom levels below 15 works very well.

Here is the code snippet:

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

My console came out of clientX and clientY clicks, and they register the correct x / y coordinates from the left and top edges of the browser. But, it seems, OL erroneously calculates moveTo at zoom levels above 15.

Any ideas?

+3
1

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.

+1

Source: https://habr.com/ru/post/1795786/


All Articles