<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx ="http://www.adobe.com/2006/mxml"
xmlns ="com.esri.solutions.flexviewer.*"
layout ="absolute"
applicationComplete ="registerGlobalKeyHandler()"
preloader="com.sarsea.MyProgressBar"
styleName ="main"
backgroundColor ="#9EBCD8"
initialize="ini()"
xmlns:GIS ="com.esri.solutions.flexviewer.info.GIS.*" xmlns:zj="zj.*">
<zjermission id="p"/>
<mx:Script>
<![CDATA[
import CustomizeControls.FunctionUtils;
import com.sarsea.MyProgressBar;
import CustomizeControls.SystemConfig;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.Map;
import mx.rpc.AsyncResponder;
import com.esri.ags.tasks.FeatureSet;
import com.esri.ags.tasks.QueryTask;
import com.esri.ags.tasks.Query;
import mx.core.IFlexDisplayObject;
import mx.effects.AnimateProperty;
import mx.controls.Alert;
import flash.net.registerClassAlias;
import mx.messaging.messages.RemotingMessage;
import com.esri.solutions.flexviewer.AppEvent;
import mx.managers.IDragManager;
import mx.managers.HistoryManager;
[Bindable]
public var loginUser:Object = null;
private var iDragManager:IDragManager;
private var hist:HistoryManager;
private var tween:AnimateProperty = new AnimateProperty();
private var map:Map=new Map;
private function registerGlobalKeyHandler() :void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
}
private function ini():void{
FunctionUtils.iniAlert();
SystemConfig.iniPath();
registerClassAlias("flex.messaging.messages.RemotingMessage", RemotingMessage);
SiteContainer.addEventListener(AppEvent.MAP_LOADED, initMap);
p.CheckPermission();
}
private function initMap(event:AppEvent):void
{
// SiteContainer.addEventListener(AppEvent.CONFIG_LOADED
tool.toolMap=event.data as Map;
map=event.data as Map;
map.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
}
private function handleKeyDown(event:KeyboardEvent) :void
{
if ((event.shiftKey) && (event.keyCode == 27))
{
SiteContainer.dispatchEvent(new AppEvent(AppEvent.SET_MAP_NAVIGATION, false, false, null));
}
}
private function fullScreen(event:MouseEvent):void
{
stage.displayState = (stage.displayState ==
StageDisplayState.NORMAL?StageDisplayState.FULL_SCREEN:StageDisplayState.NORMAL);
}
//显示xy坐标
private function mouseMoveHandler(event:MouseEvent):void
{
try{
const mapPoint:MapPoint = map.toMapFromStage(event.stageX, event.stageY);
xyText.text = "X: "+ mapPoint.x.toFixed(4) + ", Y: " + mapPoint.y.toFixed(4);
}catch(e:Error){}
}
]]>
</mx:Script>
<SiteContainer id="container">
<configManager> <ConfigManager/> </configManager>
<uiManager> <UIManager/> </uiManager>
<yujingTip>
<YujingTip/>
</yujingTip>
<controller> <Controller x="40" y="20"/> </controller>
<dataManager> <DataManager/> </dataManager>
<widgetManager> <WidgetManagerDocked/> </widgetManager>
<mapManager> <MapManager/> </mapManager>
</SiteContainer>
<mxabel id="xyText" bottom="20" right="30"/>
</mx:Application>
最近做个有关Flex的绘画程序,由于刚刚接触其坐标系统,也没看过资料,结果弄得晕乎乎的。
查阅了一些资料理解一下.
flex提供了3种不同的坐标系
全局的就是(stage级别的)
本地坐标系(组件级别的)
内容坐标系(相对于本地坐标系说的)
全局
这个坐标系的原点在整个flash舞台的左上角,MouseEvent实例的stageX,stageY就是这个坐标系中的值,
本地
坐标原点是相对的组件的左上角,MouseEvent中的localX,localY就是相对这个坐标系说的,
------------------------------------------------------------------------------------------------
自定义组件的坐标: 例如自定义一个矩形组件,该组件有一个中心点center
中心点center的坐标(x,y)是相对于矩形组件的.所以不能和坐标系中的全局坐标搞混了。
全局的就是(stage级别的)
本地坐标系(组件级别的)
内容坐标系(相对于本地坐标系说的)
这些坐标系的点是可以转换的,并且有相应的方法,看来adobe想得挺周到。我们一个一个的说一下
全局
这个坐标系的原点在整个flash舞台的左上角,MouseEvent实例的stageX ,stageY就是这个坐标系中的值,
本地
坐标原点是相对的组件的左上角,MouseEvent中的localX,localY就是相对这个坐标系说的,
内容
这个东西比较抽象了UIComponent类实例的contentMouseX 和 contentMouseY 就是了,这个主要针对有滚动条的组件说的,有滚动条了,内容肯定不少,内容所占的区域的坐标就是这个坐标系了。
下面有个官方的图说明了三个坐标系的关系及位置:
坐标转换还有现成的方法
contentMouseX |
返回mouse的内容坐标x值 |
contentMouseY |
返回mouse的内容坐标Y值 |
contentToGlobal |
将内容坐标转换成全局坐标 |
contentToLocal |
将内容坐标转换成内容坐标 |
globalToContent |
将全局的转成内容坐标 |
globalToLocal |
全局的转成本地的 |
localToContent |
本地到内容坐标 |
localToGlobal |
本地到全局坐标 |
下面是一个小例子
<?xml version="1.0"?>
<!-- containers/intro/MousePosition.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
// Handle the mouseDown event generated
// by clicking in the application.
private function handleMouseDown(event:MouseEvent):void {
// Convert the mouse position to global coordinates.
// The localX and localY properties of the mouse event contain
// the coordinates at which the event occurred relative to the
// event target, typically one of the
// colored internal Canvas controls.
// A production version of this example could use the stageX
// and stageY properties, which use the global coordinates,
// and avoid this step.
// This example uses the localX and localY properties only to
// illustrate conversion between different frames of reference.
var pt:Point = new Point(event.localX, event.localY);
pt = event.target.localToGlobal(pt);
// Convert the global coordinates to the content coordinates