Solved! Go to Solution.
Karl,
Try this.
<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" creationComplete="application1_creationCompleteHandler(event)"> <fx:Script> <![CDATA[ import com.esri.ags.Graphic; import com.esri.ags.SpatialReference; import com.esri.ags.events.GeometryServiceEvent; import com.esri.ags.geometry.MapPoint; import com.esri.ags.layers.GraphicsLayer; import com.esri.ags.tasks.supportClasses.ProjectParameters; import mx.controls.Alert; import mx.events.FlexEvent; import mx.rpc.events.FaultEvent; private var gLayer:GraphicsLayer; protected function btnSubmit_clickHandler(event:MouseEvent):void { if (lat.text!="" && lon.text != ""){ var latitude:Number = Number(lat.text); var longitude:Number = Number(lon.text); var graPoint:MapPoint = new MapPoint(longitude,latitude,new SpatialReference(27700)); if(myMap.spatialReference.wkid != graPoint.spatialReference.wkid){ var outSR:SpatialReference = myMap.spatialReference; const projectParameters:ProjectParameters = new ProjectParameters; projectParameters.geometries = [graPoint]; projectParameters.outSpatialReference = outSR; geometryService.project(projectParameters); }else{ var gra:Graphic = new Graphic(graPoint); gLayer.clear(); gLayer.add(gra); myMap.centerAt(graPoint); } } } protected function projectCompleteHandler(event:GeometryServiceEvent):void { var pt:MapPoint = (event.result as Array)[0]as MapPoint; var gra:Graphic = new Graphic(pt); gLayer.clear(); gLayer.add(gra); myMap.centerAt(pt); } protected function application1_creationCompleteHandler(event:FlexEvent):void { gLayer = new GraphicsLayer(); myMap.addLayer(gLayer); } protected function geometryService_faultHandler(event:FaultEvent):void { Alert.show(event.fault.faultString + "\n\n" + event.fault.faultDetail, "Geometry Service Error " + event.fault.faultCode); } ]]> </fx:Script> <fx:Declarations> <esri:GeometryService id="geometryService" concurrency="last" fault="geometryService_faultHandler(event)" projectComplete="projectCompleteHandler(event)" showBusyCursor="true" url="http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer"/> </fx:Declarations> <esri:Map id="myMap"> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/> </esri:Map> <s:Label text="Latitude" left="10" top="10" height="21"/> <s:TextInput id="lat" top="10" left="60"/> <s:Label text="Longitude" left="190" top="10" height="21"/> <s:TextInput id="lon" top="10" left="250"/> <s:Button id="btnSubmit" label="Plot" click="btnSubmit_clickHandler(event)" left="380" top="10"/> </s:Application>
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:
Karl,
Try this.
<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" creationComplete="application1_creationCompleteHandler(event)"> <fx:Script> <![CDATA[ import com.esri.ags.Graphic; import com.esri.ags.SpatialReference; import com.esri.ags.events.GeometryServiceEvent; import com.esri.ags.geometry.MapPoint; import com.esri.ags.layers.GraphicsLayer; import com.esri.ags.tasks.supportClasses.ProjectParameters; import mx.controls.Alert; import mx.events.FlexEvent; import mx.rpc.events.FaultEvent; private var gLayer:GraphicsLayer; protected function btnSubmit_clickHandler(event:MouseEvent):void { if (lat.text!="" && lon.text != ""){ var latitude:Number = Number(lat.text); var longitude:Number = Number(lon.text); var graPoint:MapPoint = new MapPoint(longitude,latitude,new SpatialReference(27700)); if(myMap.spatialReference.wkid != graPoint.spatialReference.wkid){ var outSR:SpatialReference = myMap.spatialReference; const projectParameters:ProjectParameters = new ProjectParameters; projectParameters.geometries = [graPoint]; projectParameters.outSpatialReference = outSR; geometryService.project(projectParameters); }else{ var gra:Graphic = new Graphic(graPoint); gLayer.clear(); gLayer.add(gra); myMap.centerAt(graPoint); } } } protected function projectCompleteHandler(event:GeometryServiceEvent):void { var pt:MapPoint = (event.result as Array)[0]as MapPoint; var gra:Graphic = new Graphic(pt); gLayer.clear(); gLayer.add(gra); myMap.centerAt(pt); } protected function application1_creationCompleteHandler(event:FlexEvent):void { gLayer = new GraphicsLayer(); myMap.addLayer(gLayer); } protected function geometryService_faultHandler(event:FaultEvent):void { Alert.show(event.fault.faultString + "\n\n" + event.fault.faultDetail, "Geometry Service Error " + event.fault.faultCode); } ]]> </fx:Script> <fx:Declarations> <esri:GeometryService id="geometryService" concurrency="last" fault="geometryService_faultHandler(event)" projectComplete="projectCompleteHandler(event)" showBusyCursor="true" url="http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer"/> </fx:Declarations> <esri:Map id="myMap"> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/> </esri:Map> <s:Label text="Latitude" left="10" top="10" height="21"/> <s:TextInput id="lat" top="10" left="60"/> <s:Label text="Longitude" left="190" top="10" height="21"/> <s:TextInput id="lon" top="10" left="250"/> <s:Button id="btnSubmit" label="Plot" click="btnSubmit_clickHandler(event)" left="380" top="10"/> </s:Application>
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: