From: Andy Allan Date: Sun, 14 Feb 2010 19:04:16 +0000 (+0000) Subject: Drag and Drop POIs. TODO: make a panel, load from mapfeatures. Bug: only shows when... X-Git-Tag: 0.5~534 X-Git-Url: https://git.openstreetmap.org/potlatch2.git/commitdiff_plain/acabebc063677b406b89c46fbc37034fd2ed3660 Drag and Drop POIs. TODO: make a panel, load from mapfeatures. Bug: only shows when map is moved/refreshed --- diff --git a/potlatch2.mxml b/potlatch2.mxml index 9357df09..6553c615 100755 --- a/potlatch2.mxml +++ b/potlatch2.mxml @@ -27,6 +27,9 @@ creationComplete="bgButton.popUp = new BackgroundSelector();"/> + + @@ -40,7 +43,7 @@ + top="0" left="0" width="100%" height="100%" dragEnter="dragEnterHandler(event);" dragDrop="dragDropHandler(event);"> @@ -71,6 +74,9 @@ import com.yahoo.maps.api.YahooMap; import com.yahoo.maps.api.YahooMapEvent; import com.yahoo.maps.api.core.location.LatLon; + import mx.events.DragEvent; + import mx.managers.DragManager; + import mx.core.DragSource; public var theMap:Map; public var yahooListener:Object = new Object(); @@ -189,6 +195,43 @@ private function onDataComplete(event:Event):void { dataWorking.visible = false; } + + private function dragPOI(event:MouseEvent, tags:Array):void { + // Get the drag initiator component from the event object. + var dragInitiator:Image = event.currentTarget as Image; + var dragSource:DragSource = new DragSource(); + dragSource.addData(tags, 'tags'); + + var dragProxy:Image = new Image(); + dragProxy.source = event.currentTarget.source; + + DragManager.doDrag(dragInitiator, dragSource, event, dragProxy); + } + + private function dragEnterHandler(event:DragEvent):void { + // Get the drop target component from the event object. + var dropTarget:Canvas=event.currentTarget as Canvas; + // Accept the drag only if the user is dragging poi with tags + if (event.dragSource.hasFormat('tags')) + { + DragManager.acceptDragDrop(dropTarget); + } + } + + private function dragDropHandler(event:DragEvent):void { + // Get the data identified by the color format from the drag source. + // Blame http://www.adobe.com/devnet/flex/quickstart/adding_drag_and_drop/#manual + // for whatever horrid abuse of "color format" this is doing + var tags:Array = event.dragSource.dataForFormat('tags') as Array; + var mapLoc:Point = Globals.vars.root.globalToLocal(new Point(event.stageX, event.stageY)); + var lat:Number = Globals.vars.root.coord2lat(mapLoc.y); + var lon:Number = Globals.vars.root.coord2lon(mapLoc.x); + var node:Node = Connection.getConnectionInstance().createNode({}, lat, lon); + for each( var tag:Array in tags ) { + node.setTag(tag[0],tag[1]); + } + } + ]]>