I attempted to write a custom toolbar similar to this one, but in my version clicking anywhere within a data frame opens a new tab of King County iMap that points to the location you clicked. Here is my code:
import arcpy
import pythonaddins
import webbrowser
class ToolClass(object):
"""Implementation for Open_iMap_addin.tool (Tool)"""
def __init__(self):
self.enabled = True
self.shape = "NONE"
def onMouseDownMap(self, x, y, button, shift):
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
point = arcpy.PointGeometry(arcpy.Point(x,y),arcpy.SpatialReference(df.spatialReference.PCSCode))
newPoint = point.projectAs(arcpy.SpatialReference(4326))
print(x,y)
print(str(newPoint.centroid.X) + ", " +str(newPoint.centroid.Y))
webbrowser.open('https://gismaps.kingcounty.gov/iMap/?center='+ str(newPoint.centroid.X) + '%2C' + str(newPoint.centroid.Y) + '&level=19', new=2)
The tool works, but my ArcMap crashes immediately after opening iMap and I get the following error:
Any idea why this might be happening?