Show All
Show All
Working with Pushpins in the MapPoint object model
You can create Pushpin objects by calling the AddPushpin method. The AddPushpin method takes a Location object and an optional name. If you do not provide the name, then the location name is used. If the location does not have a name, then it defaults to "Untitled."
The following code example creates a Pushpin object at the found location of Helena, Montana.
Sub HelenaMontanaPP()
Dim oMap As MapPoint.Map
Set oMap = GetObject(, "MapPoint.Application").ActiveMap
oMap.AddPushpin oMap.FindResults( _
"Helena, Montana")(1), "Helena"
End Sub
Pushpins can also be created by importing or linking to data sources in other programs. To learn about importing and linking to data, see Working with data maps in the MapPoint object model.
Pushpin sets
Whether Pushpins are created by the user or by calling the AddPushpin method, they are added to the default Pushpin set named My Pushpins. A Pushpin set is a DataSet object that doesn't have imported or linked fields. DataSet objects, including Pushpin sets, are listed in the map legend and are accessible in the object model through the DataSets collection.
You can create new Pushpin sets by calling the AddPushpinSet method. To add Pushpins to the new set, first create them with the AddPushpin method, and then move them to the new set using the MoveTo method. Pushpins created by the AddPushpin method can be moved to other Pushpin sets but not to imported or linked sets. If you attempt to move a Pushpin to an incompatible data set, the MoveTo method returns False. If the move was successful, it returns True. A Pushpin can belong to only one set at a time.
Sub NewPushpinSet()
Dim oMap As MapPoint.Map
Set oMap = GetObject(, "MapPoint.Application").ActiveMap
Dim oPPSet As MapPoint.DataSet
Dim oPin As MapPoint.Pushpin
Dim oDS As MapPoint.DataSets
Set oPin = oMap.AddPushpin(oMap.FindResults( _
"Space Needle, Seattle, WA")(1))
Set oDS = oMap.DataSets
Set oPPSet = oMap.DataSets.AddPushpinSet("Deliveries")
oPin.MoveTo oPPSet
End Sub
When this code runs, you get two Pushpin sets: the My Pushpins set created automatically by the AddPushpin method and the Deliveries set created by the call to the AddPushpinSet method.
You can remove Pushpin sets the same way that you remove any other set by using the Delete method on the DataSet object. For more information, see About mapping data by using the MapPoint object model.
Finding Pushpins
You can find Pushpins by using any of the Find methods (except the FindAddressResults method—Pushpins are never addresses), the FindPushpin method, or by querying a Recordset object from a Pushpin data set. For more information, see Working with data sets in the MapPoint object model.
A Pushpin is only returned from a Find method if there is an exact match. The FindPushpin method returns a single Pushpin object, and the FindResults method also returns Location objects that match the search text. To find multiple Pushpins with similar names, use the FindResults method.
Sub MarkASpot()
Dim oMap As MapPoint.Map
Set oMap = GetObject(, "MapPoint.Application").ActiveMap
Dim oLoc As MapPoint.Location
Set oLoc = oMap.FindResults("Space Needle, Seattle, WA")(1)
oMap.AddPushpin oLoc, "Lunch Spot"
oMap.FindPushpin("Lunch Spot").Highlight = True
End Sub
Moving Pushpins
To move a Pushpin to another location, set the Location property of the Pushpin object.
Sub CompanyHeadquaters()
Dim oMap As MapPoint.Map
Dim oPin As MapPoint.Pushpin
Set oMap = GetObject(, "MapPoint.Application").ActiveMap
Set oPin = oMap.AddPushpin(oMap.FindResults( _
"Albuquerque, NM")(1))
oPin.Name = "Headquaters"
oPin.BalloonState = geoDisplayName
MsgBox _
"The Pushpin will be moved to the new HQ after this message."
Set oPin.Location = oMap.FindResults("Seattle, WA")(1)
End Sub
Pushpin properties
Properties that appear in the user interface can also be automated, such as the Name, Hyperlink, Note, Highlight, and BalloonState properties. For more information, see the Pushpin object reference topic. Unlike locations, all Pushpins can be highlighted.
Sub MarkAPlace()
Dim oMap As MapPoint.Map
Set oMap = GetObject(, "MapPoint.Application").ActiveMap
Dim oLoc As MapPoint.Location
Set oLoc = oMap.FindResults("Space Needle, Seattle, WA")(1)
oLoc.GoTo
oMap.AddPushpin(oLoc, "Lunch Spot").Highlight = True
oMap.FindPushpin("Lunch Spot").BalloonState = _
geoDisplayBalloon
End Sub
Pushpin data fields
Pushpin objects are members of DataSet objects, which are listed in the map legend in the user interface. DataSet objects can be imported or linked or created by placing Pushpins on the map. The My Pushpins set is a DataSet object.
If a Pushpin is in an imported or linked set, then it has associated Field objects. Field objects can be displayed in the Pushpin note by using the SetFieldsVisibleInBalloon property.
The following code displays field names and values for any Pushpin:
Note This sample assumes that there is a MyData.mdb file with an Employees table. For this code to work properly, the table must be imported as a Pushpin map and there must be a record with the name John Smith. You can modify the names and paths in this code to make it work with your data.
Sub PushpinData()
Dim oMap As MapPoint.Map
Set oMap = GetObject(, "MapPoint.Application").ActiveMap
Dim strDB As String
strDB = App & _
"\MyData.mdb!Employees"
' Add all local addresses as waypoints
Dim dsEmps As MapPoint.DataSet
Set dsEmps = oMap.DataSets.ImportData(strDB)
' Find a particular record
Dim oPin As MapPoint.Pushpin
Set oPin = oMap.FindPushpin("John Smith")
' Display all the fields for that record
Dim oRS As MapPoint.Recordset
Set oRS = oPin.Parent.QueryAllRecords
oRS.MoveToPushpin oPin
Dim oFld As MapPoint.Field
For Each oFld In oRS.Fields
MsgBox oFld.Name & ": """ & oFld.Value & """"
Next
End Sub
For more information about DataSet and Recordset objects, see Working with data sets in the MapPoint object model.
Pushpin symbols
Pushpins are displayed on the map using a Symbol object, such as the default black Pushpin symbol. Each DataSet object has a default Pushpin symbol, which can be modified by setting the Symbol property on the DataSet object. Symbols for individual Pushpins can be set with the Symbol property of the Pushpin object. The Symbol property is set by using the ID property of the Symbol object. Because the ID property is the default value of the Symbol object, you merely pass the Symbol object itself. Symbol objects can be accessed by using the Symbols collection. The following example shows how to set the symbol for a Pushpin.
Sub SetPPSymbol()
Dim oMap As MapPoint.Map
Set oMap = GetObject(, "MapPoint.Application").ActiveMap
Dim oPin As MapPoint.Pushpin
Set oPin = oMap.AddPushpin(oMap.FindResults(_
"TF Green Airport, RI")(1))
oPin.Highlight = True
oPin.Symbol = oMap.Symbols("Purple Airplane (Airport)")
End Sub
Microsoft MapPoint has a set of 336 standard symbols, but new symbols can be added by calling the Add method on the Symbols collection. This example creates a custom Pushpin symbol and places it on the map.
Sub CustomPPSymbol()
Dim oMap As MapPoint.Map
Set oMap = GetObject(, "MapPoint.Application").ActiveMap
Dim oPin As MapPoint.Pushpin
Dim strPath As String
strPath = oMap.Parent.Path & "\Samples\Airport.bmp"
Dim oSymbol As MapPoint.Symbol
Set oSymbol = oMap.Symbols.Add(strPath)
Set oPin = oMap.AddPushpin(oMap.FindResults(_
"TF Green Airport, RI")(1))
oPin.Highlight = True
oPin.Symbol = oSymbol
End Sub
More information
Working with locations and finding places and address in the MapPoint object model
About the MapPoint object model
What's new for MapPoint 2006 developers
Getting started using the MapPoint object model
Getting started using the MapPoint Control
About mapping data by using the MapPoint object model