cant add graphic to graphic layer user actionscript

2942
13
Jump to solution
03-05-2012 01:16 PM
PeteVitt
Occasional Contributor III
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
Tags (2)
0 Kudos
13 Replies
TomRauch
New Contributor
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.
-->

<fx:Declarations>
 
 
  <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>
 
</fx:Declarations>


<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.lat, list.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>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
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.
0 Kudos
TomRauch
New Contributor
Ah, thanks - will start a new one.
0 Kudos
JohnCampbell4
New Contributor
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
0 Kudos