Jaron Bradley
Jaron Bradley

Reputation: 1119

Python Basemap remove great circle

I have a callback function set up that will connect two according dots on a map when you click on one of them. My issue is I can't seem to delete the line connecting them. Basically the below function gets called every time a marker is clicked on. I need it to delete the old great circle and map the new one. Instead, it just continues to create new lines instead of deleting the old ones. You can ignore the if statements because they work as expected. Thoughts?

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()

Upvotes: 1

Views: 171

Answers (1)

Jaron Bradley
Jaron Bradley

Reputation: 1119

Well I'm not sure why this is happening (or if it's suppose to happen) but when I assigned self.connectingLine I get a list back instead of an object. I don't know how to fix this, so here was my work around

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)

Upvotes: 1

Related Questions