2

I'm at the moment working on some QGIS Plugin and are facing a problem I couldn't find a solution for.

Basically I'm composing a map from many different layers and I want to set one layer to be shown in the Overview Panel (the one from View -> Panels -> Overview Panel).

Is there a way to set programatically which layer should be shown in the overview panel?

And does anybody know if there exists any PyQgis class, so that one can use the overview panel with it's functionality in a stand alone application?


@underdark said what I was looking for. I was all the time searching for something like "MapOverviewPanel" since it's named like this or for "overview panel" etc and had no success. Knowing it's named QgsMapOverviewCanvas (not Panel..) I found the following Link:

For completeness I'll repost the code here:

from PyQt4.QtCore import Qt, QObject
from PyQt4.QtGui import QColor, QVBoxLayout, QDockWidget
from qgis.gui import QgsMapOverviewCanvas
from qgis.utils import iface
layer = iface.activeLayer()
canvas = iface.mapCanvas()
main_window = iface.mainWindow()
new_dock_widget = QDockWidget(u"My doc widget")
layout = QVBoxLayout()
map_canvas_overview = QgsMapOverviewCanvas(
 new_dock_widget,
 canvas
)
layerset = [layer.id()]
map_canvas_overview.setLayerSet(layerset)
map_canvas_overview.setBackgroundColor(QColor(255, 127, 0))
map_canvas_overview.enableAntiAliasing(True)
map_canvas_overview.setMinimumWidth(380)
map_canvas_overview.setMinimumHeight(280)
new_dock_widget.resize(400, 300)
layout.addWidget(map_canvas_overview)
new_dock_widget.setLayout(layout)
main_window.addDockWidget(Qt.RightDockWidgetArea, new_dock_widget)
new_dock_widget.show()
map_canvas_overview.refresh() # Make the background color disappear?
# Layout optional playground
layout.setContentsMargins(0, 0, 0, 0)

As you can see, this script is not communicating with the existing Overview panel in the Qgis GUI but instead creating a new widget inside the canvas showing the overview there (see image below on the right).

overview panel 2

What I would like to do for the plugin, is communicating with the existing QgsMapOverviewCanvas which the user can de-/activate from the View-Panels menu. For the standalone application this was exactly the class reference I was looking for.

How can I communicate with the Overview Panel and not create a widget with a second overview panel inside the map canvas.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked May 10, 2017 at 13:45
3
  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. A question asking for help writing code should include a snippet of your own attempt. Please edit your question to include your code snippet and details of what it's doing. Commented May 10, 2017 at 20:47
  • Have you tried to use qgis.org/api/2.14/classQgsMapOverviewCanvas.html? Code questions are supposed to contain a code attempt. Commented May 10, 2017 at 20:50
  • Thanks underdark this is what I was looking for. I also edited the question, so hopefully fit the forum requirements (also I disagree that I could provide a code snippet in the beginning because I was looking for a class/function name. What code could I provide for this?) Commented May 11, 2017 at 14:57

1 Answer 1

1

Okay I was finally able to find the solution myself.

In case anybody wants to do the same (communicating from python script with the in-build overview panel and not creating a new widget) you can set the layer to be shown in the overview panel by the following line of code:

QgsProject.instance().layerTreeRoot().findLayer( layerid ).setCustomProperty( "overview", 1 )

layerid can be found via QgsMapLayerRegistry.instance().mapLayers() and is the name of the layer aka the key of the returned dictonary.

answered May 16, 2017 at 16:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.