Dacă plugin-ul dvs. folosește propriile metode de a randa un strat de hartă, scrierea propriului tip de strat, bazat pe QgsPluginLayer, ar putea fi cel mai bun mod de a implementa acest lucru.
Verificați corectitudinea și elaborați cazuri de corectă utilizare pentru QgsPluginLayer, ...
Mai jos este un exemplu minimal de implementare pentru QgsPluginLayer. Acesta este un extras din exemplu de plugin filigran:
class WatermarkPluginLayer(QgsPluginLayer):
LAYER_TYPE="watermark"
def __init__(self):
QgsPluginLayer.__init__(self, WatermarkPluginLayer.LAYER_TYPE, \
"Watermark plugin layer")
self.setValid(True)
def draw(self, rendererContext):
image = QImage("myimage.png")
painter = rendererContext.painter()
painter.save()
painter.drawImage(10, 10, image)
painter.restore()
return True
Methods for reading and writing specific information to the project file can also be added:
def readXml(self, node):
def writeXml(self, node, doc):
When loading a project containing such a layer, a factory class is needed:
class WatermarkPluginLayerType(QgsPluginLayerType):
def __init__(self):
QgsPluginLayerType.__init__(self, WatermarkPluginLayer.LAYER_TYPE)
def createLayer(self):
return WatermarkPluginLayer()
You can also add code for displaying custom information in the layer properties:
def showLayerProperties(self, layer):