I have a problem on the development of a python plugin, I'm trying to display the OpenStreetMap map behind layers, only the map is not synchronized with the layers, it can't find it or even the location.
The geographical position of the map does not correspond to that of my layers.
#Vlayer is defined above the code / Vlayer est définie au-dessus du code
urlWithParams = 'type=xyz&url=http://a.tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0&crs=EPSG3857'
maplayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms')
settings = QgsMapSettings()
settings.setLayers([vlayer,maplayer])
settings.setBackgroundColor(QColor(255, 255, 255))
settings.setOutputSize(QSize(800, 690))
settings.setExtent(vlayer.extent())
render = QgsMapRendererParallelJob(settings)
render.start()
render.waitForFinished()
img = render.renderedImage()
img.save(QgsApplication.qgisSettingsDirPath()+"python/plugins/nro_print/img/render.png", "png")
result: