openlayers经纬度转屏幕坐标

centerLon ,centerLat  为获取到的经纬度;
dx ,dy为该点相对于地图左上角的像素差
tmap.div.offsets[0],tmap.div.offsets[1] 为地图左上角的屏幕坐标。
PosX, PosY 为该经纬度的屏幕坐标。
IE,360,firefox,google浏览器测试通过。
 
var feature = e.feature;
                var tmap = feature.layer.map;
                //通过div实现,未完成,IE和firefox都不对
                var bounds = feature.geometry.bounds;
                var centerLon = (bounds.left + bounds.right) / 2.0;
                var centerLat = (bounds.bottom + bounds.top) / 2.0;
                var resolution = tmap.getResolution();
                var extent = tmap.getExtent();
                var size = tmap.size;
                var dx =parseInt( size.w * (centerLon - extent.left) / (extent.right - extent.left));
                var dy = parseInt(size.h * (centerLat - extent.top) / (extent.bottom - extent.top));
                
                
                var PosX = tmap.div.offsets[0] + dx;
                var PosY = tmap.div.offsets[1] + dy;
                /*
                var isIE = (document.all) ? true : false;
                var PosX = isIE ? event.x : e.pageX;
                var PosY = isIE ? event.y : e.pageY;*/
 
                //添加一个热区div
                var hotspotdiv = document.getElementById(_hotspotdivid);
                hotspotdiv.innerHTML = feature.attributes["Title"];
                hotspotdiv.style.left = PosX + "px";
                hotspotdiv.style.top = PosY + "px";
                hotspotdiv.style.position = "absolute";
                hotspotdiv.style.visibility = "visible";

 

 
posted @ 2022-07-14 15:10  devgis  阅读(813)  评论(0编辑  收藏  举报