Newer
Older
# -*- coding: utf-8 -*-
"""
/***************************************************************************

Benjamin Jakimow
committed
EO Time Series Viewer
-------------------
begin : 2015-08-20
git sha : $Format:%H$
copyright : (C) 2017 by HU-Berlin
email : benjamin.jakimow@geo.hu-berlin.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import os, sys, re, fnmatch, collections, copy, traceback, bisect

benjamin.jakimow@geo.hu-berlin.de
committed
from qgis.core import *
from qgis.core import QgsContrastEnhancement, QgsRasterShader, QgsColorRampShader, QgsProject, QgsCoordinateReferenceSystem, \
QgsRasterLayer, QgsVectorLayer, QgsMapLayer, QgsMapLayerProxyModel, QgsColorRamp, QgsSingleBandPseudoColorRenderer
from qgis.gui import *
from qgis.gui import QgsDockWidget, QgsMapCanvas, QgsMapTool, QgsCollapsibleGroupBox
from PyQt5.QtXml import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

benjamin.jakimow@geo.hu-berlin.de
committed
import numpy as np
from .utils import *
from .import Option, OptionListModel
from .timeseries import SensorInstrument, TimeSeriesDate, TimeSeries, SensorProxyLayer
from .utils import loadUI
from .mapviewscrollarea import MapViewScrollArea
from .mapcanvas import MapCanvas, MapTools, MapCanvasInfoItem, MapCanvasMapTools
from .externals.qps.crosshair.crosshair import getCrosshairStyle, CrosshairStyle, CrosshairMapCanvasItem
from .externals.qps.layerproperties import showLayerPropertiesDialog
from .externals.qps.maptools import *
#assert os.path.isfile(dummyPath)
#lyr = QgsRasterLayer(dummyPath)
#assert lyr.isValid()
DUMMY_RASTERINTERFACE = QgsSingleBandGrayRenderer(None, 0)
KEY_LOCKED_LAYER = 'eotsv/locked'
KEY_SENSOR_GROUP = 'eotsv/sensorgroup'
KEY_SENSOR_LAYER = 'eotsv/sensorlayer'

Benjamin Jakimow
committed
def equalTextFormats(tf1:QgsTextFormat, tf2:QgsTextFormat)->True:
return tf1.toMimeData().text() == tf2.toMimeData().text()
class MapViewLayerTreeViewMenuProvider(QgsLayerTreeViewMenuProvider):
def __init__(self, mapView, view: QgsLayerTreeView, canvas: QgsMapCanvas):
super(MapViewLayerTreeViewMenuProvider, self).__init__()
assert isinstance(view, QgsLayerTreeView)
assert isinstance(canvas, QgsMapCanvas)
self.mLayerTreeView = view
self.mDummyCanvas = canvas
self.mDefActions = QgsLayerTreeViewDefaultActions(self.mLayerTreeView)
self.mMapView = mapView
self.actionAddGroup = self.mDefActions.actionAddGroup()
self.actionRename = self.mDefActions.actionRenameGroupOrLayer()
self.actionRemove = self.mDefActions.actionRemoveGroupOrLayer()

Benjamin Jakimow
committed
#self.actionZoomToLayer = self.mDefActions.actionZoomToGroup(self.mDummyCanvas)
self.actionCheckAndAllChildren = self.mDefActions.actionCheckAndAllChildren()
self.actionShowFeatureCount = self.mDefActions.actionShowFeatureCount()

Benjamin Jakimow
committed
#self.actionZoomToLayer = self.mDefActions.actionZoomToLayer(self.mDummyCanvas)
#self.actionZoomToSelected = self.mDefActions.actionZoomToSelection(self.mDummyCanvas)
#self.actionZoomToGroup = self.mDefActions.actionZoomToGroup(self.mDummyCanvas)
self.actionAddEOTSVSpectralProfiles = QAction('Add Spectral Profile Layer')
self.actionAddEOTSVTemporalProfiles = QAction('Add Temporal Profile Layer')
def mapView(self):
return self.mMapView
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def layerTreeView(self)->QgsLayerTreeView:
return self.mLayerTreeView
def layerTree(self)->QgsLayerTree:
return self.layerTreeModel().rootGroup()
def layerTreeModel(self)->QgsLayerTreeModel:
return self.layerTreeView().model()
def createContextMenu(self)->QMenu:
model = self.layerTreeModel()
ltree = self.layerTree()
view = self.layerTreeView()
g = view.currentGroupNode()
l = view.currentLayer()
i = view.currentIndex()
#fixedNodes = len([l for l in view.selectedLayersRecursive() if l.property(KEY_LOCKED_LAYER) == True]) > 0 or \
# isinstance(g, QgsLayerTreeGroup) and g.property(KEY_LOCKED_LAYER) == True
# disable actions
#self.actionRemove.setEnabled(fixedNodes == False)
menu = QMenu(view)
isSensorGroup = isinstance(g, QgsLayerTreeGroup) and g.customProperty(KEY_SENSOR_GROUP) in [True, 'true']
isSensorLayer = isinstance(l, QgsRasterLayer) and l.customProperty(KEY_SENSOR_LAYER) in [True, 'true']
self.actionRemove.setEnabled(not (isSensorGroup or isSensorLayer))
self.actionAddGroup.setEnabled(not (isSensorGroup or isSensorLayer))
menu.addAction(self.actionAddGroup)
menu.addAction(self.actionRename)
menu.addAction(self.actionRemove)

Benjamin Jakimow
committed
#menu.addAction(self.actionZoomToGroup)
#menu.addAction(self.actionZoomToLayer)
#menu.addAction(self.actionZoomToSelected)
menu.addSeparator()
menu.addAction(self.actionAddEOTSVSpectralProfiles)
menu.addAction(self.actionAddEOTSVTemporalProfiles)

Benjamin Jakimow
committed
menu.addSeparator()
centerCanvas = None
if isinstance(self.mapView(), MapView):
visibleCanvases = self.mapView().visibleMapCanvases()
if len(visibleCanvases) > 0:
i = int(len(visibleCanvases) / 2)
centerCanvas = visibleCanvases[i]
a = menu.addAction('Set Properties')
a.triggered.connect(lambda *args,
canvas = centerCanvas,
lyr = l,
b = not isinstance(l, SensorProxyLayer):
showLayerPropertiesDialog(lyr, canvas, useQGISDialog=b))
a.setEnabled(isinstance(centerCanvas, QgsMapCanvas))

Benjamin Jakimow
committed
from .externals.qps.layerproperties import pasteStyleFromClipboard, pasteStyleToClipboard
a = menu.addAction('Copy Style')
a.setToolTip('Copy the current layer style to clipboard')
a.triggered.connect(lambda *args, lyr=l: pasteStyleToClipboard(lyr))

Benjamin Jakimow
committed
a = menu.addAction('Paste Style')
a.setEnabled('application/qgis.style' in QApplication.clipboard().mimeData().formats())
a.triggered.connect(lambda *args, lyr=l: pasteStyleFromClipboard(lyr))
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#a = menu.addAction('Settings')
#from qps.layerproperties import showLayerPropertiesDialog
#a.triggered.connect(lambda *args, lyr=l:showLayerPropertiesDialog(lyr, self._canvas))
return menu
class MapViewLayerTreeModel(QgsLayerTreeModel):
"""
Layer Tree as shown in a MapView
"""
def __init__(self, rootNode, parent=None):
super(MapViewLayerTreeModel, self).__init__(rootNode, parent=parent)
def dataXXX(self, index:QModelIndex, role=Qt.DisplayRole):
node = self.index2node(index)
# if node.name() == 'testlayer':
# s = ""
if True:
if isinstance(node, QgsLayerTreeGroup) and node.customProperty(KEY_SENSOR_GROUP) in ['true', True]:
if role == Qt.FontRole:
f = super(MapViewLayerTreeModel, self).data(index, role=role)
f.setBold(True)
return f
if isinstance(node, QgsLayerTreeLayer) and node.customProperty(KEY_SENSOR_LAYER) in ['true', True]:
if role == Qt.FontRole:
f = super(MapViewLayerTreeModel, self).data(index, role=role)
assert isinstance(f, QFont)
f.setItalic(True)
return f

benjamin.jakimow@geo.hu-berlin.de
committed
if role == Qt.DecorationRole:
return QIcon(':/timeseriesviewer/icons/icon.svg')
return super(MapViewLayerTreeModel, self).data(index, role=role)
def flagsXXX(self, index:QModelIndex):
f = super(MapViewLayerTreeModel, self).flags(index)
node = self.index2node(index)
if isinstance(node, QgsLayerTreeNode) and ( \
node.customProperty(KEY_SENSOR_LAYER) in ['true', True] or \
node.customProperty(KEY_SENSOR_GROUP) in ['true', True]):
f = f ^ Qt.ItemIsDragEnabled
f = f ^ Qt.ItemIsDropEnabled
return f
class MapView(QFrame, loadUIFormClass(jp(DIR_UI, 'mapview.ui'))):
"""
A MapView defines how a single map canvas visualizes sensor specific EOTS data plus additional vector overlays
"""
#sigVisibilityChanged = pyqtSignal(bool)
sigCanvasAppearanceChanged = pyqtSignal()
sigCrosshairChanged = pyqtSignal()
sigTitleChanged = pyqtSignal(str)

benjamin.jakimow@geo.hu-berlin.de
committed
sigSensorRendererChanged = pyqtSignal(SensorInstrument, QgsRasterRenderer)
sigShowProfiles = pyqtSignal(SpatialPoint, MapCanvas, str)

benjamin.jakimow@geo.hu-berlin.de
committed
def __init__(self, name='Map View', parent=None):
super(MapView, self).__init__(parent)
self.setupUi(self)

Benjamin Jakimow
committed

Benjamin Jakimow
committed
from eotimeseriesviewer.settings import DEFAULT_VALUES, Keys

Benjamin Jakimow
committed
self.mMapBackgroundColor = DEFAULT_VALUES[Keys.MapBackgroundColor]
self.mMapTextFormat = DEFAULT_VALUES[Keys.MapTextFormat]
self.mCurrentLayer = None
self.mMapWidget = None
self.mTimeSeries = None
self.mSensorLayerList = list()
self.mCrossHairStyle = CrosshairStyle()
m = QMenu(self.btnToggleCrosshair)
m.addAction(self.actionSetCrosshairStyle)
self.btnToggleCrosshair.setMenu(m)
self.btnToggleCrosshair.setDefaultAction(self.actionToggleCrosshairVisibility)
self.btnToggleCrosshair.setChecked(self.crosshairStyle().mShow)
self.btnToggleMapViewVisibility.setDefaultAction(self.actionToggleMapViewHidden)
self.tbName.textChanged.connect(self.onTitleChanged)
self.actionSetCrosshairStyle.triggered.connect(self.onChangeCrosshairStyle)
self.actionToggleMapViewHidden.toggled.connect(self.sigCanvasAppearanceChanged)
self.actionToggleCrosshairVisibility.toggled.connect(self.setCrosshairVisibility)
self.actionAddMapLayer.triggered.connect(lambda *args: self.onAddMapLayer())
self.actionAddVectorLayer.triggered.connect(lambda *args: self.onAddMapLayer(QgsMapLayerProxyModel.VectorLayer))
self.actionAddRasterLayer.triggered.connect(lambda *args: self.onAddMapLayer(QgsMapLayerProxyModel.RasterLayer))
self.btnAddLayer.setDefaultAction(self.actionAddMapLayer)
m = QMenu()
m.addAction(self.actionAddVectorLayer)
m.addAction(self.actionAddRasterLayer)
self.btnAddLayer.setMenu(m)
self.btnHighlightMapView.setDefaultAction(self.actionHighlightMapView)
self.actionHighlightMapView.triggered.connect(lambda: self.setHighlighted(True, timeout=500))
assert isinstance(self.mLayerTreeView, QgsLayerTreeView)
self.mDummyCanvas = QgsMapCanvas() # dummy map canvas for dummy layers
self.mDummyCanvas.setVisible(False)

benjamin.jakimow@geo.hu-berlin.de
committed
self.mLayerTree = QgsLayerTree()
self.mLayerTreeMapCanvasBridget = QgsLayerTreeMapCanvasBridge(self.mLayerTree, self.mDummyCanvas)

benjamin.jakimow@geo.hu-berlin.de
committed
# self.mLayerTreeModel = QgsLayerTreeModel(self.mLayerTree)
self.mLayerTreeModel = MapViewLayerTreeModel(self.mLayerTree)
self.mLayerTreeModel.setFlags(QgsLayerTreeModel.AllowNodeChangeVisibility |
QgsLayerTreeModel.AllowNodeRename |
QgsLayerTreeModel.AllowNodeReorder)
self._createSensorNode()
self.mLayerTreeView.setModel(self.mLayerTreeModel)
self.mMapLayerTreeViewMenuProvider = MapViewLayerTreeViewMenuProvider(self, self.mLayerTreeView, self.mDummyCanvas)
# register some actions that interact with other GUI elements
self.mMapLayerTreeViewMenuProvider.actionAddEOTSVSpectralProfiles.triggered.connect(self.addSpectralProfileLayer)
self.mMapLayerTreeViewMenuProvider.actionAddEOTSVTemporalProfiles.triggered.connect(self.addTemporalProfileLayer)
self.mLayerTreeView.setMenuProvider(self.mMapLayerTreeViewMenuProvider)
self.mLayerTreeView.currentLayerChanged.connect(self.setCurrentLayer)
self.mLayerTree.removedChildren.connect(self.onChildNodesRemoved)
self.mIsVisible = True

Benjamin Jakimow
committed
m = QMenu()
m.addAction(self.optionShowDate)
m.addAction(self.optionShowSensorName)
m.addAction(self.optionShowMapViewName)
self.btnInfoOptions.setMenu(m)
for action in m.actions():
action.toggled.connect(self.sigCanvasAppearanceChanged)
fixMenuButtons(self)
def setName(self, name:str):
self.setTitle(name)
def name(self)->str:
return self.title()

Benjamin Jakimow
committed
def setMapTextFormat(self, textformat:QgsTextFormat)->QgsTextFormat:
if not equalTextFormats(self.mapTextFormat(), textformat):
self.mMapTextFormat = textformat
self.sigCanvasAppearanceChanged.emit()
return self.mapTextFormat()
def mapTextFormat(self)->QgsTextFormat:
return self.mMapTextFormat
def mapBackgroundColor(self)->QColor:
"""
Returns the map background color
:return: QColor
"""
return self.mMapBackgroundColor
def setMapBackgroundColor(self, color:QColor)->QColor:
"""
Sets the map background color
:param color: QColor
:return: QColor
"""
if self.mMapBackgroundColor != color:
self.mMapBackgroundColor = color
self.sigCanvasAppearanceChanged.emit()
return self.mMapBackgroundColor
def visibleMapCanvases(self)->list:
"""
Returns the currently visible mapcanvases
:return: [list-of-MapCanvases]
"""
return [m for m in self.mapCanvases() if m.isVisibleToViewport()]
def onAddMapLayer(self, filter:QgsMapLayerProxyModel.Filter=QgsMapLayerProxyModel.All):
Slot that opens a SelectMapLayersDialog for any kind of layer
"""
from .externals.qps.utils import SelectMapLayersDialog
d = SelectMapLayersDialog()
if filter == QgsMapLayerProxyModel.All:
title = 'Select Layer'
text = 'Layer'
elif filter == QgsMapLayerProxyModel.RasterLayer:
title = 'Select Raster Layer'
text = 'Raster'
elif filter == QgsMapLayerProxyModel.VectorLayer:
title = 'Select Vector Layer'
text = 'Vector'
d.setWindowTitle(title)
d.addLayerDescription(text, filter)
if d.exec() == QDialog.Accepted:
for l in d.mapLayers():
self.addLayer(l)
def setCurrentLayer(self, layer:QgsMapLayer):
"""
Sets the QgsMapCanvas.currentLayer() that is used by some QgsMapTools
:param layer: QgsMapLayer | None
:return:
"""
assert layer is None or isinstance(layer, QgsMapLayer)
self.mCurrentLayer = layer
if layer not in self.mSensorLayerList:
for c in self.mapCanvases():
c.setCurrentLayer(layer)
else:
s = ""
def addSpectralProfileLayer(self):
"""Adds the EOTSV Spectral Profile Layer"""
from eotimeseriesviewer.main import TimeSeriesViewer
tsv = TimeSeriesViewer.instance()
if isinstance(tsv, TimeSeriesViewer):
lyr = tsv.spectralLibrary()
if lyr not in self.layers():
self.addLayer(lyr)
def addTemporalProfileLayer(self):
"""Adds the EOTSV Temporal Profile Layer"""
from eotimeseriesviewer.main import TimeSeriesViewer
tsv = TimeSeriesViewer.instance()
if isinstance(tsv, TimeSeriesViewer):
lyr = tsv.temporalProfileLayer()
if lyr not in self.layers():
self.addLayer(lyr)
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
def addLayer(self, layer:QgsMapLayer):
"""
Add a QgsMapLayer to the MapView layer tree
:param layer: QgsMapLayer
"""
if isinstance(layer, QgsVectorLayer):
self.mLayerTree.insertLayer(0, layer)
else:
self.mLayerTree.addLayer(layer)
def _createSensorNode(self):
self.mLayerTreeSensorNode = QgsLayerTreeGroup(name='Raster Time Series', checked=True)
self.mLayerTreeSensorNode.setCustomProperty(KEY_LOCKED_LAYER, True)
self.mLayerTreeSensorNode.setCustomProperty(KEY_SENSOR_GROUP, True)
self.mLayerTree.addChildNode(self.mLayerTreeSensorNode)
def _containsSensorNode(self, root:QgsLayerTreeGroup)->bool:
assert isinstance(root, QgsLayerTreeGroup)
if root.customProperty(KEY_SENSOR_GROUP) in [True, 'true']:
return True
for grp in root.findGroups():
if self._containsSensorNode(grp):
return True
return False
def onChildNodesRemoved(self, node, idxFrom, idxTo):
if not self._containsSensorNode(self.mLayerTreeModel.rootGroup()):
self._createSensorNode()
def onChangeCrosshairStyle(self):
canvases = self.mapCanvases()
if len(canvases) > 0:
mapCanvas = canvases[0]
else:
mapCanvas = None
style = getCrosshairStyle(parent=self, crosshairStyle=self.crosshairStyle(), mapCanvas=mapCanvas)
if isinstance(style, CrosshairStyle):
self.setCrosshairStyle(style)
def setVisibility(self, b: bool):

Benjamin Jakimow
committed
"""
Sets the map view visibility
:param b: bool
"""
if self.actionToggleMapViewHidden.isChecked() == b:
self.actionToggleMapViewHidden.setChecked(not b)
self.sigCanvasAppearanceChanged.emit()

Benjamin Jakimow
committed
def isVisible(self)->bool:
"""
Returns the map view visibility
:return: bool
"""
return not self.actionToggleMapViewHidden.isChecked()

Benjamin Jakimow
committed
def mapCanvases(self)->list:
"""
Returns the MapCanvases related to this map view. Requires that this mapview was added to a MapWidget

Benjamin Jakimow
committed
:return: [list-of-MapCanvases]
"""
if isinstance(self.mMapWidget, MapWidget):
return self.mMapWidget.mapViewCanvases(self)
else:
return []
def onTitleChanged(self, *args):
self.setWindowTitle('Map View "{}"'.format(self.title()))
self.sigTitleChanged.emit(self.title())
if self.optionShowMapViewName.isChecked():
self.sigCanvasAppearanceChanged.emit()
def setMapWidget(self, w):
if isinstance(w, MapWidget):
self.mMapWidget = w
else:
self.mMapWidget = None
def setTimeSeries(self, timeSeries:TimeSeries):
"""
Conntects the MapView with a TimeSeries.
:param timeSeries: TimeSeries
"""
assert isinstance(timeSeries, TimeSeries)
for s in self.sensors():
self.removeSensor(s)
self.mTimeSeries = timeSeries
self.mTimeSeries.sigSensorAdded.connect(self.addSensor)
self.mTimeSeries.sigSensorRemoved.connect(self.removeSensor)
for s in timeSeries.sensors():
self.addSensor(s)
def timeSeries(self)->TimeSeries:
"""
Returns the TimeSeries this mapview is connected with
:return: TimeSeries
"""
return self.mTimeSeries
def setTitle(self, title:str):
"""
Sets the widget title
:param title: str
"""
self.tbName.setText(title)

