Select to view content in your preferred language

Newbie need help with API 2.0

1110
12
07-12-2010 07:05 AM
MikeSavoy
New Contributor
Hi Folks,

First I am new to ARCGIS 2.0 Fex API, I am using Flash Builder 4.01
I have a running project with Google that I want to convert to ARCGIS
The problem is when I want to add throught actionscript a marker(symbol), it never show where I wanted to be
According to the examples (Adding graphics)

// This is just to show how to add markers
                // using ActionScript code as opposed to MXML tags.
                var myGraphicMarker:Graphic = new Graphic(new MapPoint(1447100, 7477200, new SpatialReference(102100)),
                                                          new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 22, 0x009933));
                myGraphicMarker.toolTip = "Marker added with ActionScript";
                myGraphicsLayer.add(myGraphicMarker);

Here where I am coming, the numbers
1447100, 7477200

I want my long lat which are -71.98, 45.33 instead of thos numbers

How can I build my own markers(symbol) with the long lat (my format) isntead of number that I don't understand how to convert them

Any clues, your support I realy appreciated

Thanks to you all

Mike
Tags (2)
0 Kudos
12 Replies
Drew
by
Regular Contributor
If you want to use lat/long you will need to change your SpatialReference to be 4326

replace



var myGraphicMarker:Graphic = new Graphic(new MapPoint(1447100, 7477200, new SpatialReference(102100)),



with

var myGraphicMarker:Graphic = new Graphic(new MapPoint(-71.98, 45.33, new SpatialReference(4326)),


Drew
0 Kudos
MikeSavoy
New Contributor
Thanks CGIShack

I have tried your example : see my code below

var myGraphicMarker:Graphic = new Graphic(new MapPoint(-71.98, 45.33, new SpatialReference(4326)),
     new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 22, 0x009933));
    myGraphicMarker.toolTip = "Marker added with ActionScript";
    repeaterLayer.add(myGraphicMarker);
    myMap.centerAt(myGraphicMarker.geometry as MapPoint);

But for a unknown reason the diamond is in africa

Thanks for your support
Mike
0 Kudos
MikeSavoy
New Contributor
Here is a copy of my code
The diamond should appear in Canada (Quebec)

<?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"
    width="100%" 
    height="100%">
 
 
 <!-- States -->
 <s:states>
  <s:State name="test"/>
 </s:states>
 
 <!-- WebServices, etc... -->
 <fx:Declarations>
  <!-- Place non-visual elements (e.g., services, value objects) here -->
 </fx:Declarations>
 
 
 <fx:Script>
  <![CDATA[
   
   //Flex
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.core.FlexGlobals;
   import mx.events.FlexEvent;
   import flash.sampler.NewObjectSample; 
   import mx.rpc.events.ResultEvent;
   
   //ESRI Object
   import com.esri.ags.events.ExtentEvent;
   import com.esri.ags.geometry.Geometry;
   import com.esri.ags.geometry.MapPoint;
   import com.esri.ags.geometry.Extent;
   import com.esri.ags.Graphic;
   import com.esri.ags.layers.TiledMapServiceLayer;
   import com.esri.ags.layers.GraphicsLayer;
   import com.esri.ags.SpatialReference;
   import com.esri.ags.symbols.PictureMarkerSymbol;
   import com.esri.ags.utils.WebMercatorUtil;
   
   //***************************************** Affichage des repeteurs **********************************
   protected function showMarker():void
   {
    var myGraphicMarker:Graphic = new Graphic(new MapPoint(-71.98, 45.33, new SpatialReference(4326)),
     new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 22, 0x009933));
    myGraphicMarker.toolTip = "Marker added with ActionScript";
    repeaterLayer.add(myGraphicMarker);
    myMap.centerAt(myGraphicMarker.geometry as MapPoint);
    
    
   }
   
  ]]>
 </fx:Script>
 <!-- Map -->
 <esri:Map id="myMap" level="4" load="myMap.centerAt(new MapPoint(-7133000, 4522000));" bottom="40" left="7" right="7" top="7">
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
  <!-- Layer -->
  <esri:GraphicsLayer id="repeaterLayer">
   <esri:Graphic>
    <esri:symbol>
     <esri:SimpleMarkerSymbol color="0x0033DD" size="18"/>
    </esri:symbol>
   </esri:Graphic>
  </esri:GraphicsLayer>
 </esri:Map> 
 <s:Button label="CLICK ME" click="showMarker();" bottom="5" left="11"/>
</s:Application>

0 Kudos
DasaPaddock
Esri Regular Contributor
Your x and y values should match the Map's spatial reference. If your map is in Web Mercator and you want to use lat/long values and you can use this utility to convert the values:
http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/utils/WebMercatorUtil.html#geographicToWeb...)
0 Kudos
MikeSavoy
New Contributor
Many thanks for your fast reply

I am to new to those stuff, I don't know the proper syntax for my code or how to use it
Is there any example that I can refer to?

Best Regards
Mike
0 Kudos
Drew
by
Regular Contributor
There is a decent sample here that shows how to use the WebMercatorUtil

http://help.arcgis.com/en/webapi/flex/samples/index.html?sample=MapCoordinates
0 Kudos
DasaPaddock
Esri Regular Contributor
0 Kudos
MikeSavoy
New Contributor
Thanks DPaddock and CGIShack

I am still with the problems in Africa
I have tried :

const mapPoint:MapPoint = new MapPoint(-71.56,45.33);
    const latlong:MapPoint = WebMercatorUtil.geographicToWebMercator(mapPoint) as MapPoint;


Wihtout succes

It must be easier I can beleive just to show a graphics where I want throught standard long, lat

Many thanks
0 Kudos
DasaPaddock
Esri Regular Contributor
Can you post the whole function?
0 Kudos