+ Reply to Thread
Results 1 to 14 of 14

Thread: cant add graphic to graphic layer user actionscript

  1. #1
    pete vitt
    Join Date
    Jul 2010
    Posts
    74
    Points
    0
    Answers Provided
    1


    0

    Default cant add graphic to graphic layer user actionscript

    I just cant seem to add a graphic to my graphic layer using actionscript --
    I'm trying to add a point graphic where the user clicks the map -- this is what I have:

    protected function MapClickHandler(event:MapMouseEvent):void
    {
    const mapPoint:MapPoint = theMap.toMapFromStage(event.stageX, event.stageY);
    mapPoint.spatialReference = new SpatialReference(102100);

    var myGraphicMarker:Graphic = new Graphic(mapPoint,
    new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 22, 0x009933));

    myGraphicMarker.toolTip = "Marker added with ActionScript";
    pointGraphicsLayer.add(myGraphicMarker);
    pointGraphicsLayer.refresh();

    }

    <esri:Map id="theMap"
    mapClick="MapClickHandler(event)">
    <esri:GraphicsLayer id="pointGraphicsLayer">
    </esri:Map>

    I've confirmed that event.stageX and stageY are returning map coords by putting the results in a text box -- Any help on what I could be missing would be appreciated.

    Thanks

    Pete

  2. #2
    Robert Scheitlin

    Join Date
    Mar 2010
    Posts
    9,260
    Points
    5579
    Answers Provided
    938


    0

    Lightbulb Re: cant add graphic to graphic layer user actionscript

    Pete,

    Try using the built-in MapPoint that is returned by MapMouseEvent.

    Code:
                protected function MapClickHandler(event:MapMouseEvent):void
                {
                    const mapPoint:MapPoint = event.mapPoint;
                    mapPoint.spatialReference = new SpatialReference(102100);
                    
                    var myGraphicMarker:Graphic = new Graphic(mapPoint,
                        new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 22, 0x009933));
                    
                    myGraphicMarker.toolTip = "Marker added with ActionScript";
                    pointGraphicsLayer.add(myGraphicMarker);
                    pointGraphicsLayer.refresh();
                    
                }
    And you need to terminate your GraphicsLayer:

    Code:
    <esri:Map id="theMap" mapClick="MapClickHandler(event)">
    <esri:GraphicsLayer id="pointGraphicsLayer" />
    </esri:Map>
    Don't forget to click the Mark as answer check and to click the top arrow (promote) as shown below:
    Just because it's not the answer you want, does not mean that it is not the answer.

    Robert Scheitlin

    GIS Manager
    Calhoun County, Alabama


  3. #3

    Join Date
    Mar 2012
    Posts
    6
    Points
    0
    Answers Provided
    0


    0

    Default Re: cant add graphic to graphic layer user actionscript

    It is useful for me!

  4. #4
    pete vitt
    Join Date
    Jul 2010
    Posts
    74
    Points
    0
    Answers Provided
    1


    0

    Default Re: cant add graphic to graphic layer user actionscript

    Thanks Robert - I tried that method but the graphics still dont appear. The graphicAdd event on the graphicsLayer does fire after the code is run, however so the code is adding the graphic to the graphic layer, but it doesnt appear. I also tried changing the wkid to 3857 -- that didnt work either

    Pete

    .

  5. #5
    Robert Scheitlin

    Join Date
    Mar 2010
    Posts
    9,260
    Points
    5579
    Answers Provided
    938


    0

    Lightbulb Re: cant add graphic to graphic layer user actionscript

    Pete,

    You need to share more of your code than because I did a quick and simple app using what I posted and it works fine.
    Just because it's not the answer you want, does not mean that it is not the answer.

    Robert Scheitlin

    GIS Manager
    Calhoun County, Alabama


  6. #6
    pete vitt
    Join Date
    Jul 2010
    Posts
    74
    Points
    0
    Answers Provided
    1


    0

    Default Re: cant add graphic to graphic layer user actionscript

    I've attached the component in a text file.
    Attached Files

  7. #7
    Robert Scheitlin

    Join Date
    Mar 2010
    Posts
    9,260
    Points
    5579
    Answers Provided
    938


    1

    Lightbulb Re: cant add graphic to graphic layer user actionscript

    Pete,

    Your issue is not in the code you sent me because I took it and adde the CompProjectLocation.mxml and added it to an new Application and commented out the skins I did not get from you and the Nav tools and When I click on the map a blue diamond appears...
    Click image for larger version

