PDA

View Full Version : How to display countries and borders only, with VBA



3oomin3
11-06-2012, 10:31 AM
Hi All, I am new and just joined this great forum. I need some help with my VBA code. I can't figure out how modify the map so that when I plot data on it, there are only countries and borders displayed ( as if you would clear all in map settings and only show Boundaries where only "Country" checked in Symbols and Labels). Is this possible to do with VBA?

thanks for your help

Eric Frost
11-06-2012, 11:07 AM
First -- Sincere Apologies about deleting your post and banning you earlier. Somehow it got mixed up with spam and/or I wasn't careful when pruning spam this morning.

Two -- I did this just recently for the State Identification Game, I pasted the code I used below, hopefully you can use it as an example:

http://www.mapforums.com/state-identification-game-using-mappoint-excel-22444.html



Private Sub TurnOffAllLabels()
Dim MF As Object
For Each MF In MAP.MapFeatures
If Right(MF.Name, 6) = "Labels" Or MF.Name = "Populated Places - Town/Other Place (0 - 99,999) - Symbols" Then MF.DetailLevel = 3
Next
End Sub

Eric Frost
11-06-2012, 11:09 AM
Also, Richard Marsden wrote an article on this topic when MapPoint 2010 came out --

Using the New MapFeatures Collection and MapFeature Objects in MapPoint 2010 - MapPoint Articles - MP2K Magazine (http://www.mp2kmag.com/a158--mapfeatures.mappoint.html)

3oomin3
11-13-2012, 08:56 AM
Eric, should this work with Mappoint 2011 ( the version I am using)?

Eric Frost
11-13-2012, 09:19 AM
Yes, with all versions 2010+

Let us know how it goes and if you get stuck!

3oomin3
11-13-2012, 01:34 PM
Eric, I got stuck. Very new to mappoint. Here is my code. Sheet1 has countries in column C and values in column D like below. It generates a gif with a map of Europe. What I wan to achieve is have no cities in the gif. I have tried to apply your code but with no success. Please let me know if you can help.



Country
Amount


Albania
-


Azerbaijan
-


Belarus
0


Bulgaria
20


Croatia
16


Czech Republic
24


Estonia
(0)


FYROM
-


Georgia
0


Hungary
56


Iceland
(0)


Kazakhstan
(57)


Latvia
20


Poland
(36)


Romania
18


Russia
346


Serbia
(0)


Slovak Republic
52



Slovenia
7


Turkey
632


Ukraine
143


Lithuania
7







Option Explicit
' The purpose of this VBA code is to show how to control MapPoint from Excel VBA
' In tools->preferences, click on MapPoint control

Global MPApp As Object ' MapPoint.Application
Global OlApp As Object ' Outlook.Application

Sub InitialiseMapPoint()

If MPApp Is Nothing Then Set MPApp = CreateObject("MapPoint.Application") 'New MapPoint.Application
'If OlApp Is Nothing Then Set OlApp = CreateObject("Outlook.Application") 'New MapPoint.Application

MPApp.Visible = True ' Make the application window visible on screen
'MPApp.UserControl = True ' continue running until user closes


End Sub
Sub GenerateEurope()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim i, j, c As Long

Call InitialiseMapPoint

' large map
MPApp.Height = 1050
MPApp.Width = 1250

Dim objLoc As Object ' MapPoint.Location
Set objLoc = MPApp.ActiveMap.getLocation(53, 9, 0)
objLoc.Goto

' object for MapPoint
Dim objDataset As Object
Dim objDatasets As Object
Dim objDataMap As Object ' MapPoint.DataMap
Dim objField As Object ' MapPoint.Field

Dim regionName As String

Dim rangeMinMax(1 To 3) As Variant, nameMinMax(1 To 3) As String


nameMinMax(1) = "High"
nameMinMax(2) = "Medium"
nameMinMax(3) = "Low"

' objects for MS Outlook
'Dim olMailItem As Object ' Outlook.MailItem

Dim CharCol As String

Call MPApp.ActiveMap.BasicRenderingOnly ' speed up
MPApp.PaneState = 3 ' geoPaneNone - no help pane on the left
MPApp.ActiveMap.Projection = 1 ' geoFlatViewWhenZoomedOut meaning Miller Cylindrical, not 0 = geoGlobeViewWhenZoomedOut

Set objDatasets = MPApp.ActiveMap.DataSets

' this will import the data into a map; we could just as well use LinkData
Set objDataset = objDatasets.ImportData( _
DataSourceMoniker:="i:\tmp\Mappoint Example.xls!Sheet1!C9:D31")
'Call objDataset.ZoomTo ' Zoom to the data
MPApp.ActiveMap.MapStyle = 4 ' geoMapStyleData

'For i = 1 To 1 'the risk measures we want to plot

'Set objField = objDataset.Fields(Sheets("ExampleData").Cells(9, 3 + i).Value) ' the header

'CharCol = Chr(67 + i) ' The letter for the column

rangeMinMax(1) = Application.WorksheetFunction.Max( _
Application.WorksheetFunction.Max(Sheets("Sheet1").Range(CharCol & "10:" & CharCol & "128")), _
-Application.WorksheetFunction.Min(Sheets("Sheet1").Range(CharCol & "10:" & CharCol & "128")))
rangeMinMax(1) = rangeMinMax(3)

'
Set objDataMap = objDataset.DisplayDataMap(DataMapType:=1, _
DataRangeType:=1, DataRangeOrder:=2, CombineDataBy:=0, _
ColorScheme:=13, ArrayOfCustomValues:=rangeMinMax, ArrayOfCustomNames:=nameMinMax)


Call MPApp.ActiveMap.DefaultRendering


Call MPApp.ActiveMap.SaveAs(Filename:="I:\tmp\map1.htm", saveformat:=2, addtorecentfiles:=False)
MPApp.ActiveMap.Saved = True ' don't prompt user to save
MPApp.Quit
Set MPApp = Nothing
Set OlApp = Nothing

End Sub

Eric Frost
11-16-2012, 08:08 AM
I'd be glad to help!

Where are you stuck or what do you want help with?

Eric

3oomin3
11-19-2012, 03:22 PM
I want to remove cities after I zoom to data. So around "MPApp.ActiveMap.MapStyle = 4 ' geoMapStyleData"
With the code you gave me above, how would I modify it to remove cities before it saves an image?

Eric Frost
11-20-2012, 09:00 AM
Write a little sub to loop over all the MapFeatures --



Dim MF As Object
For Each MF In MAP.MapFeatures
Debug.Print MF.Name
'If Right(MF.Name, 6) = "Labels" Or MF.Name = "Populated Places - Town/Other Place (0 - 99,999) - Symbols" Then MF.DetailLevel = 3
Next


Then, once you have the exact name of the MapFeature you want to modify, set the DetailLevel.

The article has more detailed instructions.
Eric