4

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?

3 Answers 3

3

if you are interested I have posted ArcGIS desktop Street View & Bird's Eye AddIn for 10 & 10.1 http://resources.arcgis.com/gallery/file/arcobjects-net-api/details?entryID=48F2BB6C-1422-2418-8822-C06E828584E8

2
  • Bird Eye no longer works. The window pops up, but is always blank.
    – MjonesGEO
    Commented Apr 16, 2014 at 18:25
  • I haven't problem: try and see if you have a firewall lock. See in source code request to Bing for details
    – nicogis
    Commented May 9, 2014 at 9:44
3

I updated the function that finds the default browser. Here is the working code.

 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

            Process.Start(FindDefaultBrowser, URLstr)

            Catch ex As Exception
                MessageBox.Show("Caught an unspecified error in the calling code: " & vbCrLf & ex.ToString)
            End Try

    End Sub

    Private Function FindDefaultBrowser() As String

        Try
            'Find default browser
            Dim browser As String = [String].Empty
            Dim key As Microsoft.Win32.RegistryKey = Nothing
            Dim Quote As String = Chr(34)

            key = My.Computer.Registry.ClassesRoot.OpenSubKey("HTTP\shell\open\command", False)

            ' trim off quotes
            browser = key.GetValue(Nothing).ToString().ToLower().Replace(Quote, "")
            If Not browser.EndsWith("exe") Then
                ' get rid of everything after the 'exe'
                browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4)

            End If

            FindDefaultBrowser = browser

            Return FindDefaultBrowser

        Catch ex As Exception
            FindDefaultBrowser = Nothing
            MessageBox.Show("Caught an unspecified error in the calling code: " & vbCrLf & ex.ToString)
        End Try

    End Function
2

Here is a sample since my rep is too low to post more. I created from various forums and tools to be used as a python addin buttons and arcmap 10.1.

  • Also converts any projection to WGS 1984 so it can be used for Google, Bing, and other maps.
    import arcpy
    import pythonaddins
    import webbrowser
    import threading

    class YahooMaps(object):
        """Implementation for Google_addin.button (Button)"""
        def __init__(self):
            self.enabled = True
            self.checked = False
        def onClick(self):
            mxd = arcpy.mapping.MapDocument("Current")
            dataframe_string = mxd.activeView
            dataframe= arcpy.mapping.ListDataFrames(mxd,dataframe_string)[0]
            # reference the dataframe's spatial reference
            oldspatialref = dataframe.spatialReference
            # change the dataframe's spatial reference to grab later the right coordinates (in WGS 84)
            spatialref = arcpy.SpatialReference(4326)
            dataframe.spatialReference = spatialref
            # calculate the dataframe's midpoint to pass this coordinate later on to Google Maps
            x = (dataframe.extent.XMin + dataframe.extent.XMax)/2
            y = (dataframe.extent.YMin + dataframe.extent.YMax)/2
            # set your dataframs spatial reference to the olde one back
            dataframe.spatialReference = oldspatialref
            # write the the link with x,y and pass it on to the webbrowser
            link = "http://maps.yahoo.com/#mvt=s&lat="
            thelink = link + str(y) + "&lon=" + str(x) + "&zoom=18"
            threading.Thread(target=webbrowser.open_new_tab, args=(thelink,)).start()
            pass

    class MashUp(object):
        """Implementation for Google_addin.button (Button)"""
        def __init__(self):
            self.enabled = True
            self.checked = False
        def onClick(self):
            mxd = arcpy.mapping.MapDocument("Current")
            dataframe_string = mxd.activeView
            dataframe= arcpy.mapping.ListDataFrames(mxd,dataframe_string)[0]
            # reference the dataframe's spatial reference
            oldspatialref = dataframe.spatialReference
            # change the dataframe's spatial reference to grab later the right coordinates (in WGS 84)
            spatialref = arcpy.SpatialReference(4326)
            dataframe.spatialReference = spatialref
            # calculate the dataframe's midpoint to pass this coordinate later on to Google Maps
            x = (dataframe.extent.XMin + dataframe.extent.XMax)/2
            y = (dataframe.extent.YMin + dataframe.extent.YMax)/2
            # set your dataframs spatial reference to the olde one back
            dataframe.spatialReference = oldspatialref
            # write the the link with x,y and pass it on to the webbrowser
            link = "http://data.mapchannels.com/mm/dual2/map.htm?lng="
            thelink = link + str(x) + "&lat=" + str(y) + "z=15&gm=1&ve=3&gc=0&xb="
            + str(x) + "&yb=" + str(y) + "&zb=1&db=0&bar=1&mw=1&sv=1&svb=0" 
            threading.Thread(target=webbrowser.open_new_tab, args=(thelink,)).start()
            pass

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.