MapPoint Spinning Globe Sample

 

Microsoft Corporation

July 2004

Applies to:
   Microsoft MapPoint 2002
   Microsoft MapPoint 2004

Summary: Learn how to manipulate the navigation, map style, map font size, and view of a map programmatically through the MapPoint ActiveX control. (6 printed pages)

Click here to download the code sample for this article.

Contents

Introduction
Code for the Spinning Globe Sample

Introduction

This download and code sample illustrate how to manipulate the navigation, map style, map font size, and view of a map programmatically through the MapPoint ActiveX Control. When you develop custom applications with Microsoft MapPoint, you might want to give your users the ability to navigate the map or change the way it looks. This simple Microsoft Visual Basic project demonstrates the objects, methods, and properties that enable this functionality.

The download consists of Visual Basic project files. To run the sample, open the Project1.vbp file in Visual Basic 6.0 and run the project.

When you first run the sample, the globe spins from left to right. You can use the buttons and fields on the left side of the application window to change the following map view functions:

  • Spin direction
  • Zoom level
  • Rotation status (whether the map is spinning)
  • Globe view or flat map view at higher altitudes
  • Exact latitude, longitude, and altitude

Other map view settings, such as map style and map font size, have been set in the code; that is, there are no user interface elements that the end user can interact with to change these settings in the application's current design.

**Note   **When you click the East button while viewing the map as a globe, the globe spins from right to left. While it may appear at first as though the globe is spinning to the west, the map view is actually moving from the left to the right, or in the east direction. The same applies when you click the West button while viewing the map as a globe.

Code for the Spinning Globe Sample

The Spinning Globe sample application runs on the following code.

[Visual Basic 6.0]
Public SpinDirection As Integer
Public KeepMoving As Boolean

Private Sub Form_Load()
    Dim objMap As MapPointCtl.Map
    Dim objLoc As MapPointCtl.Location
    
    KeepMoving = True
    
    ' Open a North American map.
    Me.MappointControl1.NewMap geoMapNorthAmerica
    
    ' Set the map object to the current map.
    Set objMap = MappointControl1.ActiveMap
    ' Set the location to Latitude 15.0000, Longitude 0.0000, Altitude 35,000 miles
    Set objLoc = objMap.GetLocation(15, 0, 35000)
    ' Move to the location settings.
    objLoc.GoTo
 
    ' Set the projection so that you will see a globe instead
    ' of a flat map at higher altitudes.
    objMap.Projection = geoGlobeViewWhenZoomedOut
    ' Change the map style to the Political style
    objMap.MapStyle = geoMapStylePolitical
    ' Set the font to the smallest size
    objMap.MapFont = geoMapFontSmallest
    
    ' Set the starting spin direction to the west.
    SpinDirection = geoWest

End Sub

Private Sub Form_Unload(Cancel As Integer)
    MappointControl1.ActiveMap.Saved = True
End Sub

Private Sub Timer1_Timer()
    Dim objMap As MapPointCtl.Map
    Set objMap = MappointControl1.ActiveMap
    
    If KeepMoving = True Then
        ' Pan (spin) the map in the direction specified
        ' and in steps expressed as a fraction of the screen width or height.
        objMap.Pan SpinDirection, 0.01
    End If
    
    MappointControl1.ActiveMap.Saved = True
End Sub

Private Sub Command1_Click()
    ' Spin to the west.
    SpinDirection = geoWest

End Sub

Private Sub Command2_Click()
    ' Spin to the east.
    SpinDirection = geoEast

End Sub

Private Sub Command3_Click()
    ' Go north to the top of the earth.
    ' Once you go all the way to the North Pole it will stop.
    SpinDirection = geoNorth

End Sub

Private Sub Command4_Click()
    ' Go south to the bottom of the earth.
    ' Once you go all the way to the South Pole it will stop.
    SpinDirection = geoSouth

End Sub

Private Sub Command5_Click()
    ' Move out from the earth.
    Dim objMap As MapPointCtl.Map
    Set objMap = MappointControl1.ActiveMap
    objMap.Altitude = objMap.Altitude + 500
    
End Sub

Private Sub Command6_Click()
    ' Move in to the earth.
    Dim objMap As MapPointCtl.Map
    Set objMap = MappointControl1.ActiveMap
    objMap.Altitude = objMap.Altitude - 500

End Sub

Private Sub Command7_Click()
    If KeepMoving = True Then
        KeepMoving = False
        Command7.Caption = "Rotate"
    Else
        KeepMoving = True
        Command7.Caption = "Stop"
    End If
    
End Sub

Private Sub Command8_Click()
    Dim objMap As MapPointCtl.Map
    Dim objLoc As MapPointCtl.Location
    Dim Latitude, Longitude, Altitude As Long

    ' Stop the rotation in preparation for the goto.
    KeepMoving = False
    Command7.Caption = "Rotate"
    
    ' Set the map object to the current map
    Set objMap = MappointControl1.ActiveMap
    
    ' Set the location latitude, longitude & altitude.
    '  to values entered in Text1, Text2 & Text3
    Latitude = Val(Text1.Text)
    Longitude = Val(Text2.Text)
    Altitude = Val(Text3.Text)
    
    ' Check to make sure the latitude is within allowable range.
    If Latitude < -90 Or Latitude > 90 Then
        MsgBox ("Latitude outside of allowable range!")
        Exit Sub
    End If
        
    ' Check to make sure the longitude is within allowable range.
    If Longitude < -180 Or Longitude > 180 Then
        MsgBox ("Longitude outside of allowable range!")
        Exit Sub
    End If
        
    ' Check to make sure the altitude is within allowable range.
    If Altitude < 1 Or Altitude > 50000 Then
        MsgBox ("Altitude outside of allowable range!")
        Exit Sub
    End If
        
    Set objLoc = objMap.GetLocation(Latitude, Longitude, Altitude)
    ' Move to the location settings.
    objLoc.GoTo

End Sub

Private Sub Command9_Click()
    Dim objMap As MapPointCtl.Map
    
    ' Set the map object to the current map.
    Set objMap = MappointControl1.ActiveMap
    
    If Command9.Caption = "Flat" Then
        ' Set the projection so that you will see a flat map instead
        ' of a globe at higher altitudes.
        objMap.Projection = geoFlatViewWhenZoomedOut
        Command9.Caption = "Globe"
    Else
        ' Set the projection so that you will see a globe instead
        ' of a flat map at higher altitudes.
        objMap.Projection = geoGlobeViewWhenZoomedOut
        Command9.Caption = "Flat"
    End If
    
End Sub