Impossible to Zoom on a MapPoint

2493
5
07-07-2016 08:25 AM
AlexandreMERMOZ
New Contributor

Hi

I'm new on ArcGIS ESRI, so sorry for my question :

I try to zoom on a MapPoint but nothing run. I've try the "CenterAndZoom" method and the ZoomTo(new Envelope(...)).

This is my code :

private void _mapLoad(object sender, RoutedEventArgs e)
        {
            GraphicsLayer gLayer = MyMap.Layers["G_LAYER"] as GraphicsLayer;
            if (gLayer == null)
            {


                gLayer = new GraphicsLayer(){ ID = "gLayer" };
                MyMap.Layers.Add(gLayer);


                Graphic marker = new Graphic();
                marker.Symbol = new SimpleMarkerSymbol();
                gLayer.Graphics.Add(marker);
            }
            MapPoint location = new MapPoint(46.780764, 4.853947000000062, MyMap.SpatialReference);
            gLayer.Graphics[0].Geometry = ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(location);
            Envelope envFullExtent = gLayer.FullExtent;
            MyMap.ZoomTo(envFullExtent);
            MyMap.PanTo(location);


            //MyMap.ZoomTo(new Envelope(location.X - 100, location.Y - 100, location.X + 100, location.Y + 100));
            //_centerAndZoom(MyMap, location, MyMap.Resolution);
        }


        //private void _centerAndZoom(Map map, MapPoint mapPoint, double resolution)
        //{
        //    double ratio = 1.0;
        //    if (map.Resolution != 0.0)
        //    {
        //        ratio = resolution / map.Resolution;
        //    }


        //    if (ratio == 1.0)
        //    {
        //        map.PanTo(mapPoint);
        //    }
        //    else
        //    {
        //        MapPoint mapCenter = map.Extent.GetCenter();
        //        double X = (mapPoint.X - ratio * mapCenter.X) / (1 - ratio);
        //        double Y = (mapPoint.Y - ratio * mapCenter.Y) / (1 - ratio);
        //        map.ZoomToResolution(resolution, new MapPoint(X, Y));
        //    }
        //}

With the "CenterAndZoom" method, I have a "NullReferenceException" on the "map.Extent.GetCenter();" (l. 43) and for the "MyMap.ZoomTo(new Envelope(location.X - 100, location.Y - 100, location.X + 100, location.Y + 100));", I have a blank page with my point in the left up corner. For the "ZoomTo" with "PanTo", nothing.

Please, can you bring me your help ?

Thanks to you

0 Kudos
5 Replies
ChrisSmith7
Frequent Contributor

I don't have a way to test Silverlight any longer, so I can't test/troubleshoot. But, what happens if you send your MapPoint location to the ZoomTo() method?

By the way, you should seriously contemplate dropping Silverlight ASAP and move to the JSAPI.

0 Kudos
AlexandreMERMOZ
New Contributor

Thanks for your reply,

Nothing happens when i send my MapPoint Location to ZoomTo()

And I have test on another project with button (With the sample), and I realize that when i make that :

    

private void _zoomTo(object sender, RoutedEventArgs e)
{
     MapPoint PointTest = new MapPoint(100, 100, MyMap.SpatialReference);
     MyMap.PanTo(PointTest);
}

The result is always on the point 0,0, at the equator (With PanTo and ZoomTo).

I don't very like Silverlight, but I can't do otherwise, it's for my work...

0 Kudos
ChrisSmith7
Frequent Contributor

Are you sure your SpatialReference is valid for the coordinates? Can you sandbox in a minimalistic app and reproduce the error, as a sanity check, or maybe try to reverse engineer the culprit, e.g. by slowly adding functionality back until it re-occurs? I know your hands are tied with Silverlight - you should let them know it has been sunseted and, I believe, may already be unsupported by Esri!

0 Kudos
AlexandreMERMOZ
New Contributor

Ok, so I think I've understood where is the problem.

When I create a point, I send two parameters in latitude and longitude format, but when I want to zoom or to pan, it's not the same format, and this is the problem.

So, I'm trying to search a way to convert this format into the latitude and longitude format, somebody know if it's possible and how realize it ?

(I don't very understand how SpatialReference work...)

0 Kudos
ChrisSmith7
Frequent Contributor

Do you know what the value of SpatialReference is when you debug?

0 Kudos