benjamin.jakimow@geo.hu-berlin.de
committed
def layers(self)->list:
"""
Returns the visible layers, including proxy layer for time-series data
:return: [list-of-QgsMapLayers]
"""
return [l for l in self.mLayerTree.checkedLayers() if isinstance(l, QgsMapLayer)]
def title(self, maskNewLines=True)->str:
"""
Returns the MapView title
:return: str
"""
if maskNewLines:
return self.tbName.text().replace('\\n', ' ').strip()
else:
return self.tbName.text().strip()
def setCrosshairStyle(self, crosshairStyle:CrosshairStyle)->CrosshairStyle:
"""

Benjamin Jakimow
committed
Seths the CrosshairStyle of this MapView
:param crosshairStyle: CrosshairStyle
"""
if self.mCrossHairStyle != crosshairStyle:
self.mCrossHairStyle = crosshairStyle
self.sigCrosshairChanged.emit()
return self.mCrossHairStyle

benjamin.jakimow@geo.hu-berlin.de
committed
def setHighlighted(self, b=True, timeout=1000):
"""
Activates or deactivates a red-line border of the MapCanvases
:param b: True | False to activate / deactivate the highlighted lines-
:param timeout: int, milliseconds how long the highlighted frame should appear
"""

benjamin.jakimow@geo.hu-berlin.de
committed
styleOn = """.MapCanvas {
border: 4px solid red;
border-radius: 4px;
}"""
styleOff = """"""
if b is True:
for mapCanvas in self.mapCanvases():
mapCanvas.setStyleSheet(styleOn)
if timeout > 0:
QTimer.singleShot(timeout, lambda : self.setHighlighted(False))
else:
for mapCanvas in self.mapCanvases():
mapCanvas.setStyleSheet(styleOff)

Benjamin Jakimow
committed
def crosshairStyle(self)->CrosshairStyle:
"""
Returns the CrosshairStyle
:return: CrosshairStyle

Benjamin Jakimow
committed
"""
return self.mCrossHairStyle
def setCrosshairVisibility(self, b:bool):

Benjamin Jakimow
committed
"""
Enables / diables the map canvas crosshair.
:param b: bool

Benjamin Jakimow
committed
"""
if b != self.actionToggleCrosshairVisibility.isChecked():
self.actionToggleCrosshairVisibility.setChecked(b)

Benjamin Jakimow
committed
else:
self.mCrossHairStyle.setVisibility(b)
self.sigCrosshairChanged.emit()
def sensorProxyLayers(self)->list:
layers = [n.layer() for n in self.mLayerTreeSensorNode.findLayers()]
return [l for l in layers if isinstance(l, SensorProxyLayer)]
def sensorProxyLayer(self, sensor:SensorInstrument)->SensorProxyLayer:

benjamin.jakimow@geo.hu-berlin.de
committed
"""
Returns the proxy layer related to a SensorInstrument
:param sensor: SensorInstrument
:return: SensorLayer
"""
for l in self.sensorProxyLayers():
if l.sensor() == sensor:
return l
return None
def sensors(self)->list:
"""
Returns a list of SensorsInstruments
:return: [list-of-SensorInstruments]
"""
return [t[0] for t in self.mSensorLayerList]
def addSensor(self, sensor:SensorInstrument):
"""
Adds a SensorInstrument to be shown in this MapView. Each sensor will be represented as a Raster Layer in the
Tree Model.
:param sensor: SensorInstrument
"""
assert isinstance(sensor, SensorInstrument)
if sensor not in self.sensors():
sensor.sigNameChanged.connect(self.sigCanvasAppearanceChanged)
dummyLayer = sensor.proxyLayer()
assert isinstance(dummyLayer.renderer(), QgsRasterRenderer)
dummyLayer.rendererChanged.connect(lambda sensor=sensor: self.onSensorRendererChanged(sensor))

Benjamin Jakimow
committed
#QgsProject.instance().addMapLayer(dummyLayer)
layerTreeLayer = self.mLayerTreeSensorNode.addLayer(dummyLayer)
assert isinstance(layerTreeLayer, QgsLayerTreeLayer)
layerTreeLayer.setCustomProperty(KEY_LOCKED_LAYER, True)
layerTreeLayer.setCustomProperty(KEY_SENSOR_LAYER, True)
self.mSensorLayerList.append((sensor, dummyLayer))
def onSensorRendererChanged(self, sensor:SensorInstrument):
for c in self.sensorCanvases(sensor):
assert isinstance(c, MapCanvas)
c.addToRefreshPipeLine(MapCanvas.Command.RefreshRenderer)
def sensorCanvases(self, sensor:SensorInstrument)->list:
"""
Returns the MapCanvases that show a layer with data for the given ``sensor``
:param sensor: SensorInstrument
:return:
"""
assert isinstance(sensor, SensorInstrument)
return [c for c in self.mapCanvases() if isinstance(c, MapCanvas) and \
isinstance(c.tsd(), TimeSeriesDate) and c.tsd().sensor() == sensor]
def sensorLayer(self, sensor: SensorInstrument):
"""
Returns the QgsRasterLayer that is used a proxy to specify the QgsRasterRenderer for a sensor
:param sensor: SensorInstrument
:return: QgsRasterLayer
"""
assert isinstance(sensor, SensorInstrument)
for t in self.mSensorLayerList:
s, l = t
assert isinstance(s, SensorInstrument)
assert isinstance(l, QgsRasterLayer)
if s == sensor:
return l
raise Exception('Sensor "{}" not registered to MapView "{}"'.format(sensor.name(), self.title()))
def removeSensor(self, sensor:SensorInstrument):
"""
Removes a sensor from this map view

benjamin.jakimow@geo.hu-berlin.de
committed
:param sensor:
:return:
"""
pair = None
for i, t in enumerate(self.mSensorLayerList):
if t[0] == sensor:
pair = t
break
assert pair is not None, 'Sensor "{}" not found'.format(sensor.name())
self.mLayerTreeSensorNode.removeLayer(pair[1])
self.mSensorLayerList.remove(pair)

benjamin.jakimow@geo.hu-berlin.de
committed
def hasSensor(self, sensor)->bool:
"""
:param sensor:
:return:
"""
assert isinstance(sensor, SensorInstrument)
return sensor in self.sensors()

benjamin.jakimow@geo.hu-berlin.de
committed
class MapViewListModel(QAbstractListModel):
"""
A model to store a list of map views.

benjamin.jakimow@geo.hu-berlin.de
committed
"""
sigMapViewsAdded = pyqtSignal(list)
sigMapViewsRemoved = pyqtSignal(list)

benjamin.jakimow@geo.hu-berlin.de
committed
def __init__(self, parent=None):
super(MapViewListModel, self).__init__(parent)
self.mMapViewList = []

benjamin.jakimow@geo.hu-berlin.de
committed
def addMapView(self, mapView):
i = len(self.mMapViewList)
self.insertMapView(i, mapView)
def insertMapView(self, i, mapView):
self.insertMapViews(i, [mapView])
def insertMapViews(self, i, mapViews):
assert isinstance(mapViews, list)
assert i >= 0 and i <= len(self.mMapViewList)
self.beginInsertRows(QModelIndex(), i, i + len(mapViews) - 1)

benjamin.jakimow@geo.hu-berlin.de
committed
for j in range(len(mapViews)):
mapView = mapViews[j]
assert isinstance(mapView, MapView)
mapView.sigTitleChanged.connect(
lambda : self.doRefresh([mapView])
)
self.mMapViewList.insert(i + j, mapView)
self.endInsertRows()
self.sigMapViewsAdded.emit(mapViews)

benjamin.jakimow@geo.hu-berlin.de
committed
def doRefresh(self, mapViews):
for mapView in mapViews:
idx = self.mapView2idx(mapView)
self.dataChanged.emit(idx, idx)

benjamin.jakimow@geo.hu-berlin.de
committed
def removeMapView(self, mapView):
self.removeMapViews([mapView])

benjamin.jakimow@geo.hu-berlin.de
committed
def removeMapViews(self, mapViews):
assert isinstance(mapViews, list)
for mv in mapViews:
assert mv in self.mMapViewList
idx = self.mapView2idx(mv)
self.beginRemoveRows(idx.parent(), idx.row(), idx.row())
self.mMapViewList.remove(mv)
self.endRemoveRows()
self.sigMapViewsRemoved.emit(mapViews)

benjamin.jakimow@geo.hu-berlin.de
committed
def rowCount(self, parent=None, *args, **kwargs):
return len(self.mMapViewList)

benjamin.jakimow@geo.hu-berlin.de
committed
def columnCount(self, QModelIndex_parent=None, *args, **kwargs):
return 1
def idx2MapView(self, index):
if isinstance(index, QModelIndex):
if index.isValid():
index = index.row()
else:
return None
assert index >= 0 and index < len(self.mMapViewList)
return self.mMapViewList[index]
def mapView2idx(self, mapView):
assert isinstance(mapView, MapView)
row = self.mMapViewList.index(mapView)
return self.createIndex(row, 0, mapView)

benjamin.jakimow@geo.hu-berlin.de
committed
def __getitem__(self, slice):
return self.mMapViewList[slice]
def data(self, index, role=Qt.DisplayRole):
if not index.isValid():
return None
if (index.row() >= len(self.mMapViewList)) or (index.row() < 0):
return None
mapView = self.idx2MapView(index)
assert isinstance(mapView, MapView)
if role == Qt.DisplayRole:
value = '{} {}'.format(index.row() +1 , mapView.title())
#if role == Qt.DecorationRole:
#value = classInfo.icon(QSize(20,20))
if role == Qt.UserRole:
value = mapView
return value
class MapWidget(QFrame, loadUIFormClass(jp(DIR_UI, 'mapwidget.ui'))):
"""
This widget contains all maps
"""
class ViewMode(enum.Enum):
MapViewByRows = 1,
MapViewByCols = 2
sigCrosshairPositionChanged = pyqtSignal([SpatialPoint], [SpatialPoint, MapCanvas])
sigCRSChanged = pyqtSignal(QgsCoordinateReferenceSystem)

Benjamin Jakimow
committed
sigMapBackgroundColorChanged = pyqtSignal(QColor)
sigMapTextColorChanged = pyqtSignal(QColor)

Benjamin Jakimow
committed
sigMapTextFormatChanged = pyqtSignal(QgsTextFormat)
sigMapsPerMapViewChanged = pyqtSignal(int)
sigMapViewsChanged = pyqtSignal()
sigMapViewAdded = pyqtSignal(MapView)
sigMapViewRemoved = pyqtSignal(MapView)
sigCurrentDateChanged = pyqtSignal(TimeSeriesDate)
sigCurrentLocationChanged = pyqtSignal(SpatialPoint, MapCanvas)
sigVisibleDatesChanged = pyqtSignal(list)
sigViewModeChanged = pyqtSignal(ViewMode)
def __init__(self, *args, **kwds):
super(MapWidget, self).__init__(*args, **kwds)
self.setContentsMargins(1, 1, 1, 1)

Benjamin Jakimow
committed
self.mGrid = self.gridFrame.layout()
assert isinstance(self.mGrid, QGridLayout)
self.mGrid.setSpacing(0)
self.mGrid.setContentsMargins(0, 0, 0, 0)
self.mSyncLock = False

Benjamin Jakimow
committed
self.mMaxNumberOfCachedLayers = 0
self.mMapLayerStore = QgsMapLayerStore()

Benjamin Jakimow
committed
self.mMapLayerCache = dict()
self.mCanvasCache = dict()
self.mMapViews = []
self.mCanvases = dict()
self.mTimeSeries = None

Benjamin Jakimow
committed
self.mMapToolKey = MapTools.Pan
self.mViewMode = MapWidget.ViewMode.MapViewByRows
self.mMpMV = 3
self.mSpatialExtent = SpatialExtent.world()
self.mCrs = self.mSpatialExtent.crs()
self.mCurrentDate = None
self.mCrosshairPosition = None

benjamin.jakimow@geo.hu-berlin.de
committed
self.mMapSize = QSize(200, 200)

Benjamin Jakimow
committed
from eotimeseriesviewer.settings import DEFAULT_VALUES, Keys
self.mMapTextFormat = DEFAULT_VALUES[Keys.MapTextFormat]
self.mMapRefreshTimer = QTimer(self)
self.mMapRefreshTimer.timeout.connect(self.timedRefresh)
self.mMapRefreshTimer.setInterval(500)
self.mMapRefreshTimer.start()
#self.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

Benjamin Jakimow
committed
self.btnFirst.setDefaultAction(self.actionFirstDate)
self.btnLast.setDefaultAction(self.actionLastDate)
self.btnBackward.setDefaultAction(self.actionBackward)
self.btnForward.setDefaultAction(self.actionForward)
self.btnBackwardFast.setDefaultAction(self.actionBackwardFast)
self.btnForwardFast.setDefaultAction(self.actionForwardFast)
self.actionFirstDate.triggered.connect(self.moveToFirstTSD)
self.actionLastDate.triggered.connect(self.moveToLastTSD)
self.actionBackward.triggered.connect(self.moveToPreviousTSD)
self.actionForward.triggered.connect(self.moveToNextTSD)
self.actionBackwardFast.triggered.connect(self.moveToPreviousTSDFast)
self.actionForwardFast.triggered.connect(self.moveToNextTSDFast)

Benjamin Jakimow
committed
self.mTimeSlider.valueChanged.connect(self.onSliderReleased)
def messageBar(self)->QgsMessageBar:
"""
Returns the QgsMessageBar
:return: QgsMessageBar
"""
return self.mMessageBar
def refresh(self):
for c in self.mapCanvases():
assert isinstance(c, MapCanvas)
c.timedRefresh()

Benjamin Jakimow
committed
def setMapTextFormat(self, textFormat:QgsTextFormat)->QgsTextFormat:
if not equalTextFormats(textFormat, self.mMapTextFormat):
self.mMapTextFormat = textFormat
for mapView in self.mapViews():
assert isinstance(mapView, MapView)
mapView.setMapTextFormat(textFormat)
self.sigMapTextFormatChanged.emit(self.mapTextFormat())
return self.mapTextFormat()
def mapTextFormat(self)->QgsTextFormat:
return self.mMapTextFormat
def setMapTool(self, mapToolKey:MapTools):
if self.mMapToolKey != mapToolKey:
self.mMapToolKey = mapToolKey

Benjamin Jakimow
committed
for c in self.mapCanvases():
assert isinstance(c, MapCanvas)
mts = c.mapTools()
mts.activate(self.mMapToolKey)
def visibleTSDs(self)->list:
"""
Returns the list of currently shown TimeSeriesDates.
:return: [list-of-TimeSeriesDates]
"""
for mv in self.mMapViews:
tsds = []
for c in self.mCanvases[mv]:
if isinstance(c.tsd(), TimeSeriesDate):
tsds.append(c.tsd())
return sorted(tsds)
return []
def spatialExtent(self)->SpatialExtent:
"""
Returns the current SpatialExtent
:return: SpatialExtent
"""
return self.mSpatialExtent
def setSpatialExtent(self, extent:SpatialExtent)->SpatialExtent:
"""
Sets a SpatialExtent to all MapCanvases.
:param extent: SpatialExtent
:return: SpatialExtent the current SpatialExtent
"""
if self.mSpatialExtent != extent:
self.mSpatialExtent = extent

benjamin.jakimow@geo.hu-berlin.de
committed
for c in self.mapCanvases():
assert isinstance(c, MapCanvas)
c.addToRefreshPipeLine(extent)

benjamin.jakimow@geo.hu-berlin.de
committed
self.sigSpatialExtentChanged.emit(self.mSpatialExtent.__copy__())
return self.spatialExtent()

