qq_28139347
qq_28139347
采纳率0%
2015-06-11 01:55 阅读 1.8k

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()));
}
添加的标注和鼠标获取的坐标偏移太大了, 缩放地图偏移更大怎么回事!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • qq_38233149 qq_38233149 2018-10-12 07:39

    var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);

    点赞 评论 复制链接分享

相关推荐