Graphics Reference
In-Depth Information
feature.setAttribute("status", TRACK_STATUS_OPEN)
feature.setAttribute("direction",
TRACK_DIRECTION_BOTH)
self.layer.addFeature(feature)
self.layer.updateExtents()
self.onTrackAdded()
Now that we've defined our map tool, let's update our application to use this tool. Back in
the forestTrails.py module, add the following to the end of the
setupMapTools() method:
self.addTrackTool = AddTrackTool(self.mapCanvas,
self.trackLayer,
self.onTrackAdded)
self.addTrackTool.setAction(self.actionAddTrack)
We can now define our addTrack() method as follows:
def addTrack(self):
if self.actionAddTrack.isChecked():
self.mapCanvas.setMapTool(self.addTrackTool)
else:
self.setPanMode()
If the user checks the Add Track action, we activate the Add Track tool. If the user un-
checks the action by clicking on it again, we will switch back to the pan mode.
Finally, we have to define a helper method called onTrackAdded() . This method re-
sponds when the user adds a new track to our track layer. Here is the implementation of
this method:
def onTrackAdded(self):
self.modified = True
self.mapCanvas.refresh()
self.actionAddTrack.setChecked(False)
self.setPanMode()
Search WWH ::




Custom Search