benjamin.jakimow@geo.hu-berlin.de
committed
def setSpatialCenter(self, centerNew:SpatialPoint):
"""
Sets the spatial center of all MapCanvases
:param centerNew: SpatialPoint
"""
assert isinstance(centerNew, SpatialPoint)
extent = self.spatialExtent()
if isinstance(extent, SpatialExtent):
centerOld = extent.center()
centerNew = centerNew.toCrs(extent.crs())
if centerNew != centerOld and isinstance(centerNew, SpatialPoint):
extent = extent.__copy__()
extent.setCenter(centerNew)
self.setSpatialExtent(extent)

benjamin.jakimow@geo.hu-berlin.de
committed
def spatialCenter(self)->SpatialPoint:
"""
Return the center of all map canvas
:return: SpatialPoint
"""
return self.spatialExtent().spatialCenter()

benjamin.jakimow@geo.hu-berlin.de
committed
def setCrs(self, crs:QgsCoordinateReferenceSystem)->QgsCoordinateReferenceSystem:
Sets the MapCanvas CRS.
:param crs: QgsCoordinateReferenceSystem
:return: QgsCoordinateReferenceSystem

benjamin.jakimow@geo.hu-berlin.de
committed
self.mCrs = crs
if isinstance(crs, QgsCoordinateReferenceSystem):
for c in self.mapCanvases():
c.setCrs(crs)

benjamin.jakimow@geo.hu-berlin.de
committed
return self.crs()

benjamin.jakimow@geo.hu-berlin.de
committed
def timedRefresh(self):
Calls the timedRefresh() routine for all MapCanvases
for c in self.mapCanvases():
assert isinstance(c, MapCanvas)
c.timedRefresh()

benjamin.jakimow@geo.hu-berlin.de
committed

Benjamin Jakimow
committed
def currentLayers(self):
layers = set()
for c in self.mapCanvases():
layers = layers.union(set(c.layers()))
return list(layers)
def crs(self)->QgsCoordinateReferenceSystem:
return self.mCrs
def setTimeSeries(self, ts:TimeSeries)->TimeSeries:
assert ts == None or isinstance(ts, TimeSeries)
self.mTimeSeries = ts
if isinstance(self.mTimeSeries, TimeSeries):
self.mTimeSeries.sigVisibilityChanged.connect(self._updateCanvasDates)
self.mTimeSeries.sigTimeSeriesDatesRemoved.connect(self._updateCanvasDates)

benjamin.jakimow@geo.hu-berlin.de
committed

Benjamin Jakimow
committed
self.mTimeSeries.sigTimeSeriesDatesAdded.connect(self._updateSliderRange)
self.mTimeSeries.sigTimeSeriesDatesRemoved.connect(self._updateSliderRange)
if len(self.mTimeSeries) > 0:
self.mCurrentDate = self.mTimeSeries[0]
else:
self.mTimeSeries.sigTimeSeriesDatesAdded.connect(self.onSetInitialCurrentDate)

Benjamin Jakimow
committed
self._updateSliderRange()
return self.timeSeries()

benjamin.jakimow@geo.hu-berlin.de
committed
def onSetInitialCurrentDate(self):
if len(self.timeSeries()) > 0:
self.setCurrentDate(self.timeSeries()[0])
self.mTimeSeries.sigTimeSeriesDatesAdded.disconnect(self.onSetInitialCurrentDate)

Benjamin Jakimow
committed
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
def _updateSliderRange(self):
n = len(self.timeSeries())
self.mTimeSlider.setRange(0, n)
self.mTimeSlider.setEnabled(n > 0)
if n > 0:
tsd = self.currentDate()
if isinstance(tsd, TimeSeriesDate) and tsd in self.timeSeries():
i = self.timeSeries()[:].index(tsd)
self.mTimeSlider.setValue(i+1)
def onSliderReleased(self):
i = self.mTimeSlider.value() - 1
if isinstance(self.mTimeSeries, TimeSeries) and len(self.mTimeSeries) > 0:
i = min(i, len(self.mTimeSeries)-1)
i = max(i, 0)
tsd = self.mTimeSeries[i]
self.setCurrentDate(tsd)
def timeSeries(self)->TimeSeries:
return self.mTimeSeries

benjamin.jakimow@geo.hu-berlin.de
committed
def setMode(self, mode:ViewMode):

benjamin.jakimow@geo.hu-berlin.de
committed
if mode != self.mViewMode:
self.mViewMode = mode
self._updateGrid()
self.sigViewModeChanged.emit(self.mViewMode)
def setMapsPerMapView(self, n:int):
assert n >= 0

benjamin.jakimow@geo.hu-berlin.de
committed
if n != self.mMpMV:
self.mMpMV = n
self._updateGrid()
self.timeSlider().setPageStep(max(1, n))
self.sigMapsPerMapViewChanged.emit(n)

benjamin.jakimow@geo.hu-berlin.de
committed
def setMapSize(self, size:QSize)->QSize:
Sets the MapCanvas size
:param size: QSite
:return: QSize

benjamin.jakimow@geo.hu-berlin.de
committed
if size != self.mMapSize:
for canvas in self.mapCanvases():
canvas.setFixedSize(size)

benjamin.jakimow@geo.hu-berlin.de
committed
self.mMapSize = size
self._updateWidgetSize()
self.sigMapSizeChanged.emit(size)
return self.mMapSize

benjamin.jakimow@geo.hu-berlin.de
committed
def mapSize(self)->QSize:
"""
Returns the MapCanvas size
:return: QSize
"""
return self.mMapSize

benjamin.jakimow@geo.hu-berlin.de
committed
def mapCanvases(self)->list:
"""
Returns all MapCanvases
:return: [list-of-MapCanvases]
"""
return self.findChildren(MapCanvas)
def mapViewCanvases(self, mapView:MapView)->list:

benjamin.jakimow@geo.hu-berlin.de
committed
"""
Returns the MapCanvases related to a MapView
:return: [list-of-MapCanvases]

benjamin.jakimow@geo.hu-berlin.de
committed
"""
return self.mCanvases[mapView]

benjamin.jakimow@geo.hu-berlin.de
committed
def moveToNextTSD(self):
for tsd in self.timeSeries()[:]:
assert isinstance(tsd, TimeSeriesDate)
if tsd > self.currentDate() and tsd.isVisible():
self.setCurrentDate(tsd)
return
s = ""

benjamin.jakimow@geo.hu-berlin.de
committed
def moveToPreviousTSD(self):
for tsd in reversed(self.timeSeries()[:]):
if tsd < self.currentDate() and tsd.isVisible():
self.setCurrentDate(tsd)
return
s = ""

benjamin.jakimow@geo.hu-berlin.de
committed
def moveToNextTSDFast(self):
visible = list([tsd for tsd in self.timeSeries() if tsd.isVisible() and tsd > self.currentDate()])
if len(visible) > 0 and self.mMpMV > 0:
i = min(self.mMpMV-1, len(visible)-1)
self.setCurrentDate(visible[i])

benjamin.jakimow@geo.hu-berlin.de
committed
def moveToPreviousTSDFast(self):
visible = list(reversed([tsd for tsd in self.timeSeries() if tsd.isVisible() and tsd < self.currentDate()]))
if len(visible) > 0 and self.mMpMV > 0:
i = min(self.mMpMV - 1, len(visible)-1)
self.setCurrentDate(visible[i])

benjamin.jakimow@geo.hu-berlin.de
committed
def moveToFirstTSD(self):
for tsd in self.timeSeries()[:]:
if tsd.isVisible():
self.setCurrentDate(tsd)
return
s = ""
def moveToLastTSD(self):
for tsd in reversed(self.timeSeries()[:]):
if tsd.isVisible():
self.setCurrentDate(tsd)
return
s = ""
def setCurrentDate(self, tsd:TimeSeriesDate)->TimeSeriesDate:
Sets the current TimeSeriesDate, i.e. the "center" date of all dates to be shown
:param tsd: TimeSeriesDate
:return: TimeSeriesDate
assert isinstance(tsd, TimeSeriesDate)

benjamin.jakimow@geo.hu-berlin.de
committed
b = tsd != self.mCurrentDate
self.mCurrentDate = tsd

benjamin.jakimow@geo.hu-berlin.de
committed
if b:
self._updateCanvasDates()

Benjamin Jakimow
committed
i = self.mTimeSeries[:].index(self.mCurrentDate) + 1
if self.mTimeSlider.value() != i:
self.mTimeSlider.setValue(i)
self.sigCurrentDateChanged.emit(self.mCurrentDate)

Benjamin Jakimow
committed
if isinstance(self.currentDate(), TimeSeriesDate):
i = self.timeSeries()[:].index(self.currentDate())
canForward = i < len(self.mTimeSeries) - 1
canBackward = i > 0
else:
canForward = canBackward = False
for a in [self.actionForward, self.actionForwardFast, self.actionLastDate]:
a.setEnabled(canForward)
for a in [self.actionBackward, self.actionBackwardFast, self.actionFirstDate]:
a.setEnabled(canBackward)
return self.mCurrentDate

benjamin.jakimow@geo.hu-berlin.de
committed

Benjamin Jakimow
committed
def timeSlider(self)->QSlider:
return self.mTimeSlider
def currentDate(self)->TimeSeriesDate:
Returns the current TimeSeriesDate
:return: TimeSeriesDate
return self.mCurrentDate

