Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

Thanks to Bert Granberg who originally posted this on the Utah GIS Portal.

I only made minor changes and added a few different Google/Bing choices.
Nick Harrison. Dec 2009
Part I. Paste code into VBA Editor
1) From the ArcMap menu, navigate to Tools --> Macros --> Visual Basic Editor
to open the
VBA editor
2) In the VBA Editor's Project Window, expand either the Normal (Normal.mxt)
or the
Project (YourMXDName.mxd) --> Arcmap Objects folder and double click on
ThisDocument
Note: If you want the code accessible in every MXD you open place the code
in the Normal.mxt;
If you only want it in a specific MXD then place it in the project.
3) Paste the code (below) in the window that opens and close the VBA editor.
4) Save your project
Part II. Create and configure custom ArcMap Tool
1) From the ArcMap menu, navigate to Tools -->Customize
2) Click the Commands tab.
3) Click the drop-down arrow on the Save in combo box, then change the
selected item so it is
either the Normal.MXD or the current name of your ArcMap project (ex.
Untitled.mxd) depending
on where you placed the code in part I.
4) Click [UIControls] in the Categories list. then Click the New UIControl
button.
5) Click the UIToolControl radio button and then click Create.
6) The name of the new tool appears in the Commands list. Single click the
newly created UIControl,
then click it again to activate in-place editing, then type a new name for
the control so it reads
Normal.GoogleMap_Link or Project.GoogleMap_Link depending on where you put
the code.
7) Click and drag the newly created UIControl and drop it on an ArcMap toolbar
or menu.
8) With the Customize dialog still open, on the toolbar or menu, right-click
the command to set its

image, caption, and other properties.


9) Save Project and start using the tool.
10) To change the specific Google/Bing parameters (i.e. Street View / Bird's
Eye, etc) edit the
code in the VBA Editorand change the URL String(s) in case 6 and/or 7.
Several options are
available in the code as comments. Or have a look at all the parameters
at:
http://mapki.com/index.php?title=Google_Map_Parameters
http://www.bing.com/community/blogs/maps/archive/2008/04/10/live-searchmaps-api.aspx
11) Optional Step - If you like this tool and use it a lot then I recommend
changing the behaviour
of the mouse wheel in ArcMap so that Roll up/down matches the behaviour of
Google/Bing.
By default, ArcMap is the oposite. To change this in ArcMap go to The
Tools menu / Options.
On the Genral tab set Mouse Wheel setting to "Zooms In"
-------------------------------------------------------------------------------Option Explicit
Const
Const
Const
Const
Const

SW_SHOWMAXIMIZED = 3
SW_SHOWMINIMIZED = 2
SW_SHOWDEFAULT = 10
SW_SHOWMINNOACTIVE = 7
SW_SHOWNORMAL = 1

Private Declare Function ShellExecute Lib "shell32.dll" _


