我有一个回调函数设置,当你点击其中一个时,它会在地图上连接两个点。我的问题是我似乎无法删除连接它们的线。基本上,每次点击标记时都会调用以下函数。我需要它来删除旧的大圆并映射新的圆。相反,它只是继续创建新行而不是删除旧行。您可以忽略if语句,因为它们按预期工作。想法?
def mapPair(self,localLat,localLon,remoteLat, remoteLon):
if self.connectingLine != None:
self.connectingLine.remove() # <--doesn't work
if localLat != "unknown" and self.currentLocalItem is None:
self.currentLocalItem, = self.map.plot(localLon, localLat, 'bo', markersize=15, color='g', label="Local")
elif localLat!= "unknown" and self.currentLocalItem is not None:
self.currentLocalItem.set_ydata(localLat)
self.currentLocalItem.set_xdata(localLon)
self.connectingLine = self.map.drawgreatcircle(localLon, localLat, remoteLon, remoteLat, lw=3)
self.fig.canvas.draw()
答案 0 :(得分:1)
嗯,我不确定为什么会发生这种情况(或者如果它发生了),但是当我分配self.connectingLine时,我得到一个列表而不是一个对象。我不知道如何解决这个问题,所以这是我的工作
def mapPair(self,localLat,localLon,remoteLat, remoteLon):
if self.connectingLine != None:
for x in self.connectingLine:
x.remove()
if localLat != "unknown" and self.currentLocalItem is None:
self.currentLocalItem, = self.map.plot(localLon, localLat, 'bo', markersize=15, color='g', label="Local")
elif localLat!= "unknown" and self.currentLocalItem is not None:
self.currentLocalItem.set_ydata(localLat)
self.currentLocalItem.set_xdata(localLon)
self.connectingLine = self.map.drawgreatcircle(localLon, localLat, remoteLon, remoteLat, lw=3)