benjamin.jakimow@geo.hu-berlin.de
committed
def addMapView(self, mapView:MapView)->MapView:
Adds a MapView
:param mapView: MapView
:return: MapView
assert isinstance(mapView, MapView)
if mapView not in self.mMapViews:

benjamin.jakimow@geo.hu-berlin.de
committed
self.mMapViews.append(mapView)

benjamin.jakimow@geo.hu-berlin.de
committed
mapView.setMapWidget(self)

benjamin.jakimow@geo.hu-berlin.de
committed
# connect signals
mapView.sigCanvasAppearanceChanged.connect(self._updateCanvasAppearance)
mapView.sigCrosshairChanged.connect(self._updateCrosshair)
self._updateGrid()
self._updateCrosshair(mapView=mapView)
self.sigMapViewsChanged.emit()
self.sigMapViewAdded.emit(mapView)
return mapView
def removeMapView(self, mapView:MapView)->MapView:
Removes a MapView
:param mapView: Mapview
:return: MapView
if mapView in self.mMapViews:
self.mMapViews.remove(mapView)
mapView.setMapWidget(None)
# disconnect signals
self._updateGrid()
self.sigMapViewsChanged.emit()
self.sigMapViewRemoved.emit(mapView)
return mapView
def mapViews(self)->list:
Returns a list of all MapViews
:return: [list-of-MapViews]
return self.mMapViews[:]
def syncQGISCanvasCenter(self, qgisChanged:bool):
if self.mSyncLock:
return
iface = qgis.utils.iface
assert isinstance(iface, QgisInterface)
c = iface.mapCanvas()
if not isinstance(c, QgsMapCanvas):
return
tsvCenter = self.spatialExtent().spatialCenter()
qgsCenter = SpatialExtent.fromMapCanvas(c).spatialCenter()
if qgisChanged:
# change EOTSV
if tsvCenter.crs().isValid():
self.mSyncLock = True
qgsCenter = qgsCenter.toCrs(tsvCenter.crs())
if isinstance(qgsCenter, SpatialPoint):
self.setSpatialCenter(qgsCenter)
QApplication.processEvents()
self.mSyncLock = False
else:
# change QGIS
if qgsCenter.crs().isValid():
self.mSyncLock = True
tsvCenter = tsvCenter.toCrs(qgsCenter.crs())
if isinstance(tsvCenter, SpatialPoint):
c.setCenter(tsvCenter)
QApplication.processEvents()
self.mSyncLock = False
def _createMapCanvas(self)->MapCanvas:
mapCanvas = MapCanvas()
mapCanvas.setMapLayerStore(self.mMapLayerStore)

Benjamin Jakimow
committed
mapCanvas.mInfoItem.setTextFormat(self.mapTextFormat())
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
# set general canvas properties
mapCanvas.setFixedSize(self.mMapSize)
mapCanvas.setDestinationCrs(self.mCrs)
mapCanvas.setSpatialExtent(self.mSpatialExtent)
# activate the current map tool
mapTools = mapCanvas.mapTools()
mapTools.activate(self.mMapToolKey)
mt = mapCanvas.mapTool()
if isinstance(mt, QgsMapToolSelect):
mt.setSelectionMode(self.mMapToolMode)
# connect signals
self._connectCanvasSignals(mapCanvas)
return mapCanvas
def _connectCanvasSignals(self, mapCanvas:MapCanvas):
mapCanvas.sigSpatialExtentChanged.connect(self.setSpatialExtent)
mapCanvas.sigDestinationCrsChanged.connect(self.setCrs)
mapCanvas.sigCrosshairPositionChanged.connect(self.onCrosshairPositionChanged)
mapCanvas.mapTools().mtCursorLocation.sigLocationRequest[SpatialPoint, QgsMapCanvas].connect(self.sigCurrentLocationChanged)
def _disconnectCanvasSignals(self, mapCanvas:MapCanvas):
mapCanvas.sigSpatialExtentChanged.disconnect(self.setSpatialExtent)
mapCanvas.sigDestinationCrsChanged.disconnect(self.setCrs)
mapCanvas.sigCrosshairPositionChanged.disconnect(self.onCrosshairPositionChanged)
mapCanvas.mapTools().mtCursorLocation.sigLocationRequest[SpatialPoint, QgsMapCanvas].disconnect(
self.sigCurrentLocationChanged)
def onCrosshairPositionChanged(self, spatialPoint:SpatialPoint):
canvas = self.sender()
if self.mCrosshairPosition != spatialPoint:
self.setCrosshairPosition(spatialPoint)
self.sigCrosshairPositionChanged[SpatialPoint, MapCanvas].emit(self.mCrosshairPosition, canvas)
def setCurrentLayer(self, layer:QgsMapLayer):
for mapView in self.mapViews():
mapView.setCurrentLayer(layer)
def setCrosshairPosition(self, spatialPoint)->SpatialPoint:
spatialPoint = spatialPoint.toCrs(self.crs())
if self.mCrosshairPosition != spatialPoint:
self.mCrosshairPosition = spatialPoint
for canvas in self.mapCanvases():
assert isinstance(canvas, MapCanvas)
canvas.setCrosshairPosition(spatialPoint)
self.sigCrosshairPositionChanged[SpatialPoint].emit(self.mCrosshairPosition)
return self.crosshairPosition()
def crosshairPosition(self)->SpatialPoint:
return self.mCrosshairPosition
def _updateGrid(self):
import time
t0 = time.time()

Benjamin Jakimow
committed
oldCanvases = self._updateLayerCache()

Benjamin Jakimow
committed
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
# crop grid
if self.mViewMode == MapWidget.ViewMode.MapViewByRows:
nc = self.mMpMV
nr = len(self.mapViews())
else:
raise NotImplementedError()
toRemove = []
for row in range(nr, self.mGrid.rowCount()):
for col in range(self.mGrid.columnCount()):
item = self.mGrid.itemAtPosition(row, col)
if isinstance(item, QLayoutItem) and isinstance(item.widget(), QWidget):
toRemove.append(item.widget())
for col in range(nc, self.mGrid.columnCount()):
for row in range(self.mGrid.rowCount()):
item = self.mGrid.itemAtPosition(row, col)
if isinstance(item, QLayoutItem) and isinstance(item.widget(), QWidget):
toRemove.append(item.widget())
for w in toRemove:
self.mGrid.removeWidget(w)
w.setParent(None)
w.setVisible(False)
usedCanvases = []
if self.mViewMode == MapWidget.ViewMode.MapViewByRows:
for row, mv in enumerate(self.mMapViews):
assert isinstance(mv, MapView)
self.mCanvases[mv] = []
for col in range(self.mMpMV):
item = self.mGrid.itemAtPosition(row, col)
if isinstance(item, QLayoutItem) and isinstance(item.widget(), MapCanvas):
c = item.widget()
else:
c = self._createMapCanvas()
self.mGrid.addWidget(c, row, col)
assert isinstance(c, MapCanvas)
#c.setFixedSize(self.mMapSize)
c.setTSD(None)
c.setMapView(mv)
usedCanvases.append(c)
self.mCanvases[mv].append(c)
else:
raise NotImplementedError()
t1 = time.time()
self._updateCanvasDates()
t2 = time.time()
self._updateWidgetSize()
t3 = time.time()
s = ""
# remove old canvases
for c in oldCanvases:
if c not in usedCanvases:
try:
self._disconnectCanvasSignals(c)
except:
pass
t4 = time.time()

Benjamin Jakimow
committed
if False:
print('t1: {}'.format(t1 - t0))
print('t2: {}'.format(t2 - t1))
print('t3: {}'.format(t3 - t2))
print('t4: {}'.format(t4 - t3))

Benjamin Jakimow
committed
def _updateWidgetSize(self):
self.mGrid.update()
# self.setMaximumSize(self.sizeHint())

Benjamin Jakimow
committed
#if False and self.parentWidget():
if True:
w = self
assert isinstance(w, QWidget)
rect = QGuiApplication.primaryScreen().geometry()
maxw, maxh = 0.66*rect.width(), 0.66*rect.height()
hint = self.sizeHint()
minw, minh = min(hint.width(), maxw), min(hint.height(), maxh)
w.setMinimumSize(minw, minh)
#w.setFixedSize(self.sizeHint())
w.layout().update()
w.update()

Benjamin Jakimow
committed
def _updateLayerCache(self)->list:
canvases = self.findChildren(MapCanvas)
for c in canvases:
assert isinstance(c, MapCanvas)
self.mMapLayerCache[self._layerListKey(c)] = c.layers()
return canvases

Benjamin Jakimow
committed
def _layerListKey(self, canvas:MapCanvas):
return (canvas.mapView(), canvas.tsd())

Benjamin Jakimow
committed
def _updateCanvasDates(self, updateLayerCache=True):
visibleBefore = self.visibleTSDs()
bTSDChanged = False

