2014-09-30 5 views
1

지도 중 하나를 클릭하면 두 점을 연결하는 콜백 함수가 설정되어 있습니다. 내 문제는 그들을 연결하는 줄을 삭제할 수없는 것입니다. 기본적으로 아래 함수는 마커를 클릭 할 때마다 호출됩니다. 오래된 거대한 원을 삭제하고 새 원을 그려야합니다. 대신, 이전 행을 삭제하는 대신 새로운 행을 계속 작성합니다. if 문은 예상대로 작동하기 때문에 무시할 수 있습니다. 생각?Python Basemap 큰 원을 제거하십시오.

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

난 그냥 다시 가서 같은 self.connectingLine.get_xydata 같은 더 많은 기능을 실행하려고 주위에 있었고, 난이 오류 "인쇄 self.connectingLine를 얻을. get_xydata() AttributeError : 'list'객체에 'get_xydata'속성이 없습니다. ".... 무슨 일이 벌어지고 있는지 전혀 모르겠습니다. apprently someself self.connectingLine은 객체 대신 목록입니까? –

답변

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)