You are here: > ESRI Forums > arcgis server forums > Thread Replies

ArcGIS Server Forums

ArcGIS API for Flex forum

How to create a MapPoint with a lat/long va...   Dennis Nguyen Aug 21, 2008
Re: How to create a MapPoint with a lat/lon...   Bjorn Svensson Aug 22, 2008
Re: How to create a MapPoint with a lat/lon...   Stephen Ansari Aug 27, 2008
Re: How to create a MapPoint with a lat/lon...   Bjorn Svensson Aug 27, 2008
Re: How to create a MapPoint with a lat/lon...   Tim Scharff Dec 31, 2008
Re: How to create a MapPoint with a lat/lon...   Dasa Paddock Dec 31, 2008
Re: How to create a MapPoint with a lat/lon...   Tim Scharff Dec 31, 2008
Re: How to create a MapPoint with a lat/lon...   Tim Scharff Jan 05, 2009
Re: How to create a MapPoint with a lat/lon...   Tim Spangler Nov 18, 2009
Re: How to create a MapPoint with a lat/lon...   Robert Scheitlin Nov 18, 2009
Re: How to create a MapPoint with a lat/lon...   wayne zhang Jan 02, 2009
Re: How to create a MapPoint with a lat/lon...   wayne zhang Jan 05, 2009
Re: How to create a MapPoint with a lat/lon...   Stephen Ansari Aug 27, 2008
Re: How to create a MapPoint with a lat/lon...   Stephen Ansari Aug 28, 2008
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject How to create a MapPoint with a lat/long values 
Author Dennis Nguyen 
Date Aug 21, 2008 
Message How I create a mappoint with lat/long values? is there any conversion code from lat/long values and x, y coordinates. Thanks 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to create a MapPoint with a lat/long values 
Author Bjorn Svensson 
Date Aug 22, 2008 
Message You can create the MapPoint directly using lat/long values. See examples below.

-Bjorn 
 
// Using ActionScript
var wgs:SpatialReference = new SpatialReference(4326);
var myBeijingPoint:MapPoint = new MapPoint(116.41,39.9,wgs);

// Using mxml
<esri:SpatialReference id="wgs" wkid="4326"/>
<esri:MapPoint x="116.41" y="39.9" spatialReference="{wgs}"/>
 
  Bjorn Svensson,
ESRI Flex team
http://resources.esri.com/arcgisserver/apis/flex/ (version 1.x)
http://resources.arcgis.com/content/arcgis-api-flex (version 2.x beta) 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to create a MapPoint with a lat/long values 
Author Stephen Ansari 
Date Aug 27, 2008 
Message If the 'base' layer is a projected ArcGISTiledMapServiceLayer, adding points using geographic coords (lat/lon) using above syntax does not appear to respect the spatialReference. The point appears near the origin, presumably as if they are placed using projected map units and not decimal degrees.

Has anyone seen this behavior, or is it even possible to place markers using lat/lon onto a projected (meters) map without using geometry service?

[link removed by author] 
 
<esri:Map logoVisible="false" >
	  <!-- Basemap is projected in web mercator wkid=102113 -->
	  <esri:ArcGISTiledMapServiceLayer url="http://www.xxxxxxx.org/arcgis/rest/services/xxxxx_webmercator/MapServer" />
	    <esri:GraphicsLayer id="myGraphicsLayer" spatialReference="{new SpatialReference(4326)}">
            <esri:Graphic id="M1" symbol="{mySymbol}">
                <esri:geometry>
                    <esri:MapPoint x="-75" y="40"  spatialReference="{new SpatialReference(4326)}" id="myPoint"/>
                </esri:geometry>
            </esri:Graphic>           
        </esri:GraphicsLayer>
    </esri:Map>

    <esri:SimpleMarkerSymbol id="mySymbol" size="18" color="0xFF0000" style="circle" alpha="1.0">
        <esri:SimpleLineSymbol color="0x00ff00" width="3" alpha="1.0" style="solid"/>
    </esri:SimpleMarkerSymbol>
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to create a MapPoint with a lat/long values 
Author Bjorn Svensson 
Date Aug 27, 2008 
Message Steven is correct. The graphics needs to be specified in the same projection as the map projection.

