Select to view content in your preferred language

Problem with Displaying Markers

674
2
09-10-2011 01:32 PM
ShreyansJain
Emerging Contributor
Hi all,

I am working on a simple mashup with the Esri's arcgis api for flex and the last.fm api. This mashup would tell the users about the latest musical events from around the world. I have been able to parse the XML document and retrieve  latitude and longitude information. However, for some reason the marker symbols are not updating.Right now I am concentrating on displaying just the event locations. I would add the event descriptions once I figure out the present problem.

I am attaching the code below.
Thanks in advance 🙂

Regards
Shreyans




<?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="Music Events round the World ! ">

<fx:Script>
<![CDATA[
  import com.esri.ags.FeatureSet;
  import com.esri.ags.Graphic;
  import com.esri.ags.Map;
  import com.esri.ags.SpatialReference;
  import com.esri.ags.events.LayerEvent;
  import com.esri.ags.events.MapMouseEvent;
  import com.esri.ags.geometry.MapPoint;
  import com.esri.ags.layers.GraphicsLayer;
  import com.esri.ags.symbols.SimpleMarkerSymbol;
 
  import mx.controls.Alert;
  private static const LASTFM_API_KEY:String = "1368bd4f2cf7756fccc7d3e46f921680";
  private static const REQUEST_URL:String = "http://ws.audioscrobbler.com/2.0/?method=geo.getevents&api_key=" + LASTFM_API_KEY;
  private var myGraphicsLayer:GraphicsLayer = new GraphicsLayer();
 
 
  private function loadLastFMevents():void
  {
   var loader:URLLoader = new URLLoader();
   loader.addEventListener(Event.COMPLETE, loaderComplete);
   loader.addEventListener(IOErrorEvent.IO_ERROR,
    function(error:IOErrorEvent):void
    {
     Alert.show("IO Error");
    }
   );
  
   var request:URLRequest = new URLRequest(REQUEST_URL);
  
   loader.load(request);
  }
  private function loaderComplete(event:Event):void
  {
   var response:URLLoader = URLLoader(event.target);
   var responseData:XML = new XML(response.data);
  
   var point:MapPoint =null;
   for each (var node:Object in responseData.events.event)
   {
    point = createMarker(node);
   }
  
   if (point != null)
    myMap.centerAt(point);
  
     }
 
  // Now creating Markers
  private function createMarker(node:Object):MapPoint
  {
   var geo:Namespace = new Namespace("http://www.w3.org/2003/01/geo/wgs84_pos#");
  
   var description:String = node.title + "\n" + node.startDate + "\n" + node.venue.name;
  
   var lat:String = node.venue.location.geo::point.geo::lat;
   var long:String = node.venue.location.geo::point.geo::long;
   var latNumber:Number = parseFloat(lat);
   var longNumber:Number = parseFloat(long);
  
  
   if (isNaN(latNumber)) latNumber = 0;
   if (isNaN(longNumber)) longNumber = 0;
  
   var wgs:SpatialReference = new SpatialReference(4326);
   var point:MapPoint = new MapPoint(latNumber, longNumber,wgs);
   Alert.show(latNumber.toString()+","+latNumber.toString());
  
   // Add contents later
   var myGraphicMarker:Graphic = new Graphic(point,
    new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 22, 0x009933));
 
  myGraphicsLayer1.add(myGraphicMarker);
   return point;
  }
  protected function button1_clickHandler(event:MouseEvent):void
  {
   // TODO Auto-generated method stub
 
   loadLastFMevents();
   //Alert.show("So it Actually comes here");
  }
 
]]>
</fx:Script>

    <fx:Declarations>
        <esri:Extent id="initialExtent"
        
                     xmin="-14630000" ymin="2747000" xmax="8851000" ymax="10105000">
            <esri:SpatialReference wkid="102100"/>
        </esri:Extent>
    </fx:Declarations>

    <esri:Map extent="{initialExtent}" wrapAround180="true" id="myMap">
        <esri:ArcGISTiledMapServiceLayer
   id="mapLayer"
  
   url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
  <esri:GraphicsLayer id="myGraphicsLayer1">
  
  
  </esri:GraphicsLayer>
    </esri:Map>
<s:Button click="button1_clickHandler(event)" label="Load Events ! " />

</s:Application>
Tags (2)
0 Kudos
2 Replies
MehulChoksey
Esri Contributor
Map's projection is set to the projection of the first layer added to it. In your case its http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer with  102100 WebMarcator.
So you will need to project your geometry from 4326 spatial reference to Webmercator using http://help.arcgis.com/en/webapi/flex/apiref/index.html?com/esri/ags/utils/WebMercatorUtil.html&com/... before adding it to the map.

Mehul
0 Kudos
ShreyansJain
Emerging Contributor
Thanks Mehul ! Here is the URL for a first version of my application.

http://www.spatial.maine.edu/~shreyans.jain/mapthebands/mapthebands.html

Do you have any suggestions ?

Shrey
0 Kudos