Alias "ShellExecuteA" (ByVal hWnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Function OpenLocation(URL As String, WinState As Long) As Long
'PURPOSE: Opens default browser to display URL
'RETURNS: module handle to executed application or
'Error Code ( < 32) if there is an error
'can also be used to open any document associated with
'an application on the system (e.g., passing the name
'of a file with a .doc extension will open that file in Word)
Dim lHWnd As Long
Dim lAns As Long

lAns = ShellExecute(lHWnd, "open", URL, vbNullString, _


vbNullString, WinState)
OpenLocation = lAns
'ALTERNATIVE: if not interested in module handle or error
'code change return value to boolean; then the above line
'becomes:
'OpenLocation = (lAns > 32)
End Function
Private Function GoogleMap_Link_Message() As String
GoogleMap_Link_Message = "Link to Google or Bing Web Map"
End Function
Private Sub GoogleMap_Link_Mousedown(ByVal button As Long, ByVal shift _
As Long, ByVal x As Long, ByVal y As Long)
Dim
Dim
Dim
Dim
Dim
Dim

pMxDoc As IMxDocument
pApp As IMxApplication
pMap As IMap
pPoint As IPoint
pSpatialReferenceFactory As ISpatialReferenceFactory
pSpatialReference As ISpatialReference

Set pMxDoc = ThisDocument


Set pMap = pMxDoc.FocusMap
Set pApp = Application
Set pSpatialReferenceFactory = New SpatialReferenceEnvironment
Set pSpatialReference = pSpatialReferenceFactory. _
CreateGeographicCoordinateSystem(esriSRGeoCS_WGS1984)
' convert mouse click to map units
Set pPoint = pApp.Display.DisplayTransformation.ToMapPoint(x, y)
Set pPoint.SpatialReference = pMap.SpatialReference
If pPoint.SpatialReference.Name <> pSpatialReference.Name Then
pPoint.Project pSpatialReference
End If
Dim URLstr As String
Dim returnLong As Long
Dim webmapchoice
webmapchoice = MsgBox("Launch web map application?" & vbCrLf & vbCrLf _
& "Open Map at: " & Round(pPoint.y, 6) & ", " & Round(pPoint.x, 6) &
vbCrLf & vbCrLf _
& "Click YES for GOOGLE Maps" & vbCrLf _
& "Click NO for BING Maps" & vbCrLf & vbCrLf _
& "or CANCEL to exit.", vbYesNoCancel, "WEB RESOURCES")
Select Case webmapchoice

Case 6
'GOOGLE MAP - HYBRID
URLstr = "http://www.google.com/maps?ie=UTF8&ll=" _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) _
& "&z=17&t=h"
Case 7
'BING MAPS - HYBRID
URLstr = "http://www.bing.com/maps/default.aspx?v=2&cp=" _
& Round(pPoint.y, 6) & "~" & Round(pPoint.x, 6) _
& "&lvl=17&style=h"
Case 2
Exit Sub
End Select
'Use one of the constants as the window state parameter
returnLong = OpenLocation(URLstr, SW_SHOWNORMAL)
' URL CODE FOR OTHER POSSIBILITIES:
'more info on google map URL query string request setting parameters:
'http://mapki.com/index.php?title=Google_Map_Parameters
'more info on BING URL query string request setting parameters:
'http://www.bing.com/community/blogs/maps/archive/2008/04/10/live-searchmaps-api.aspx
'GOOGLE MAP - HYBRID
'URLstr = "http://www.google.com/maps?ie=UTF8&ll=" _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) _
& "&z=17&t=h"
'GOOGLE MAP - STREET VIEW
'URLstr = "http://www.google.com/maps?ie=UTF8&layer=c&cbll=" _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) &
"&cbp=1,0,,0,5&ll=" _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) & "&z=17"
'GOOGLE MAP - STREET VIEW WITH MAP - SPLIT SCREEN
'URLstr = "http://www.google.com/maps?ie=UTF8&layer=c&cbll=" _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) &
"&cbp=11,0,,0,5&ll=" _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) & "&t=h&z=17"
'GOOGLE MAP - STREET VIEW WITH MAP - LOWER RIGHT CORNER
'URLstr = "http://www.google.com/maps?ie=UTF8&layer=c&cbll=" _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) &
"&cbp=12,0,,0,5&ll=" _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) & "&t=h&z=17"
'BING MAPS - HYBRID
' URLstr = "http://www.bing.com/maps/default.aspx?v=2&cp=" _
& Round(pPoint.y, 6) & "~" & Round(pPoint.x, 6) _
& "&lvl=17&style=h"

'BING MAPS - Bird's Eye


'URLstr = "http://www.bing.com/maps/default.aspx?v=2&cp=" _
& Round(pPoint.y, 6) & "~" & Round(pPoint.x, 6) _
& "&style=o&dir=0"
End Sub
Private Sub GoogleMap_Link_Click()
End Sub
Private Function GoogleMap_Link_ToolTip() As String
GoogleMap_Link_ToolTip = "Google / Bing Map"
End Function

You might also like