我设置了一个回调函数,当您单击其中的一个时,它将在地图上连接两个相应的点。我的问题是我似乎无法删除连接它们的线。基本上,每次单击标记时都会调用以下函数。我需要它删除旧的大圆并映射新的大圆。相反,它只是继续创建新行,而不是删除旧行。您可以忽略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()
最佳答案
好吧,我不确定为什么会发生这种情况(或者是否应该发生),但是当我分配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)
关于python - Python basemap 移除大圆圈,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26112063/