Simple Map Point Question

1038
16
Jump to solution
10-21-2012 07:51 AM
PhilipTownsend
New Contributor
I am new to the Flex API but not new to GIS programming.

I have a message service that will be reporting locations via Lat/Lon and I will need to locate a simple graphic on the map specified by the incoming location coordinates. It seems like this should be really simple. I have created a simple click event for testing. The points show up at the correct locations, but how do I get them to be represented by lat/lon coordinates? Obviously, the end goal is not to be using mouse clicks to determine locations. Thanks!

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

   private function onMapClick(event:MapMouseEvent):void{
    var g:Graphic = new Graphic();
    //g.geometry = new MapPoint(38.0594, 81.1121, wgs); //event.mapPoint;
    g.geometry = event.mapPoint;
    grLayer.add(g);
    Alert.show("Mouse clicked at: " + event.mapPoint.x + "|" + event.mapPoint.y);
   }
Tags (2)
0 Kudos
16 Replies
TomRauch
New Contributor
Hi Robert, thanks - I did try WebMercatorMapPoint and got the same error.  I also ran a break at the myMap.zoom and it looked like all the data that's supposed to be there is, although maybe I need to look for a specific item in my FlashBuilder debugger?

This is how I am referencing 'myMap' - not sure if that has a bearing or not:

<esri:Map id = "myMap" extent="{initialExtent}" wrapAround180="false" x="52" y="209" width="383" height="221">
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
  <esri:GraphicsLayer id="myGraphicsLayer"/>
</esri:Map>

Tom
0 Kudos
TomRauch
New Contributor
Interesting - when I click through the error message, I do get a zoomed in map, but always to the same location (the southern part of the US).  If I pull back, I do see my selected marker.

So the zoom is working, but its just not zooming to the right location (the point I select).
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Tom,

   I am not sure if you are confusing what the focupoint of the zoom function is suppose to do:
focusPoint:MapPoint (default = null) �?? The map point that should not move in relation to the screen.


<?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">
    <fx:Declarations>
        <esri:Extent id="initialExtent"
                     xmin="-17731" ymin="6710077" xmax="-12495" ymax="6712279">
            <esri:SpatialReference wkid="102100"/>
        </esri:Extent>
    </fx:Declarations>
    
    <fx:Script>
        <![CDATA[
            import com.esri.ags.Graphic;
            import com.esri.ags.geometry.WebMercatorMapPoint;
            import com.esri.ags.symbols.SimpleMarkerSymbol;
            
            private function placePoint(evt:Event):void{
                var wmp:WebMercatorMapPoint = new WebMercatorMapPoint(-0.088205,51.503306);
                var myGraphicMarker:Graphic = new Graphic(wmp, new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 22, 0x009933));
                
                myGraphicsLayer.add(myGraphicMarker);
                //If you want the map to center at the point you created use the next line.
                myMap.centerAt(wmp);

                //Delay the map zoom by 1 second
                var timeoutExample:uint = setTimeout(
                    function():void{
                        myMap.zoom(1 / 16, wmp);
                    }, 1000
                );
            }
            
        ]]>
    </fx:Script>
    
    <esri:Map id = "myMap" extent="{initialExtent}" wrapAround180="false" x="52" y="209" width="383" height="221">
        <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
        <esri:GraphicsLayer id="myGraphicsLayer"/>
    </esri:Map>
    <s:Button click="placePoint(event)" label="test" />
</s:Application>
0 Kudos
TomRauch
New Contributor
Progress!  That works, Robert - thank you.  My map now appears centered and zoomed to the map point, with the map marker visible.

But, I still get that ding-dang null error message! 

The only thing that looks odd to me is a reference to a variable called "mapX" with a value of 1.1217475844103828E7; I don't decalre a 'mapX" variable in my code, and have no clue what that value represents.

Tom
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Tom,
   I would have to see your whole project to help with that.
0 Kudos
TomRauch
New Contributor
Robert, thanks - let me give it a shot.

Tom
0 Kudos
TomRauch
New Contributor
Robert,

Just to close the loop on this issue, I used the function call:

var timeoutExample:uint = setTimeout(
        function():void{
         myMap.zoom(1 / 16, wmp);
        }, 1000
       );

instead of just myMap.zoom(1 / 16, wmp);

and now it works!

Thanks for your help, Tom
0 Kudos