Select to view content in your preferred language

How to clear a graphic result on map in FlexViewer

650
1
06-08-2011 08:24 AM
francescodi_vito
Deactivated User
hi guys,
i developed a model with arcgis 10 and i pulished it with arcgis server.
Now in Flex Viewer i created a new widget and i wrote a flex script for call this model whit a graphic result on a map. When i run the model i receive a graphic result that i wrote in my script, but the clear function don't work.
i a custom web app. i create a samp'èle button with
click="graphicsLayer.clear()"
but this method in Flex Viewer don't works. Why?
could someone tell me how to rewrite this method to get it to work in FlexViewer?
Thanks
any help is good
Tags (2)
0 Kudos
1 Reply
IvanBespalov
Frequent Contributor
May be this code helps:
<?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"
                    xmlns:esri="http://www.esri.com/2008/ags">
 
    <s:layout>
        <s:VerticalLayout paddingBottom="6"/>
    </s:layout>
 
    <fx:Script>
        <![CDATA[
            import com.esri.ags.Graphic;
            import com.esri.ags.events.MapMouseEvent;
            import com.esri.ags.geometry.Geometry;
            import com.esri.ags.geometry.MapPoint;
   
            import mx.collections.ArrayCollection;
            import mx.utils.StringUtil;
   
            private var lastAddedGraphic:Graphic = null;
   
            /**
             * Listen map mouse down handler
             */
            protected function myMap_mapMouseDownHandler(event:MapMouseEvent):void
            {
                var grGeometry:MapPoint = event.mapPoint;
                var grAttributes:Object = new Object();
                grAttributes.creationDate = new Date().toString();
    
                var gr:Graphic = new Graphic(grGeometry, sms, grAttributes);
                gr.toolTip = gr.attributes.creationDate;
    
                var grId:String = myGraphicsLayer.add(gr);
    
                trace(StringUtil.substitute("Graphic with id: {0} added.", grId));
    
                lastAddedGraphic = gr;
            }
   
            /**
             * Listen clear all button click handler
             */
            protected function btnClearClick(event:MouseEvent):void
            {
                myGraphicsLayer.clear();
                lastAddedGraphic = null;
            }
   
            /**
             * Listen remove button click handler
             */
            protected function btnRemoveClick(event:MouseEvent):void
            {
                if (lastAddedGraphic != null)
                {
                    try
                    {
                        var grId:String = lastAddedGraphic.id;
                        myGraphicsLayer.remove(lastAddedGraphic);
                        trace(StringUtil.substitute("Graphic with id: {0} removed.", grId));
                        lastAddedGraphic = null;
                    }
                    catch (err:Error)
                    {
                        trace(err.message);
                    }     
                }
            }
   
        ]]>
    </fx:Script>
 
    <fx:Declarations>
        <!-- Symbol for all point shapes -->
        <esri:SimpleMarkerSymbol id="sms"
                                           color="0x00FF00"
                                           size="12"
                                           style="{SimpleMarkerSymbol.STYLE_DIAMOND}"/>
 </fx:Declarations>
 
 <esri:Map id="myMap"
     mapMouseDown="myMap_mapMouseDownHandler(event)"
     level="3"
     wrapAround180="true">
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"/>
  <esri:GraphicsLayer id="myGraphicsLayer"/>
 </esri:Map>
 
 <s:Button id="btnClearAll" label="Clear all graphics" click="btnClearClick(event)"/>
 <s:Button id="btnRemove" label="Remove last graphics" click="btnRemoveClick(event)"/>
</s:Application>
0 Kudos