Benjamin Jakimow
committed
if updateLayerCache:
self._updateLayerCache()
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
if not (isinstance(self.mCurrentDate, TimeSeriesDate) and isinstance(self.timeSeries(), TimeSeries)):
for c in self.findChildren(MapCanvas):
assert isinstance(c, MapCanvas)
c.setTSD(None)
bTSDChanged = True
else:
visible = [tsd for tsd in self.timeSeries() if tsd.isVisible()]
t = self.mCurrentDate.date()
visible = sorted(visible, key=lambda tsd: abs(tsd.date() - t))
visible = visible[0:min(len(visible), self.mMpMV)]
visible = sorted(visible)
# set TSD of remaining canvases to None
while len(visible) < self.mMpMV:
visible.append(None)
for mapView in self.mapViews():
for tsd, canvas in zip(visible, self.mCanvases[mapView]):
assert isinstance(tsd, TimeSeriesDate) or tsd is None
assert isinstance(canvas, MapCanvas)
if canvas.tsd() != tsd:
canvas.setTSD(tsd)

Benjamin Jakimow
committed
key = self._layerListKey(canvas)
if key in self.mMapLayerCache.keys():
canvas.setLayers(self.mMapLayerCache.pop(key))
bTSDChanged = True
# canvas.setLayers()
if bTSDChanged:
self._updateCanvasAppearance()
visible2 = self.visibleTSDs()
if visible2 != visibleBefore:
self.sigVisibleDatesChanged.emit(visible2)

Benjamin Jakimow
committed
self._freeUnusedMapLayers()
def _freeUnusedMapLayers(self):
layers = [l for l in self.mMapLayerStore.mapLayers().values() if isinstance(l, SensorProxyLayer)]
needed = self.currentLayers()
toRemove = [l for l in layers if isinstance(l, SensorProxyLayer) and l not in needed]
# todo: use a kind of caching
# remove layers from MapLayerCache and MapLayerStore
for mv in self.mMapLayerCache.keys():
layers = [l for l in self.mMapLayerCache[mv] if l not in toRemove]
self.mMapLayerCache[mv] = layers
self.mMapLayerStore.removeMapLayers(toRemove)
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
def _updateCrosshair(self, mapView=None):
if isinstance(mapView, MapView):
mapViews = [mapView]
else:
mapViews = self.mapViews()
for mapView in mapViews:
assert isinstance(mapView, MapView)
style = mapView.crosshairStyle()
assert isinstance(style, CrosshairStyle)
for canvas in self.mCanvases[mapView]:
assert isinstance(canvas, MapCanvas)
item = canvas.mCrosshairItem
item.setVisibility(style.mShow)
assert isinstance(item, CrosshairMapCanvasItem)
item.setCrosshairStyle(style)
canvas.addToRefreshPipeLine(MapCanvas.Command.UpdateMapItems)
def _updateCanvasAppearance(self, mapView=None):
if isinstance(mapView, MapView):
mapViews = [mapView]
else:
mapViews = self.mapViews()
for mapView in mapViews:
assert isinstance(mapView, MapView)
v = mapView.isVisible()
bg = mapView.mapBackgroundColor()

Benjamin Jakimow
committed
tf = mapView.mapTextFormat()
showDate = mapView.optionShowDate.isChecked()
showName = mapView.optionShowMapViewName.isChecked()
showSensor = mapView.optionShowSensorName.isChecked()
for canvas in self.mCanvases[mapView]:
assert isinstance(canvas, MapCanvas)
# set overall visibility
if canvas.isVisible() != v:
canvas.setVisible(v)
tsd = canvas.tsd()
if canvas.canvasColor() != bg:
canvas.addToRefreshPipeLine(mapView.mapBackgroundColor())
# set info text
info = canvas.infoItem()
assert isinstance(info, MapCanvasInfoItem)

Benjamin Jakimow
committed
info.setTextFormat(tf)
uc = []
lc = []
if isinstance(tsd, TimeSeriesDate):
if showDate:
uc += ['{}'.format(tsd.date())]
if showName:
lc += ['{}'.format(mapView.title(maskNewLines=False))]
if showSensor:
uc += ['{}'.format(tsd.sensor().name())]
uc = '\n'.join(uc)
lc = '\n'.join(lc)

Benjamin Jakimow
committed
info.setUpperCenter(uc)
info.setLowerCenter(lc)
canvas.addToRefreshPipeLine(MapCanvas.Command.UpdateMapItems)
class MapViewDock(QgsDockWidget, loadUI('mapviewdock.ui')):
sigMapViewAdded = pyqtSignal(MapView)
sigMapViewRemoved = pyqtSignal(MapView)
sigShowProfiles = pyqtSignal(SpatialPoint, MapCanvas, str)
sigMapCanvasColorChanged = pyqtSignal(QColor)

Benjamin Jakimow
committed
sigMapCanvasTextFormatChanged = pyqtSignal(QgsTextFormat)
sigSpatialExtentChanged = pyqtSignal(SpatialExtent)
sigCrsChanged = pyqtSignal(QgsCoordinateReferenceSystem)
sigMapSizeChanged = pyqtSignal(QSize)
sigMapsPerMapViewChanged = pyqtSignal(int)

Benjamin Jakimow
committed
sigMapTextFormatChanged = pyqtSignal(QgsTextFormat)
def setTimeSeries(self, timeSeries:TimeSeries):
assert isinstance(timeSeries, TimeSeries)
self.mTimeSeries = timeSeries
self.mTimeSeries.sigSensorAdded.connect(self.addSensor)
self.mTimeSeries.sigSensorRemoved.connect(self.removeSensor)
def __init__(self, parent=None):
super(MapViewDock, self).__init__(parent)
self.setupUi(self)
self.baseTitle = self.windowTitle()
self.btnAddMapView.setDefaultAction(self.actionAddMapView)
self.btnRemoveMapView.setDefaultAction(self.actionRemoveMapView)
self.btnCrs.crsChanged.connect(self.sigCrsChanged)
self.btnMapCanvasColor.colorChanged.connect(self.sigMapCanvasColorChanged)

Benjamin Jakimow
committed
self.btnTextFormat.changed.connect(lambda *args: self.sigMapTextFormatChanged.emit(self.mapTextFormat()))
self.btnApplySizeChanges.clicked.connect(self.onApplyButtonClicked)
self.actionAddMapView.triggered.connect(self.createMapView)
self.actionRemoveMapView.triggered.connect(lambda: self.removeMapView(self.currentMapView()) if self.currentMapView() else None)
self.toolBox.currentChanged.connect(self.onToolboxIndexChanged)
self.spinBoxMapSizeX.valueChanged.connect(lambda: self.onMapSizeChanged('X'))
self.spinBoxMapSizeY.valueChanged.connect(lambda: self.onMapSizeChanged('Y'))
self.mLastMapSize = self.mapSize()

Benjamin Jakimow
committed
self.mLastNDatesPerMapView = self.sbMpMV.value()
self.mTimeSeries = None
self.mMapWidget = None

Benjamin Jakimow
committed
def onApplyButtonClicked(self):
self.sigMapSizeChanged.emit(QSize(self.spinBoxMapSizeX.value(), self.spinBoxMapSizeY.value()))
self.sigMapsPerMapViewChanged.emit(self.mapsPerMapView())
def setMapWidget(self, mw)->MapWidget:
"""
Connects this MapViewDock with a MapWidget
:param mw: MapWidget
:return:
"""
assert isinstance(mw, MapWidget)
assert mw.timeSeries() == self.mTimeSeries, 'Set the time series first!'
self.mMapWidget = mw
self.sigCrsChanged.connect(mw.setCrs)
mw.sigCRSChanged.connect(self.setCrs)
self.sigMapSizeChanged.connect(mw.setMapSize)
mw.sigMapSizeChanged.connect(self.setMapSize)

Benjamin Jakimow
committed
self.sigMapTextFormatChanged.connect(mw.setMapTextFormat)
mw.sigMapTextFormatChanged.connect(self.setMapTextFormat)
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
self.sigMapsPerMapViewChanged.connect(mw.setMapsPerMapView)
mw.sigMapsPerMapViewChanged.connect(self.setMapsPerMapView)
self.sigMapViewAdded.connect(mw.addMapView)
self.sigMapViewRemoved.connect(mw.removeMapView)
mw.sigMapViewAdded.connect(self.addMapView)
mw.sigMapViewRemoved.connect(self.removeMapView)
for mapView in mw.mapViews():
self.addMapView(mapView)
return self.mMapWidget
def mapWidget(self):
"""
Returns the connected MapWidget
:return: MapWidget
"""
return self.mMapWidget
def mapViews(self)->list:
"""
Returns the defined MapViews
:return: [list-of-MapViews]
"""
assert isinstance(self.toolBox, QToolBox)
mapViews = []
for i in range(self.toolBox.count()):
item = self.toolBox.widget(i)
if isinstance(item, MapView):
mapViews.append(item)
return mapViews
def mapCanvases(self)->list:
"""
Returns all MapCanvases from all MapViews
:return: [list-of-MapCanvases]
"""
maps = []
for mapView in self.mapViews():
assert isinstance(mapView, MapView)
maps.extend(mapView.mapCanvases())
return maps
def setCrs(self, crs):
if isinstance(crs, QgsCoordinateReferenceSystem):
old = self.btnCrs.crs()
if old != crs:
self.btnCrs.setCrs(crs)
self.btnCrs.setLayerCrs(crs)
def mapsPerMapView(self)->int:
return self.sbMpMV.value()
def setMapsPerMapView(self, n:int):
assert n >= 0

Benjamin Jakimow
committed
if self.sbMpMV.value != n:
self.sbMpMV.setValue(n)