Name:	Screenshot.jpg
Views:	51
Size:	88.9 KB
ID:	12452
    Just because it's not the answer you want, does not mean that it is not the answer.

    Robert Scheitlin

    GIS Manager
    Calhoun County, Alabama


  8. #8
    pete vitt
    Join Date
    Jul 2010
    Posts
    74
    Points
    0
    Answers Provided
    1


    0

    Default Re: cant add graphic to graphic layer user actionscript

    Thanks Robert for looking at this. I've had warnings pop up in my console about some of the esri classes I'm importing. Warnings such as:
    The class com.esri.ags.geometry.MapPoint has been used in a call to net.registerClassAlias() in _ModRound2Form_FlexInit. This will cause Round2Form:ModRound2Form to be leaked. To resolve the leak, define com.esri.ags.geometry.MapPoint in the top-level application.

    I need to dig more into this I guess. The map component is being used in ModRound2Form -- ModRound2Form is one of a number of modules that are swapped out using ModuleLoader in the main application

  9. #9
    Robert Scheitlin

    Join Date
    Mar 2010
    Posts
    9,260
    Points
    5579
    Answers Provided
    938


    2
    This post is marked as the answer

    Lightbulb Re: cant add graphic to graphic layer user actionscript

    Pete,

    So what that message means is that you need to import
    Code:
    import com.esri.ags.geometry.MapPoint;
    in your main mxml Application.

    You still need to mark this post as answered (follow the pictures steps left to right).

    Don't forget to click the Mark as answer check and to click the top arrow (promote) as shown below:
    Just because it's not the answer you want, does not mean that it is not the answer.

    Robert Scheitlin

    GIS Manager
    Calhoun County, Alabama


  10. #10
    pete vitt
    Join Date
    Jul 2010
    Posts
    74
    Points
    0
    Answers Provided
    1


    0

    Default Re: cant add graphic to graphic layer user actionscript

    I had the map component inside of an mx:tabNavigator and that seemed (for whatever reason) to be the cause of the graphic not appearing on the map when clicked. When I put the component inside of a viewstack it worked fine.

  11. #11
    Tom Rauch
    Join Date
    Mar 2012
    Posts
    40
    Points
    0
    Answers Provided
    0


    0

    Default Re: cant add graphic to graphic layer user actionscript

    Hi, here's my problem: I can access all the xml data from a php feed, but the script below returns only one data point. I should have several hundred.

    Thanks for any help! Tom

    <?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:esri="http://www.esri.com/2008/ags"
    pageTitle="World Street Map"
    creationComplete="service.send();" xmlns:mx="library://ns.adobe.com/flex/mx">

    <!--
    This sample shows how to add a street basemap layer to your application.

    The sample uses a cached map service from ArcGIS Online.

    You can browse the ArcGIS.com site for additional online basemap and reference
    map services or publish your own geographic data as a service using ArcGIS Server.
    -->

    <fxeclarations>


    <mx:HTTPService id="service" url="http://192.168.1.49/buoy/flex/metar.php" result="myMap_loadHandler(event)" />

    <esri:Extent id="initialExtent"
    xmin="-19325128.942" ymin="-10948057.675" xmax="-539964.871" ymax="18364625.427">
    <esri:SpatialReference wkid="102100"/>
    </esri:Extent>

    </fxeclarations>


    <fx:Script>
    <![CDATA[
    import com.esri.ags.Graphic;
    import com.esri.ags.events.ExtentEvent;
    import com.esri.ags.events.GeometryServiceEvent;
    import com.esri.ags.events.MapEvent;
    import com.esri.ags.geometry.Geometry;
    import com.esri.ags.geometry.MapPoint;
    import com.esri.ags.geometry.Polygon;
    import com.esri.ags.symbols.PictureMarkerSymbol;
    import com.esri.ags.symbols.SimpleMarkerSymbol;
    import com.esri.ags.tasks.supportClasses.BufferParameters;
    import com.esri.ags.utils.WebMercatorUtil;

    import flash.sensors.Geolocation;

    import mx.collections.ArrayCollection;
    import mx.collections.XMLListCollection;
    import mx.rpc.events.ResultEvent;

    private function myMap_loadHandler(event:ResultEvent):void
    {
    var list:ArrayCollection = event.result.markers.marker;
    for (var i:int=0; i < list.length; i++) {

    var lat: Number;
    var lon: Number;




    var myGraphicMarker:Graphic = new Graphic(new MapPoint(list[i].lat, list[i].lon,
    new SpatialReference(102100)),
    new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 22, 0x009933));



    myGraphicsLayer.add(myGraphicMarker);
    myGraphicsLayer.refresh();
    }


    }

    ]]>
    </fx:Script>

    <esri:Map extent="{initialExtent}" wrapAround180="true" >
    <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
    <esri:GraphicsLayer id="myGraphicsLayer"/>

    </esri:Map>




    </s:Application>

  12. #12
    Robert Scheitlin

    Join Date
    Mar 2010
    Posts
    9,260
    Points
    5579
    Answers Provided
    938


    0

    Lightbulb Re: cant add graphic to graphic layer user actionscript

    Tom,

    As this is a new question specific to you and this thread has already been answered, forum etiquette says you should not hijack a thread you should start your own.
    Just because it's not the answer you want, does not mean that it is not the answer.

    Robert Scheitlin

    GIS Manager
    Calhoun County, Alabama


  13. #13
    Tom Rauch
    Join Date
    Mar 2012
    Posts
    40
    Points
    0
    Answers Provided
    0


    0

    Default Re: cant add graphic to graphic layer user actionscript

    Ah, thanks - will start a new one.

  14. #14
    John Campbell
    Join Date
    Dec 2011
    Posts
    2
    Points
    1
    Answers Provided
    0


    0

    Default Re: cant add graphic to graphic layer user actionscript

    Quote Originally Posted by pvitt View Post
    Thanks Robert for looking at this. I've had warnings pop up in my console about some of the esri classes I'm importing. Warnings such as:
    The class com.esri.ags.geometry.MapPoint has been used in a call to net.registerClassAlias() in _ModRound2Form_FlexInit. This will cause Round2Form:ModRound2Form to be leaked. To resolve the leak, define com.esri.ags.geometry.MapPoint in the top-level application.
    I ran into the same problem with mx.messaging.messages.SOAPMessage and some custom widgets. I'm using FB 4.6 and Flex Viewer 3.0. Problem did not arise wth FB 4.1 and Flex Viewer 2.3.1. Not only did I have to import the class into index.mxml as Robert pointed out but I also had to create a variable of the same class to fix the problem (no error messages in debug console):

    import mx.messaging.messages.SOAPMessage;

    private var _dummy:SOAPMessage;

    John Campbell
    GIS Application Developer

    Kingston, Ontario, Canada
    geospatialweb.ca
    Last edited by geospatialweb; 06-28-2012 at 09:14 AM.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts