I'm trying to create an Add-In for this tool:
Link to Google Maps and Bing from MXD (Streetview and Bird's Eye supported)
I'm not receiving an error however my browser is not opening after I select either the Yes or No option in the messagebox. Here is the code.
I'm using Windows7 and IE8.
Public Class StreetViewBirdsEye
Inherits ESRI.ArcGIS.Desktop.AddIns.Tool
Const SW_SHOWMAXIMIZED = 3
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWDEFAULT = 10
Const SW_SHOWMINNOACTIVE = 7
Const 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
Public Sub New()
End Sub
Protected Overrides Sub OnUpdate()
Enabled = My.ArcMap.Application IsNot Nothing
End Sub
Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs)
MyBase.OnMouseDown(arg)
Try
My.ArcMap.Application.CurrentTool = Nothing
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pPoint As IPoint
Dim pSpatialReferenceFactory As ISpatialReferenceFactory
Dim pSpatialReference As ISpatialReference
Dim pApp As IMxApplication
pApp = CType(Hook, IApplication)
pMxDoc = CType(pApp.Document, IMxDocument)
pMap = pMxDoc.FocusMap
pApp = My.ArcMap.Application
pSpatialReferenceFactory = New SpatialReferenceEnvironment
pSpatialReference = pSpatialReferenceFactory. _
CreateGeographicCoordinateSystem(esriSRGeoCSType.esriSRGeoCS_WGS1984)
' convert mouse click to map units
pPoint = pApp.Display.DisplayTransformation.ToMapPoint(arg.X, arg.Y)
pPoint.SpatialReference = pMap.SpatialReference
If pPoint.SpatialReference.Name <> pSpatialReference.Name Then
pPoint.Project(pSpatialReference)
End If
Dim URLstr As String = Nothing
Dim returnLong As Long
'more info on google map URL query string request setting parameters:
'http://mapki.com/index.php?title=Google_Map_Parameters
Dim webmapchoice
webmapchoice = MsgBox("View this location in a browser?" & vbCrLf & vbCrLf _
& "Click YES for BING Bird's Eye" _
& vbCrLf & "Click NO for GOOGLE Street View" _
& vbCrLf & vbCrLf & "or CANCEL to exit.", vbYesNoCancel, "Web Mapping Analysis")
Select Case webmapchoice
Case 6
URLstr = "http://www.bing.com/maps/default.aspx?v=2&cp=" & _
pPoint.Y & "~" & pPoint.X & "&lvl=/8&style=o&dir=0"
' goto http://www.bing.com/community/blogs/maps/archive/2008/04/10/live-search-maps-api.aspx
' for additional parameters to enter for Bing Maps
Case 7
URLstr = "http://www.google.com/maps? ie=UTF8&layer=c&cbll=" & _
pPoint.Y & "," & pPoint.X & "&cbp=11,0,,0,5&ll=" & pPoint.Y _
& "," & pPoint.X & "&z=16"
Case 2
Exit Sub
End Select
'Use one of the constants as the window state parameter
returnLong = OpenLocation(URLstr, SW_SHOWNORMAL)
Catch ex As Exception
MessageBox.Show("Caught an unspecified error in the calling code: " & vbCrLf & ex.ToString)
End Try
End Sub
Private Function OpenLocation(ByVal URL As String, ByVal WinState As Long) As Long
Try
'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)
Catch ex As Exception
MessageBox.Show("Caught an unspecified error in the calling code: " & vbCrLf & ex.ToString)
End Try
End Function
End Class
Maybe this is not coded to open IE8?
Any ideas of what needs updated?