Benjamin Jakimow
committed
self.mLastNDatesPerMapView = n
def setMapTextFormat(self, textFormat:QgsTextFormat):
if not equalTextFormats(textFormat, self.mapTextFormat()):
self.btnTextFormat.setTextFormat(textFormat)
def mapTextFormat(self)->QgsTextFormat:
return self.btnTextFormat.textFormat()
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
def setMapSize(self, size):
assert isinstance(size, QSize)
ws = [self.spinBoxMapSizeX, self.spinBoxMapSizeY]
oldSize = self.mapSize()
b = oldSize != size
for w in ws:
w.blockSignals(True)
self.spinBoxMapSizeX.setValue(size.width()),
self.spinBoxMapSizeY.setValue(size.height())
self.mLastMapSize = QSize(size)
for w in ws:
w.blockSignals(False)
self.mLastMapSize = QSize(size)
if b:
self.sigMapSizeChanged.emit(size)
def onMapSizeChanged(self, dim):
newSize = self.mapSize()
#1. set size of other dimension accordingly
if dim is not None:
if self.checkBoxKeepSubsetAspectRatio.isChecked():
if dim == 'X':
vOld = self.mLastMapSize.width()
vNew = newSize.width()
targetSpinBox = self.spinBoxMapSizeY
elif dim == 'Y':
vOld = self.mLastMapSize.height()
vNew = newSize.height()
targetSpinBox = self.spinBoxMapSizeX
oldState = targetSpinBox.blockSignals(True)
targetSpinBox.setValue(int(round(float(vNew) / vOld * targetSpinBox.value())))
targetSpinBox.blockSignals(oldState)
newSize = self.mapSize()
if newSize != self.mLastMapSize:
self.btnApplySizeChanges.setEnabled(True)
else:
self.sigMapSizeChanged.emit(self.mapSize())
self.btnApplySizeChanges.setEnabled(False)
self.setMapSize(newSize)
def mapSize(self)->QSize:
return QSize(self.spinBoxMapSizeX.value(),
self.spinBoxMapSizeY.value())
def dummySlot(self):
s =""
def onMapViewsRemoved(self, mapViews):
for mapView in mapViews:
idx = self.stackedWidget.indexOf(mapView.ui)
if idx >= 0:
self.stackedWidget.removeWidget(mapView.ui)
mapView.ui.close()
else:
s = ""
self.actionRemoveMapView.setEnabled(len(self.mMapViews) > 0)
def mapBackgroundColor(self)->QColor:
"""
Returns the map canvas background color
:return: QColor
"""
return self.btnMapCanvasColor.color()
def setMapBackgroundColor(self, color:QColor):
"""
Sets the MapCanvas background color
:param color: QColor
"""
if color != self.mapBackgroundColor():
self.btnMapCanvasColor.setColor(color)
def setMapTextColor(self, color:QColor):
"""
Sets the map text color
:param color: QColor
:return: QColor
"""
if color != self.mapTextColor():
self.btnMapTextColor.setColor(color)
return self.mapTextColor()
def mapTextColor(self)->QColor:
"""
Returns the map text color.
:return: QColor
"""
return self.btnMapTextColor.color()
def onMapViewsAdded(self, mapViews):
nextShown = None
for mapView in mapViews:
mapView.sigTitleChanged.connect(self.updateTitle)
self.stackedWidget.addWidget(mapView.ui)
if nextShown is None:
nextShown = mapView
contents = mapView.ui.scrollAreaWidgetContents
size = contents.size()
hint = contents.sizeHint()
#mapView.ui.scrollArea.update()
s = ""
#setMinimumSize(mapView.ui.scrollAreaWidgetContents.sizeHint())
#hint = contents.sizeHint()
#contents.setMinimumSize(hint)
if isinstance(nextShown, MapView):
self.setCurrentMapView(nextShown)
for mapView in mapViews:
self.sigMapViewAdded.emit(mapView)
def updateButtons(self, *args):
b = len(self.mMapViews) > 0
self.actionRemoveMapView.setEnabled(b)
self.actionApplyStyles.setEnabled(b)
self.actionHighlightMapView.setEnabled(b)
def createMapView(self, name:str=None)->MapView:
"""
Create a new MapView
:return: MapView
"""
mapView = MapView()
n = len(self.mapViews()) + 1
if isinstance(name, str) and len(name) > 0:
title = name
else:
title = 'Map View {}'.format(n)
while title in [m.title() for m in self.mapViews()]:
n += 1
title = 'Map View {}'.format(n)
if n == 1:
mapView.optionShowDate.setChecked(True)
mapView.optionShowSensorName.setChecked(True)
mapView.setTitle(title)
mapView.sigShowProfiles.connect(self.sigShowProfiles)
mapView.setTimeSeries(self.mTimeSeries)
self.addMapView(mapView)
return mapView
def onInfoOptionToggled(self):
self.sigMapInfoChanged.emit()
s = ""
def addMapView(self, mapView:MapView):
"""
Adds a MapView
:param mapView: MapView
"""
assert isinstance(mapView, MapView)
if mapView not in self:
mapView.sigTitleChanged.connect(lambda *args, mv=mapView: self.onMapViewUpdated(mv))
#mapView.sigVisibilityChanged.connect(lambda *args, mv=mapView: self.onMapViewUpdated(mv))
mapView.sigCanvasAppearanceChanged.connect(lambda *args, mv=mapView: self.onMapViewUpdated(mv))
self.sigMapCanvasColorChanged.connect(mapView.setMapBackgroundColor)

Benjamin Jakimow
committed
self.sigMapCanvasTextFormatChanged.connect(mapView.setMapTextFormat)
i = self.toolBox.addItem(mapView, mapView.windowIcon(), mapView.title())
self.toolBox.setCurrentIndex(i)
self.onMapViewUpdated(mapView)
if len(self.mapViews()) == 1:
self.setMapTextFormat(mapView.mapTextFormat())
self.sigMapViewAdded.emit(mapView)
def onToolboxIndexChanged(self):
b = isinstance(self.toolBox.currentWidget(), MapView)
self.actionRemoveMapView.setEnabled(b)
def onMapViewUpdated(self, mapView:MapView):
"""
Handles updates that react on MapView changes
:param mapView: MapView to make the update for
"""
numMV = 0
for i in range(self.toolBox.count()):
item = self.toolBox.widget(i)
if isinstance(item, MapView):
numMV += 1
if item == mapView:
if mapView.isVisible():
icon = QIcon(":/timeseriesviewer/icons/mapview.svg")
else:
icon = QIcon(":/timeseriesviewer/icons/mapviewHidden.svg")
self.toolBox.setItemIcon(i, icon)
self.toolBox.setItemText(i, 'Map View {} "{}"'.format(numMV, mapView.title()))
break
def removeMapView(self, mapView:MapView)->MapView:
"""
Removes a MapView
:param mapView: MapView
:return: MapView
"""
if mapView in self.mapViews():
for i in range(self.toolBox.count()):
w = self.toolBox.widget(i)
if isinstance(w, MapView) and w == mapView:
self.toolBox.removeItem(i)
mapView.close()
if self.toolBox.count() >= i:
self.toolBox.setCurrentIndex(min(i, self.toolBox.count()-1))
self.sigMapViewRemoved.emit(mapView)
return mapView
def __len__(self)->int:
"""
Returns the number of MapViews
:return: int
"""
return len(self.mapViews())
def __iter__(self):
"""
Provides an iterator over all MapViews
:return:
"""
return iter(self.mapViews())
def __getitem__(self, slice):
return self.mapViews()[slice]
def __contains__(self, mapView):
return mapView in self.mapViews()
def index(self, mapView):
assert isinstance(mapView, MapView)
return self.mapViews().index(mapView)
def addSensor(self, sensor:SensorInstrument):
"""
Adds a new SensorInstrument
:param sensor: SensorInstrument
"""
for mapView in self.mapViews():
mapView.addSensor(sensor)
def removeSensor(self, sensor:SensorInstrument):
"""
Removes a Sensor
:param sensor: SensorInstrument
"""
for mapView in self.mMapViews:
mapView.removeSensor(sensor)
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
def applyStyles(self):
for mapView in self.mMapViews:
mapView.applyStyles()
def setCrosshairStyle(self, crosshairStyle):
for mapView in self.mMapViews:
mapView.setCrosshairStyle(crosshairStyle)
def setShowCrosshair(self, b):
for mapView in self.mMapViews:
mapView.setCrosshairVisibility(b)
def index(self, mapView):
assert isinstance(mapView, MapView)
return self.mapViewsDefinitions.index(mapView)
def setCurrentMapView(self, mapView):
assert isinstance(mapView, MapView) and mapView in self.mapViews()
self.toolBox.setCurrentWidget(mapView)
self.updateTitle()
def updateTitle(self, *args):
# self.btnToggleMapViewVisibility.setChecked(mapView)
mapView = self.currentMapView()
if isinstance(mapView, MapView):
title = '{} | {}'.format(self.baseTitle, mapView.title())
else:
title = self.baseTitle
self.setWindowTitle(title)
def currentMapView(self):
w = self.toolBox.currentWidget()
if isinstance(w, MapView):
return w
return None