Can I zoom to a specific lat/lon?

5118
8
04-20-2011 09:06 AM
DanDong
New Contributor
Hi all,

I would like to implement such function that the user can type the latitude and longitude in the textbox and map can zoom in to this point, just like the Find function. But Find function rely on the attributes in the map layer, on the contrary, the user will type latitude and longitude in my application. Any suggestions? Thank you 🙂
0 Kudos
8 Replies
nakulmanocha
Esri Regular Contributor
You just need to create a MapPoint geometry (MyMapPoint) based on the input lat/long values. Then use ZoomTo method of Map Class.

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Map~ZoomTo...

MyMap.ZoomTo( MyMapPoint.Extent)
0 Kudos
DanDong
New Contributor
You just need to create a MapPoint geometry (MyMapPoint) based on the input lat/long values. Then use ZoomTo method of Map Class.

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Map~ZoomTo...

MyMap.ZoomTo( MyMapPoint.Extent)


Thank you Nakul! I am able to write codes like this:
        private void DecimalGo_Click(object sender, RoutedEventArgs e)
        {
            string lat = Decimal_lat.Text;   //use textbox to get the value
            string lon = Decimal_lon.Text;

            MapPoint myMapPoint = new MapPoint();
            myMapPoint.X = Convert.ToDouble(lat);
            myMapPoint.Y = Convert.ToDouble(lon);
            MyMap.ZoomTo(myMapPoint.Extent);
        }


But the projection of the maps is:

Projected Coordinate System: Illinois State Transverse_Mercator
Projection: Transverse_Mercator
False_Easting: 3280833.33333330
False_Northing: 3937000.00000000
Central_Meridian: -89.50000000
Scale_Factor: 0.99985294
Latitude_Of_Origin: 36.66666667
Linear Unit:  Foot_US

Geographic Coordinate System: GCS_North_American_1983
Datum:  D_North_American_1983
Prime Meridian:  Greenwich
Angular Unit:  Degree

So the map unit is feet and myMapPoint.X and myMapPoint.Y should have the value of distance with the feet unit, instead of degree of lat and lon. Do you have any suggestion on how to transfer feet to lat/lon?
0 Kudos
nakulmanocha
Esri Regular Contributor
You can project the MapPoint using Illinois State Transverse_Mercator. Please take alook at thi sample. Similar to what you are looking to do.

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Project
0 Kudos
DanDong
New Contributor
Hi Nakul, thank you very much!! That is so powerful! I have successfully implemented it based on this sample.

Furthermore, since  resultGraphic.Geometry is a point and I checked it's extent. It seems like the x.min=x.max and y.min=y.max. So when I use this line: MyMap.ZoomTo(resultGraphic.Extent), it doesn't work. Thus I use an envelope to display a defined extent by adding 2500 feet for left, right, up and down sides.

                double buff = 2500; 
                ESRI.ArcGIS.Client.Geometry.Envelope resultGraphicExtent = resultGraphic.Geometry.Extent;
                double minX = resultGraphicExtent.XMin;
                double minY = resultGraphicExtent.YMin;
                double maxX = resultGraphicExtent.XMax;
                double maxY = resultGraphicExtent.YMax;

                ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
                minX - buff,
                minY - buff,
                maxX + buff,
                maxY + buff);

                MyMap.ZoomTo(displayExtent);
0 Kudos
nakulmanocha
Esri Regular Contributor
I don't think there is a extent proeprty available for Graphic. Since resultGraphic.Geometry is MapPoint. You should use MyMap.ZoomTo(resultGraphic.Geometry.Extent) which should zoom to the minimum enclosing envelope of the point.

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Geometry.M...


Alternatively, you can also use the Expand method of Envelope class to creates a new envelope expanded by the amount specified from the original envelope.

Envelope expanded = myEnvelope.Expand(1.1);

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Geometry.E...
0 Kudos
DanDong
New Contributor
Actually I tied this method: MyMap.ZoomTo(resultGraphic.Geometry.Extent).

But the map cannot zoom in. I checked the value of resultGraphic.Geometry.Extent and we can see from it that the x.min=x.max, y.min=y.max. I attach a screenshot of this.
[ATTACH]6128[/ATTACH]
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You can't use 'ZoomTo' to zoom to a point (i.e. xmin==xmax and ymin == ymax).

You have to create an envelope centered on this point but having a non nul size.
0 Kudos
DanDong
New Contributor
You can't use 'ZoomTo' to zoom to a point (i.e. xmin==xmax and ymin == ymax).

You have to create an envelope centered on this point but having a non nul size.


Thank you Dominique! I used a envelope with 2500 feet added to each of the four sides (up, down, left and right) around the point. It is great to know we cannnot use ZoomTo method to a point since it's two x values are the same.
0 Kudos