ArcGIS Flex API 拖拽Graphic

用了Google Street View的话,很熟悉那个人形,可以拖拽的,那么在 Flex API中怎么实现拖动某个Graphic呢?

如果用过ArcGIS Flex API中Drag Polygon查询例子的同行会知道,用这个例子修改一下就可以实现,但是,细心的同行可能会注意用Drage Polygon时,拖动Polygon会很卡,特别是鼠标移动太快时就会很卡。

不过,这个问题被解决了。


理解一下这段代码,你就会有收获。现在拖动Graphic时不会再卡,而且效率很高。

private function addListeners():void
            {
                panoGraphic.addEventListener(MouseEvent.MOUSE_UP,panoGraphicMouseUpEventHandler);
                myMap.addEventListener(MouseEvent.MOUSE_UP,mapMouseUpEventHandler);
                panoGraphic.addEventListener(MouseEvent.MOUSE_DOWN, panoGraphicMouseDownEventHandler);                                                            
            }
           
            public function panoGraphicMouseDownEventHandler(event:MouseEvent):void
            {  
                try
                {
                    myMap.panEnabled = false;             
                    panoGraphic.addEventListener(MouseEvent.MOUSE_MOVE, dragShapeEventHandler);
                    myMap.addEventListener(MouseEvent.MOUSE_MOVE, dragShapeEventHandler);

                }
                catch(err:Error)
                {
                }
            }

            //handle a mouseup event on the map
            public function panoGraphicMouseUpEventHandler(event:MouseEvent):void
            {
                try
                {  
                    myMap.panEnabled = true;
                    panoGraphic.symbol = pano;  
                    panoGraphic.removeEventListener(MouseEvent.MOUSE_MOVE, dragShapeEventHandler);
                    myMap.removeEventListener(MouseEvent.MOUSE_MOVE, dragShapeEventHandler);
                }

                catch(err:Error)
                {
                }                              
            }

            //as the polygon gets dragged, remove old Graphic children and create new Graphic
            public function dragShapeEventHandler(event:MouseEvent):void
            {  
                myMap.panEnabled = false;
                var arr1:Array = new Array();                   //a temporary array
                var mapPointFromStage:MapPoint = myMap.toMapFromStage(event.stageX,event.stageY);                            
            
                panoGraphic.geometry = mapPointFromStage;    
                panoGraphic.symbol = panoDrag;          
            }
           

            public function mapMouseOverEventHandler(event:MouseEvent):void
            {  
                try
                {
                    if(event.target.geometry.type == "esriGeometryPoint")
                    {
                        myMap.panEnabled = false;
                    }  
                }
                catch(err:Error)
                {
                }          
            }

            public function mapMouseUpEventHandler(event:MouseEvent):void
            {
                try
                {  
                    panoGraphic.symbol = pano;  
                    panoGraphic.removeEventListener(MouseEvent.MOUSE_MOVE, dragShapeEventHandler);
                }

                catch(err:Error)
                {
                }          
            }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值