It doesn't matter what you set the graphic spatial reference to. The spatial reference is only used/useful for when sending it as input to different tasks on the server side.

If you have latlongs that you would like to put on the map, you will have to project them. This is because there is no client side projection for either Flex or JavaScript APIs. You need to use the geometry service.

Cheers,
Bjorn 
  Bjorn Svensson,
ESRI Flex team
http://resources.esri.com/arcgisserver/apis/flex/ (version 1.x)
http://resources.arcgis.com/content/arcgis-api-flex (version 2.x beta) 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to create a MapPoint with a lat/long values 
Author Tim Scharff 
Date Dec 31, 2008 
Message We're experiencing a similar problem with trying to take user input lat/long coordinates and plot them on a map that's in a state plane coordinate system. We have tried using a geometry service to project point coordinates (graphic) but the graphic still appears near the origin. Please see code snippet below of the 2 main functions involved.

As additional background, we have modified the sample viewer so that the Locate widget has 4 radio buttons on the dialog box: decimal degrees (DD), degrees and minutes (DM), degrees, minutes and seconds (DMS), and state plane. As an example, if the user selects DD, the script should attempt to project the input coordinates to state plane before placing a graphic on the map.

The geometry service has been created (and referenced in the script) and we believe we've imported the necessary modules, but in the end the x and y values are unchanged from the original user input. Please help. 
 
private function locateCoordinates():void
{
	graphicsLayer.clear();
	WidgetEffects.flipWidget(this, viewStack, "selectedIndex", 2, 400);
	if (coordinateType.selectedValue=="DD")
	{
		try
		{
			var long:String = txtLong.text;
			var lat:String = txtLat.text;
			if ((long) && (lat))
			{
				var point:MapPoint = new MapPoint(Number(long), Number(lat),new SpatialReference(4152));
				//point.spatialReference= new SpatialReference(4269);
				var icon:String = widgetIcon;
				var title:String = coordinatesLabel;  
				var content:String = long.toString() + ", " + lat.toString();
				var link:String = "";
				var infoData:Object = 
				{
					icon: icon, 
					title: title, 
					content: content, 
					link: link, 
					point: point,
					geometry: point
				};
					var recAC:ArrayCollection =  new ArrayCollection([infoData]);                
					wRepeater.dataProvider = recAC;
					this.addSharedData(widgetTitle, recAC);
					showLocation(infoData);
					showMessage(locationsLabel, false);
			}
		}
		catch (error:Error)
		{
			showMessage(error.message, false);
		}
	}
	else 
		if (coordinateType.selectedValue=="DM")
		{
			<<do something>>
		}
}

=====================

private function showLocation(infoData:Object):void
{
	var pt:MapPoint = infoData.point
	var outSR : SpatialReference = new SpatialReference(102667)
	var ptGraphic:Graphic = new Graphic(pt);
	ptGraphic.attributes = infoData;
	graphicsLayer.add(ptGraphic)
	geometryService.project([ptGraphic],outSR)

	ptGraphic.addEventListener(MouseEvent.ROLL_OVER, mouseOverGraphic);

	if (map.scale > zoomScale)
		map.scale = zoomScale;
		map.centerAt(pt);
		this.showInfoWindow(infoData);
}
 
  Tim Scharff
Cobb County 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to create a MapPoint with a lat/long values 
Author Dasa Paddock 
Date Dec 31, 2008 
Message You shouldn't add the graphic to the graphics layer in the showLocation function since the point hasn't been reprojected yet. You need to use the result of the project() call. You can add a listener to the geometry service, or pass a IResponder to the project call. See this sample: http://resources.esri.com/help/9.3/arcgisserver/apis/flex/samples/index.html?sample=ProjectPoint 
  Dasa Paddock
