Google Addin

4174
2
07-13-2015 08:35 AM
WesMiller
Regular Contributor III

This is an ESRI Add-In, Google Map Channels tool. You may close your arc products and double click the tool to install or place the file in a folder and use the Add-Ins option folder in ArcMap. When you restart Arcmap make sure to check the Google Extension(this causes the tool to be inoperable when in layout). To use this tool click on the tool then click in your map somewhere near a road your default internet explorer will open Google map channels at the place you clicked. Beware of the direction, direction is not coded in the tool so you may have to pan around to face the desired direction. Enjoy

0 Kudos
2 Replies
BrianKingery3
New Contributor

@Wes - Could you post the .py file that you used to make the tool? It works great. I have a few ideas that I would like to add to it if possible. Thanks

0 Kudos
WesMiller
Regular Contributor III
import arcpy
import pythonaddins
import functools
import os
import threading
import webbrowser
arcpy.env.overwriteOutput = True


def run_in_other_thread(function):
    @functools.wraps(function)
    def fn_(*args, **kwargs):
        thread = threading.Thread(target=function, args=args, kwargs=kwargs)
        thread.start()
        thread.join()
    return fn_
openbrowser = run_in_other_thread(webbrowser.open)


class GoogleExtension(object):
    """Implementation for GoogleTool_addin.extension10 (Extension)"""
    def activeViewChanged(self):
        mxd = arcpy.mapping.MapDocument('current')
        active_view = mxd.activeView
        # tool1 is the tool ID (without the namespace prefix)
        if active_view == 'PAGE_LAYOUT':
            tool.enabled = False
        else:
            tool.enabled = True
        arcpy.RefreshActiveView()
        return




class MapChannels(object):
    """Implementation for GoogleTool_gmcaddin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.shape = "NONE" 
    def onMouseUpMap(self, x, y, button, shift):
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        dfsr = df.spatialReference
        if len(dfsr.type) > 0:
            pass
        else:
            msgbox = pythonaddins.MessageBox('No Coordinate System','Oops!',0)
            print msgbox
            sys.exit("Unknown projection")
        in_memory = "in_memory"
        fcname = "pnt_name4444aj"
        #x,y = [2424419.971, 864749.537]
        fc = arcpy.CreateFeatureclass_management(in_memory,fcname,"POINT","","DISABLED","DISABLED",dfsr)
        rows = arcpy.da.InsertCursor(fc,["SHAPE@XY"])
        xy = (x,y)
        rows.insertRow([xy])
        del rows
        sr = 'GEOGCS["GCS_North_American_1927",DATUM["D_North_American_1927",SPHEROID["Clarke_1866",6378206.4,294.9786982]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]'
        for row in arcpy.da.SearchCursor(fc, ["SHAPE@XY"],"",sr):
            adx,ady = row[0]
            #print("{0}, {1}".format(adx, ady))
        for lyr in arcpy.mapping.ListLayers(mxd, "", df):
            if lyr.name == fcname:
                arcpy.mapping.RemoveLayer(df, lyr)
        url = "http://data.mapchannels.com/mm/dual2/map.htm?x=" +  str(adx) + "&y="+ str(ady) + "&z=16&xb=" + str(adx) + "&yb="+  str(ady) + "&bar=1&mw=1&gm=0&ve=2&sv=1"#&svb="+ String(computeAngle2(startPt,lastPnt))
        openbrowser(url)


        del mxd,df,dfsr,in_memory,fc,xy,sr,row,url
    
0 Kudos