Graphics Reference
In-Depth Information
self.rubberBand = None
if self.tempRubberBand:
self.canvas.scene().removeItem(self.tempRubberBand)
self.tempRubberBand = None
self.capturing = False
self.capturedPoints = []
self.canvas.refresh()
We now come to the addVertex() method. This adds a new vertex to the current geo-
metry at the clicked-on mouse position, and updates the rubber bands to match:
def addVertex(self, canvasPoint):
mapPt,layerPt =
self.transformCoordinates(canvasPoint)
self.rubberBand.addPoint(mapPt)
self.capturedPoints.append(layerPt)
self.tempRubberBand.reset(self.bandType())
if self.captureMode == CaptureTool.CAPTURE_LINE:
self.tempRubberBand.addPoint(mapPt)
elif self.captureMode ==
CaptureTool.CAPTURE_POLYGON:
firstPoint = self.rubberBand.getPoint(0, 0)
self.tempRubberBand.addPoint(firstPoint)
self.tempRubberBand.movePoint(mapPt)
self.tempRubberBand.addPoint(mapPt)
Note that we add the captured point to the self.capturedPoints list. This is the list
of points that will define the geometry when we finish capturing. Setting up the temporary
rubber band is a bit convoluted, but the basic idea is to define LineString or Polygon so
that it covers the currently highlighted portion of the new geometry.
Let's now define the removeLastVertex() method, which is called when the user
presses Backspace or Delete to undo their last click. This method is slightly complicated
because we have to update both rubber bands to remove the last vertex, as well as the
self.capturedPoints list:
Search WWH ::




Custom Search