ArcGIS API for Flex
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to create a MapPoint with a lat/long values 
Author Tim Scharff 
Date Dec 31, 2008 
Message Thanks, Dasa. We noticed that sample before, but we'll take another look at it. The sample is a little different -- it starts with a user clicked point on the map (an actual point in the same projection as the point), while we're starting with hand-entered coordinates (in this case, in a different projection). But we'll take a closer look and post back with the results. 
  Tim Scharff
Cobb County 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to create a MapPoint with a lat/long values 
Author Tim Scharff 
Date Jan 05, 2009 
Message We were finally able to get this to work. In the end, we were just piggybacking too much on existing code. Setting up new functions/ listeners was definitely the way to go (see post from Wayne Zhang). The last hurdle was getting the "red glow" to display in the correct location when the user hovers the cursor over the record in the results pane (it wanted to show in the un-projected location), but even this works now.

Thank you very much for the help. Wayne has shared the code snippet for anyone else interested in doing the same. 
  Tim Scharff
Cobb County 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to create a MapPoint with a lat/long values 
Author Tim Spangler 
Date Nov 18, 2009 
Message Tim;
From this post, it sounds as if you were able to finalize code that permits a user to plot a location by entering coordinates that are different than the map projection. My map data is in state plane and I need a user to be able to determine a location by typing in decimal degrees.
If your code does this, are you able to provide it in a mxml format? I'm relatively new to ESRI Flex and I'm not sure how to insert you code.

Tim Spangler
Cambria County PA 911 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to create a MapPoint with a lat/long values 
Author Robert Scheitlin 
Date Nov 18, 2009 
Message Tim,

I have posted a modified version of the LocateWidget that handles entering DMS, DD, UTM, and State Plane coordinates. All you have to do is change the LocateWidget.xml to change the WKIDs for the UTM and State Plane to be the one that work for your data. Find the post here

http://forums.esri.com/Thread.asp?c=158&f=2421&t=293818#922239 
  Robert Scheitlin
GIS Manager
Calhoun County, Alabama 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to create a MapPoint with a lat/long values 
Author wayne zhang 
Date Jan 02, 2009 
Message Thanks for your comment. We changed the code below and it can locate the projected point. However, the event target is always the Decimal degree point and when you move the mouse over the widget record. It shows hightlight in Decimal degree point. I tried couple of ways and it still stick to Decimal degree point. Any help is appreciated 
 
private function projectCompleteHandler(event:GeometryServiceEvent) :void   
			  {               
			  	 var g:Graphic = event.graphics[0];              
			  	 var pt : MapPoint = g.geometry as MapPoint;
			  	 var point:MapPoint = new MapPoint(pt.x,pt.y);
			  	 var icon:String = widgetIcon;
						var title:String = coordinatesLabel;  
						var content:String = xdd.toString() + ", " + ydd.toString();
						var link:String = "";
						var infoData:Object = 
						{
							icon: icon, 
							title: title, 
							content: content, 
							link: link, 
							point: point,
							geometry: point
						};     
				var ptGraphic:Graphic = new Graphic(point);            
			  	//graphicsLayer.clear()
			  	ptGraphic.addEventListener(MouseEvent.ROLL_OVER, mouseOverGraphic);
			  	graphicsLayer.add(ptGraphic)
			  	
			  	if (map.scale > zoomScale)
					map.scale = zoomScale;
				map.centerAt(pt);
			  	this.showInfoWindow(infoData);
           
			  }
private function showLocation(infoData:Object):void

			{
				var pt:MapPoint = infoData.point
				var outSR : SpatialReference = new SpatialReference(102667)
				var ptGraphic:Graphic = new Graphic(pt); 
				//ptGraphic.geometry = pt;    
				//ptGraphic.attributes = infoData; 
				//graphicsLayer.add(ptGraphic)
				geometryService.project([ptGraphic],outSR) 		

				ptGraphic.addEventListener(GeometryServiceEvent.PROJECT_COMPLETE,projectCompleteHandler); 
}				
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to create a MapPoint with a lat/long values 
Author wayne zhang 
Date Jan 05, 2009 
Message I finally make new showprjLocation function and add projectCompleteHandler event function. It works. 
 
