Graphics Reference
In-Depth Information
Implementing the explore mode
So far, the user can choose which map layers are displayed, and can zoom and pan the map
view. The only thing missing is the entire point of the application: exploring landmarks. To
do this, we'll have to implement our application's explore mode.
In the previous chapter, we saw how we can use a QgsMapToolIdentify subclass to
respond when the user clicks on a vector feature. We're going to use the same logic here to
implement a new map tool, which we'll call ExploreTool . Add the following class
definition to your lex.py module after the PanTool class definition:
class ExploreTool(QgsMapToolIdentify):
def __init__(self, window):
QgsMapToolIdentify.__init__(self, window.mapCanvas)
self.window = window
def canvasReleaseEvent(self, event):
found_features = self.identify(event.x(), event.y(),
self.TopDownStopAtFirst,
self.VectorLayer)
if len(found_features) > 0:
layer = found_features[0].mLayer
feature = found_features[0].mFeature
geometry = feature.geometry()
info = []
name = feature.attribute("NAME")
if name != None: info.append(name)
admin_0 = feature.attribute("ADM0NAME")
admin_1 = feature.attribute("ADM1NAME")
if admin_0 and admin_1:
info.append(admin_1 + ", " + admin_0)
timezone = feature.attribute("TIMEZONE")
if timezone != None:
Search WWH ::




Custom Search