Graphics Reference
In-Depth Information
clicking on each vertex in turn. Unfortunately,
QgsMapToolCapture
is not available
as part of the PyQGIS library, so we will have to re-implement it ourselves using Python.
Let's start by looking at the design of our
QgsMapToolCapture
port, which we will
call
CaptureTool
. This will be a standard map tool, derived from
QgsMapTool
,
which makes use of
QgsRubberBand
objects to draw the visual highlighting of the
LineString or Polygon as it is drawn.
A
QgsRubberBand
is a map canvas item that draws a geometry on top of the map.
Since a rubber band draws its entire geometry in a single color and style, we have to use
two rubber bands in our capture tool: one that draws the already captured part of the geo-
metry and a second temporary rubber band that extends the geometry out to the current
mouse position. The following illustration shows how this works for both LineString and
Polygon geometries:
Here are some additional features that we will include in
CaptureTool
:
• It will have a
capture mode
that indicates whether the user is creating a
LineString or a Polygon geometry.
• The user can press the
Backspace
or
Delete
key to remove the last vertex added.
• The user can press the
Enter
or
Return
key to finish the capturing process.