private function projectCompleteHandler(event:GeometryServiceEvent) :void   
			  {               
			  	 var g:Graphic = event.graphics[0];              
			  	 var pt : MapPoint = g.geometry as MapPoint;
			  	 var point:MapPoint = new MapPoint(pt.x,pt.y);
			  	 var icon:String = widgetIcon;
						var title:String = coordinatesLabel;  
						var content:String = xdd.toString() + ", " + ydd.toString();
						var link:String = "";
						var infoData:Object = 
						{
							icon: icon, 
							title: title, 
							content: content, 
							link: link, 
							point: point,
							geometry: point
						};     
				var recAC:ArrayCollection =  new ArrayCollection([infoData]);                
				wRepeater.dataProvider = recAC;
				this.addSharedData(widgetTitle, recAC);
				var ptGraphic:Graphic = new Graphic(point);  
				          
			  	//graphicsLayer.clear()
			  	ptGraphic.addEventListener(MouseEvent.ROLL_OVER, mouseOverGraphic);
			  	graphicsLayer.add(ptGraphic)
			  	
			  	if (map.scale > zoomScale)
					map.scale = zoomScale;
				map.centerAt(pt);
			  	this.showInfoWindow(infoData);
           
			  }
private function showprjLocation(infoData:Object):void

			{
				var pt:MapPoint = infoData.point
				var outSR : SpatialReference = new SpatialReference(102667)
				var ptGraphic:Graphic = new Graphic(pt); 
				//ptGraphic.geometry = pt;    
				//ptGraphic.attributes = infoData; 
				//graphicsLayer.add(ptGraphic)
				geometryService.project([ptGraphic],outSR) 		

				ptGraphic.addEventListener(GeometryServiceEvent.PROJECT_COMPLETE,projectCompleteHandler); 
				
			}
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to create a MapPoint with a lat/long values 
Author Stephen Ansari 
Date Aug 27, 2008 
Message When I think about it, this makes sense. The other APIs only need one projection formula in their client, but ESRI would have to put thousands of different projection/transformation formulas to account for all the projections they support.

Has anyone done this calculation between Web Mercator and WGS84 in the client? 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to create a MapPoint with a lat/long values 
Author Stephen Ansari 
Date Aug 28, 2008 
Message Here is some code that works in both directions. This allows a projected map to integrate with other webservices that only support geographic coordinates (lat/lon).

[link removed by author] 
 
			private  var DEG_TO_RAD:Number = 0.017453292519943296;
			private  var RAD_TO_DEG:Number = 57.295779513082322;
			private  var PI:Number = 3.14159267;
			private  var MAGIC_NUM:Number = 6356752.3142;

    		private function mercator_meters_to_degrees(X:Number,Y:Number):Object {
				var lat:Number;
				var lon:Number

				lat = RAD_TO_DEG * ( (2 * Math.atan( Math.exp( Y / MAGIC_NUM ) ) ) - (PI/2) ); 
				lon = RAD_TO_DEG * (X / MAGIC_NUM);
				
				//Limit decimal places
				lat = Math.round(lat*(10000)) / (10000); 
				lon = Math.round(lon*(10000)) / (10000); 
				//Limit to World
				if(lat <= -90) lat=-90;
				if(lat >= 90)  lat=90;
				if(lon <= -180)lon=-180;
				if(lon >= 180) lon=180;
				
 				return {y:lat,x:lon};
			}
    		private function degrees_to_mercator_meters (lon:Number,lat:Number):Object {
				var Y:Number;
				var X:Number;

				//Limit to World
				if(lat<=-90)lat=-90;
				if(lat>=90)lat=90;
				if(lon<=-180)lon=-180;
				if(lon>=180)lon=180;
				
				Y = Math.round(MAGIC_NUM * Math.log( Math.tan( ((lat * DEG_TO_RAD) + (PI/2)) / 2 ) ));
				X = Math.round(MAGIC_NUM * (lon * DEG_TO_RAD));
				
				return {y:Y,x:X};
			}