I have a problem with the conversion from pixel to lon/lat. It's not always correct. The map is a simple XYZ map. The items on it are dragable. But after I dragged an item it gives me a wrong lon/lat value. Most of the time it's 50 pixels to low.
I've created a grid on the map with lines every 100 pixels. When I move an item on the 3th line sometimes I get 300, other times 250.
Is this a bug in OpenLayers or is there something I did wrong?
groundplan = new OpenLayers.Layer.XYZ(
'GroundPlan',
'@Url.Content("~/Centrals/" + ViewBag.Id)/Maps/' + planId + '/${z}/${x}/${y}.jpg',
{
attribution: "© Limotec",
transitionEffect: 'resize',
maxExtent: new OpenLayers.Bounds(0, 0, 4096, 4096),
maxResolution: 4096 / 256,
numZoomLevels: 5
}
);
map.addLayer(groundplan);
markers = new OpenLayers.Layer.Vector("Markers",
{
renderOptions: { yOrdering: true },
renderers: renderer
}
);
map.addLayer(markers);
dragFeature = new OpenLayers.Control.DragFeature(markers);
dragFeature.onComplete = function (feature, pixel) {
var id = feature.geometry.id;
id = id.replace('Det_', '');
//var lonLat = map.getLonLatFromPixel(pixel);
var lonLat = groundplan.getLonLatFromViewPortPx(pixel);
console.info("Moved detector " + id + " naar " + lonLat.lon + " - " + lonLat.lat + " (x: " + pixel.x + " y: " + pixel.y + ")");
$.post('@Url.Action( "MoveDet", "Api" )',
{ "centralId": @ViewBag.Id, "id": id, "lat": lonLat.lon, "lng": lonLat.lat }
);
}
dragFeature.handlers['drag'].stopDown = false;
dragFeature.handlers['drag'].stopUp = false;
dragFeature.handlers['drag'].stopClick = false;
dragFeature.handlers['feature'].stopDown = false;
dragFeature.handlers['feature'].stopUp = false;
dragFeature.handlers['feature'].stopClick = false;
map.addControl(dragFeature);
dragFeature.activate();