2 qq 28139347 qq_28139347 于 2015.06.11 09:55 提问

Openayers中鼠标点击获取经纬度然后添加标注 和鼠标点击位置错位太大

我是这样做的

//鼠标点击地图获取 经纬度

mapGraph.events.register('click', mapGraph, function (e) {
var pixel = new OpenLayers.Pixel(e.xy.x,e.xy.y);
var lonlat = mapGraph.getLonLatFromPixel(pixel);
lonlat.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326")); //由900913坐标系转为4326
// alert(lonlat.lon+", "+lonlat.lat);
createmarker(lonlat.lon,lonlat.lat);
});
//创建图标
function createmarker(lon,lat){
var size=new OpenLayers.Size(20,20);
var offset = new OpenLayers.Pixel(-(size.w/5), -(size.h/5));
var iconImage = 'resources/images/red.png';
var icon = new OpenLayers.Icon(iconImage, size, offset);
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(lon,lat).transform_lc(),icon.clone()));
}
添加的标注和鼠标获取的坐标偏移太大了, 缩放地图偏移更大怎么回事!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!