Flex 地理坐标与屏幕坐标 转换


Flex端:
   protected function application1_preinitializeHandler(event:FlexEvent):void
   {
    ExternalInterface.addCallback("openRightClick", openRightClick);//注册函数,方便被JS调用
   }

   private var point:Point=new Point();
   protected function map_mouseMoveHandler(event:MouseEvent):void
   {
    point.x=event.stageX;//屏幕坐标(圆点在屏幕左上角)
    point.y=event.stageY-myActive.height; //myActive为map上面的控件的高度
   }

   public function openRightClick():void
   {
    arrAs[currentImage-1]._curDir = 8;//当前方向,8为无方向;所以定位时要设置为8表示无方向 ;如果不设置定位不到影像
    //map.width,map控件的宽度;map.exetent,控件四个角的地理坐标;
    //map原点在左下角,从左到右X坐标变大,从下到上Y坐标变大;screen则原点在左上角,从左到右X坐标变大,从上到下Y坐标变大
    coorX = (map.extent.xmax-map.extent.xmin)*point.x/map.width+map.extent.xmin;//屏幕横向为x轴。从左到右坐标变大
    coorY = map.extent.ymax-(map.extent.ymax-map.extent.ymin)*point.y/map.height;//屏幕纵向为y轴。从下到上坐标变大
    forArrayURL();//循环执行查询,并赋于个img图片地址
   }

JS端:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title>无标题页</title> 
<script language="javascript" type="text/javascript"> 
var active; 

//初始化影像插件 
window.onload = function() 

active = document.getElementById("loadingSWF"); 


document.oncontextmenu = function()// js文档中定义了oncontextmenu右击事件 

event.returnValue = false; //禁止弹出右键菜单
active.openRightClick(); 


//定位到坐标对应的影像 
function findImageByXY() 

var coorX=document.getElementById("txt_X").value; 
var coorY=document.getElementById("txt_Y").value; 
active.setXY(coorX,coorY); 

</script> 

</head> 
<body style="background-color: #aaa"> 
<div> 
<input id="btnGet" type="button" value="定位到对应坐标的影像" οnclick="findImageByXY()" /> 
<input id="txt_X" type="text" value="503131.268292774" /> 
<input id="txt_Y" type="text" value="306360.787042478" /> 
</div> 
<div> 
<embed id='loadingSWF' src='trueMap.swf' style='z-index:500; position:absolute;' width='100%' height='100%' bgcolor='#FFFFFF' wmode='transparent' quality='high' allowfullscreen="true"> //如此设置wmode
</embed> 
</div> 
</body> 
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值