hOW TO CENTRE A MAP....

476
3
Jump to solution
06-02-2012 08:19 AM
JulieBiju
Occasional Contributor
Dears how to centre a map using the following code
In the following code i need to centre the map using e.Result(recordcount).ELat and e.Result(recordcount).ELon ??

Please help me?????

Dim gpsNMEASentences As String = "$GPGGA, 92204.9, " & e.Result(recordcount).ELat & ", N," & e.Result(recordcount).ELon & ", W, 1, 04, 2.4, 25.7, M,,,,*75"              Dim gpsNMEASentenceArray() As String = gpsNMEASentences.Split(ControlChars.Lf)              Dim gpsNMEASentence() As String = gpsNMEASentenceArray(0).Split(","c)                         Dim graphic As New Graphic() With                 {                     .Geometry = mercator.FromGeographic(New MapPoint(Convert.ToDouble(gpsNMEASentence(4)), Convert.ToDouble(gpsNMEASentence(2)))),                     .Symbol = TryCast(LayoutRoot.Resources(colourstyle), Symbol)                 }             Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)             graphicsLayer.Graphics.Clear()             graphicsLayer.Graphics.Add(graphic)              esriLogoImage.Visibility = Windows.Visibility.Collapsed             MyMap.Visibility = Windows.Visibility.Visible             MyMap.ZoomTo(graphicsLayer.FullExtent)
0 Kudos
1 Solution

Accepted Solutions
JulieBiju
Occasional Contributor
I did in the following way..It is working perfect

 ZoomToResolution(MyMap, 0.00551220549302222, New MapPoint(Convert.ToDouble(gpsNMEASentence(4)), Convert.ToDouble(gpsNMEASentence(2))))


   Private Sub ZoomToResolution(map As Map, resolution As Double, center As MapPoint)         'Workaround for Map.ZoomToResolution         Dim halfWidth As Double = resolution * MyMap.ActualWidth / 2         Dim halfHeight As Double = resolution * MyMap.ActualHeight / 2         Dim newExtent As New Envelope(center.X - halfWidth, center.Y - halfHeight, center.X + halfWidth, center.Y + halfHeight)         Map.ZoomTo(newExtent)     End Sub

View solution in original post

0 Kudos
3 Replies
JulieBiju
Occasional Contributor
I added the following code for getting a particular map point to be the centre of the map.Now this part is ok but i need to zoomin to the point more.How can i do that???

   Dim graphic As New Graphic() With
                {
                    .Geometry = mercator.FromGeographic(New MapPoint(Convert.ToDouble(gpsNMEASentence(4)), Convert.ToDouble(gpsNMEASentence(2)))),
                    .Symbol = TryCast(LayoutRoot.Resources(colourstyle), Symbol)
                }
            Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)
            graphicsLayer.Graphics.Clear()
            graphic.Attributes.Add("Zen Factor", 7)
            graphic.Attributes.Add("Zodiac Sign", Status)
            graphicsLayer.Graphics.Add(graphic)
            AddHandler graphic.MouseLeftButtonDown, AddressOf Graphic_MouseEnter
            AddHandler graphic.MouseLeave, AddressOf Graphic_Mouseleave

            Dim envelope As ESRI.ArcGIS.Client.Geometry.Envelope = New ESRI.ArcGIS.Client.Geometry.Envelope(Convert.ToDouble(gpsNMEASentence(4)) - 100, Convert.ToDouble(gpsNMEASentence(2)) - 100, Convert.ToDouble(gpsNMEASentence(4)) + 100, Convert.ToDouble(gpsNMEASentence(2)) + 100)
            MyMap.ZoomTo(envelope)
0 Kudos
JoeHershman
MVP Regular Contributor
MyMap.ZoomToResolution(MyMap.Resolution / MyMap.ZoomFactor, mapPoint);
Thanks,
-Joe
0 Kudos
JulieBiju
Occasional Contributor
I did in the following way..It is working perfect

 ZoomToResolution(MyMap, 0.00551220549302222, New MapPoint(Convert.ToDouble(gpsNMEASentence(4)), Convert.ToDouble(gpsNMEASentence(2))))


   Private Sub ZoomToResolution(map As Map, resolution As Double, center As MapPoint)         'Workaround for Map.ZoomToResolution         Dim halfWidth As Double = resolution * MyMap.ActualWidth / 2         Dim halfHeight As Double = resolution * MyMap.ActualHeight / 2         Dim newExtent As New Envelope(center.X - halfWidth, center.Y - halfHeight, center.X + halfWidth, center.Y + halfHeight)         Map.ZoomTo(newExtent)     End Sub
0 Kudos