3 Replies Latest reply on Mar 6, 2012 10:24 PM by stanko80

    Zoom to a Point in the Map

    stanko80
      Hello,

      I have the problem, that I need to zoom to a specific Point (my own GPS Position) in the Map... but the SpatialReference of the
      Mappoint (with the GPS-Coordinates) seems to be different, than the SpatialReference from Bing Maps. Here is the relevant part of the code...

                  SpatialReference sp = new SpatialReference();
                  sp.WKID = 4326;

                  MapPoint mpZoomToGPSPosition = new MapPoint();
                  mpZoomToGPSPosition.SpatialReference = sp;
                  mpZoomToGPSPosition.Y = epl.Latitude;
                  mpZoomToGPSPosition.X = epl.Longitude;

                 
                  MyMap.ZoomToResolution(MyMap.Resolution / 5, mpZoomToGPSPosition);


      The "ZoomToResolution"-Function works, but the WKID of the SpatialReference of "MyMap" (this is the whole map declared in the xaml-File) is "102100". Can someone help
      me please.
      Is it maybe possible to change the WKID of "MyMap".

      Thank you.
        • Re: Zoom to a Point in the Map
          stanko80
          Hello,

          ok I find out how to convert the SpatialReference, but can someone of you tell me why the Point which is given as a Parameter in the ZoomToResolution-Function is not the center of the map?

          Here is the new code...
                      SpatialReference sp = new SpatialReference();
                      sp.WKID = 4326;
          
                      MapPoint mpZoomToGPSPosition = new MapPoint();
                      mpZoomToGPSPosition.SpatialReference = sp;
                      mpZoomToGPSPosition.Y = epl.Latitude;
                      mpZoomToGPSPosition.X = epl.Longitude;
                      
                      MyMap.ZoomToResolution(MyMap.Resolution / 5, new WebMercator().FromGeographic(mpZoomToGPSPosition) as MapPoint);


          and here is the result in a screenshot....[ATTACH=CONFIG]12411[/ATTACH]

          The blue marker shows the Position of the Mappoint "mpZoomToGPSPosition".
          • Re: Zoom to a Point in the Map
            mnielsen-esristaff
            The point paramter is not the point it centers on - It's the point it zooms 'around'. Ie if you give it the upper left corner, and say "New York" was up in that corner, New York would stay in this corner, and everything else expand out around it.
            If you want to zoom and center to a point, you should create an envelope around the point and zoom to that (you can't zoom to a point, since it is infinitely small). Ie.
                map.ZoomTo(new Envelope(p.X-10,p.Y-10, p.X+10,p.Y+10));
            • Re: Zoom to a Point in the Map
              stanko80
              Thank you SharpGIS! That was the answer on my question!