Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want to get a message when every time I move the map.

I had:

def info(self):
    QMessageBox.information( self, self.tr( "Info" ), self.tr("info") )

I suppose that used to be something like that...

iface.mapCanvas().???.connect(self.info)
share|improve this question
    
By moved you mean moving the viewport, the position in the legend or the actual file/database where the layer/map is? –  lynxlynxlynx Apr 21 '13 at 17:54
add comment

1 Answer 1

up vote 6 down vote accepted

What you are looking for is the extentsChanged() signal. This is emitted every time, the map canvas is moved or zoomed.

The following code works from the python console:

from PyQt4.QtGui import QMessageBox

def info():
    QMessageBox.information( iface.mapCanvas(), "Extents changed", "Pan or zoom occurred" )

iface.mapCanvas().extentsChanged.connect(info)

Adjusting it to be used from a a python object (like in a plugin) should be easy, the necessary self-parameters are in the question code already.

There is no information about the new extents emitted with the signal, but this can be easily queried with

iface.mapCanvas().extent()
share|improve this answer
    
@underdark This should also work for QGIS 2.x, doesn't it? –  Matthias Kuhn Sep 29 '13 at 9:14
    
The signal/slot mechanism has changed, see gis.stackexchange.com/questions/72696/… –  underdark Sep 30 '13 at 13:13
    
They are different use-cases available in both versions. The signal mentioned in this answer only gets emitted when the extent changes (pan / zoom) the other one gets emitted whenever the map canvas is repainted (e.g. symbology change). –  Matthias Kuhn Sep 30 '13 at 13:30
    
sorry, my fault –  underdark Sep 30 '13 at 18:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.