Select to view content in your preferred language

Symbol not showing in correct place

662
3
Jump to solution
10-22-2012 07:21 AM
PhilipTownsend
Emerging Contributor
I need to place a symbol on a map at a specified Lat/Lon coordinate. For testing purposes, I am executing my method from a mouse click anywhere on the map. I have hard coded the coordinate values and am using the following spatial reference

<esri:SpatialReference id="wgs" wkid="4326"/>

When the method is executed, the symbol appears at 0,0 on the map and seems to disregard the coordinates passed in. My GraphicsLayer is grLayer. What am I doing wrong? Thanks!

   private function onMapClick(event:MapMouseEvent):void{
    var coordstring:String = "38.0594, 81.1121";
    var coords:Array = coordstring.split(",");
    var g:Graphic = new Graphic(new MapPoint(coords[0],coords[1],wgs));
    grLayer.add(g);
    //Alert.show("Mouse clicked at: " + event.mapPoint.x + "|" + event.mapPoint.y);
   }
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
What projection is your application? If it's in Web Mercator, you'll have to project that point to that projection, like in the following:

private function onMapClick(event:MapMouseEvent):void{      var coordstring:String = "38.0594, 81.1121";      var coords:Array = coordstring.split(",");      var mappoint1:MapPoint = new MapPoint(coords[0],coords[1],wgs);      var mappoint2:Geometry = WebMercatorUtil.geographicToWebMercator(mappoint1);       var g:Graphic = new Graphic();      g.geometry = mappoint2;          grLayer.add(g); }         

View solution in original post

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor
What projection is your application? If it's in Web Mercator, you'll have to project that point to that projection, like in the following:

private function onMapClick(event:MapMouseEvent):void{      var coordstring:String = "38.0594, 81.1121";      var coords:Array = coordstring.split(",");      var mappoint1:MapPoint = new MapPoint(coords[0],coords[1],wgs);      var mappoint2:Geometry = WebMercatorUtil.geographicToWebMercator(mappoint1);       var g:Graphic = new Graphic();      g.geometry = mappoint2;          grLayer.add(g); }         
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Philip,

   If your maps WKID is in webmercator than use the new WebMercatorMapPoint instead:

private function onMapClick(event:MapMouseEvent):void{
    var coordstring:String = "38.0594, 81.1121";
    var coords:Array = coordstring.split(",");
    var g:Graphic = new Graphic(new WebMercatorMapPoint(coords[0],coords[1]));
    grLayer.add(g);
    //Alert.show("Mouse clicked at: " + event.mapPoint.x + "|" + event.mapPoint.y);
}


If your maps WKID (Spatial reference) is something else than you need to re-project the coordinates to that WKID:

See this sample:  http://resources.arcgis.com/en/help/flex-api/samples/01nq/01nq0000004w000000.htm


Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow these steps as shown in the below graphic:

0 Kudos
DasaPaddock
Esri Regular Contributor
0 Kudos