var newGraphic:Graphic = ObjectUtil.clone(exisitngGraphic)
package ee.alphagis.utils { import com.esri.ags.Graphic; import com.esri.ags.geometry.Geometry; import com.esri.ags.symbols.Symbol; import mx.core.IFactory; public class MyGraphicUtils { public static function cloneGraphic(graphic:Graphic):Graphic { if (!graphic) { return null; } var geometry:Geometry = graphic.geometry; var symbol:Symbol = graphic.symbol; var attributes:Object = graphic.attributes; var autoMoveToTop:Boolean = graphic.autoMoveToTop; var checkForMouseListeners:Boolean = graphic.checkForMouseListeners; var infoWindowRenderer:IFactory = graphic.infoWindowRenderer; var result:Graphic = new Graphic(geometry, symbol, attributes); result.autoMoveToTop = autoMoveToTop; result.checkForMouseListeners = checkForMouseListeners; result.infoWindowRenderer = infoWindowRenderer; return result; } } }
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"> <!-- Adobe FLEX SDK ver. 4.5.1 --> <!-- ArcGIS API for FLEX ver. 2.5 --> <s:layout> <s:VerticalLayout paddingBottom="20" paddingLeft="20" paddingRight="20" paddingTop="20" /> </s:layout> <fx:Script> <![CDATA[ import com.esri.ags.Graphic; import com.esri.ags.SpatialReference; import com.esri.ags.geometry.MapPoint; import com.esri.ags.symbols.SimpleMarkerSymbol; import ee.alphagis.utils.MyGraphicUtils; import mx.controls.Alert; import mx.utils.StringUtil; private var _pattern:String = "base={0}, geometry={1}, name={2}, stamp={3}\n\nclone={4}, geometry={5}, name={6}, stamp={7}"; protected function button1_clickHandler(event:MouseEvent):void { var attr:Object = new Object(); attr.name = "qwerty"; attr.date = new Date(); var geometry:MapPoint = new MapPoint(654, 456, new SpatialReference(4326)); var symbol:SimpleMarkerSymbol = new SimpleMarkerSymbol("circle", 16, 0x00ff56); var baseGraphic:Graphic = new Graphic(geometry, symbol, attr); var clonedGraphic:Graphic = MyGraphicUtils.cloneGraphic(baseGraphic); var message:String = StringUtil.substitute(_pattern, baseGraphic.toString(), baseGraphic.geometry.type, baseGraphic.attributes["name"], baseGraphic.attributes["date"], clonedGraphic.toString(), clonedGraphic.geometry.type, clonedGraphic.attributes["name"], clonedGraphic.attributes["date"]); Alert.show(message); } ]]> </fx:Script> <s:Button label="clone" click="button1_clickHandler(event)"/> </s:Application>
cspring,http://forums.arcgis.com/threads/31993-Can-t-add-the-same-Graphic-twice-to-a-GraphicsLayer?p=107453#post107453Question to you: Can you tell, what is the base idea? Why do you need in 2 absolutely equals graphics?
var newGraphic:Graphic = deepClone(existingGraphic); newGraphic.attributes = existingGraphic.attributes; newGraphic.geometry = existingGraphic.geometry;
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.