Register  |  Login   Search
ThinkGeo - GPS Tracking and Mapping Solutions  |  Home  |  Cygnus Track  |  Developer Community
 
LivePerson Chat

Discussion Forums

The online community for users of Map Suite GIS components

RSS Feed Available AddThis - Bookmarking and Sharing Button Printer Friendly

 NextNext

How To Use the Map Rotation Feature in Map Suite 2.53.5

Posted by ThinkGeo on 11-13-2008 12:48 PM

After hearing many requests for Map Rotation functionality from the Map Suite user community, we decided to add that feature to Map Suite starting with version 2.53. We approached the goal of having the entire map rotate from the center of its current extent at will through a Projection class called Rotated. In other words, from the developer's perspective, Map Rotation is simply applying a Projection class to all the Layers and MapShapes, and letting Map Suite take care of everything else automatically.

Note: For the purposes of this article we have used the Map Suite Desktop Edition to demonstrate Map Rotation, but please note that Map Rotation functionality is also available in the Map Suite Web and Engine editions.

Applying Map Rotation

For the developer, applying Map Rotation is very straightforward. Essentially, all vector data (Layers and MapShapes) need to have their projection property set to the projection class Rotated. But before we do that, we need to declare a form level variable for Rotated.

Private mRotated As New MapSuite.Geometry.Rotated()

We will use mRotated as the projection for all the Layers and MapShapes of the Map. It is very important that each time you add a new Layer or MapShape to the Map, you apply the Rotated projection to it. Otherwise, the Map Rotation will not apply to that object.

For a Layer, we add it to the Map the following way:

Dim Layer1 As New Layer("..\MyLayer.shp", mRotated, False)

For a MapShape, we simply set the Projection property to Rotated:

PointMapShape1.Projection = mRotated

Now, with all the Layers and MapShapes having their Projection property set to Rotated, we are ready to have the Map Rotation take effect. Each time the map has to rotate, we use the SetAngle method of Rotated.

Map1.CurrentExtent = mRotated.SetAngle(90, Map1.CurrentExtent)

You can rotate the Map from 0 to 360 degrees counterclockwise by using positive values, or clockwise by using negative values. So for example, 90 and -270 will have the same effect.

If you want to rotate incrementally, for example by 10 degrees at a time, you can use the GetAngle property and add 10 as the Angle parameter of SetAngle. Here we are rotating the map by increment of 10 degrees counterclockwise.

Map1.CurrentExtent = mRotated.SetAngle(mRotated.GetAngle + 10, Map1.CurrentExtent)

Keeping the Bearings

As the Map rotates, it is important to keep bearings and to know where the North is. That is why drawing a North Arrow that always points to the north helps prevent you from getting disoriented. Below is a trick that can be used to draw a bitmap of a North Arrow that always points to the North.

First, declare a form level variable for the North Arrow bitmap. Then, in the AfterMapDraw event of the Map, you can write the logic for the rotation:

Private Sub Map1_AfterMapDraw(ByVal g As System.Drawing.Graphics) Handles Map1.AfterMapDraw
        Dim Matrix As New Matrix
        Dim ImageX, ImageY, ImageWidth, ImageHeight As Integer
        ImageX = 30 : ImageY = 30 : ImageWidth = 56 : ImageHeight = 69
        Dim pt As New PointF(ImageX + (ImageWidth / 2), ImageY + (ImageHeight / 2))
        Matrix.RotateAt(CSng(-mRotated.GetAngle), pt)
        g.Transform = Matrix
        g.DrawImage(mNorthArrowBitmap, ImageX, ImageY, ImageWidth, ImageHeight)
        g.Dispose()
End Sub

Figure 1
Fig 1: Street Map with Angle set at 0.

Figure 2
Fig 2: Street Map with Angle set at 132. See how the North Arrow tilted to point to the North.

In the included demo application, we show you two ways to rotate the map. One is by using a Button control where the angle of Map is changed, by a user defined increment, clockwise and counterclockwise. The other method is by using a Roll control that serves as a compass, where you can set the angle of the map using the mouse. Download the demo application to see both methods in action. (Please note that the demo requires the free evaluation of the Map Suite Desktop GIS .NET control, available here.)

Another important thing to take into account is the coordinates we get on the Map by rotating it. If we always want to have the real coordinates and not the coordinates from the rotation, we are going to use the ProjectPointBack method of Rotated. The code below will show the real coordinates from the MouseMove event on the status bar:

Private Sub Map1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Map1.MouseMove
        Dim RotWorldPointR As PointR = Map1.ToWorldCoordinate(e.X, e.Y)
        Dim RealWorldPointR As PointR = mRotated.ProjectPointBack(RotWorldPointR.X, RotWorldPointR.Y)
        StatusBar1.Panels(0).Text = "X: " & RealWorldPointR.X & "  Y: " & RealWorldPointR.Y
        StatusBar1.Panels(1).Text = DecimalDegrees.DecimalDegreesToDMS(RealWorldPointR)
End Sub

Ruminations

Taking the idea of Map Rotation further, nothing stops us from displaying the world with the North down, the South up, the East to the left and the West to the right by applying a 180 angle to the Rotated projection:

Figure 3
Fig 3. The World with the South on top. This map was created by applying an angle of 180 degrees to a few of the ShapeFiles that come with the Render World product.

The map shown above will probably shock many of us, but although this is an unconventional view of the world, it is completely accurate scientifically and it is not breaking any cartographic rules.

Below are the scientific definitions of the four cardinal directions:

East: The direction toward which the Earth rotates about its axis (therefore the direction from which the Sun appears to rise)

West: The direction opposite to that of the Earth's rotation axis (therefore the direction towards which the Sun appears to set)

South: The direction along the earth's surface toward the pole that is on one's right at the Equator when facing the direction toward which the Earth rotates about its axis (East).

North: The direction along the earth's surface toward the pole that is on one's left at the Equator when facing the direction toward which the Earth rotates about its axis (East).

So according to those definitions, there is no reason why the North must be placed on top. The reason it seems odd to many of us is due to our own western bias, where North has always historically been used as a fundamental direction, placing Europe on the top of the map. But this is completely arbitrary.

Even the magnetic north, which is the direction along the earth's surface in which horizontal magnetic field strength has its most positive value, is a very transitional thing. Due to the “flipping” of the magnetic poles, perhaps in a few thousand years, the magnetic pole will later lie in the southern hemisphere.

Conclusion

Map Suite developers can now take advantage of Map Rotation to add a totally new dimension of map display to their GIS applications. Currently, Map Rotation applies only to vector data, Layers and MapShapes, not ImageLayers or GRIDs. We are aware that this is a limitation. The next major release of Map Suite, version 3.0, is planned to support Map Rotation for any data, vector or raster image.

Downloads

Have Questions?

Do you have any questions or comments about this article? If so, feel free post your questions on the Map Suite Discussion Forums or leave feedback at the ThinkGeo Blog.

Additional Resources

About the Author

Val Guillou is a GIS analyst and developer at ThinkGeo, a software company specializing in geospatial software with an emphasis on software development tools and GPS tracking solutions.

0 Comments

Active Forums 4.1