2

I'm trying to program a PySide2 app and one of the features should be a map creator for offline usage.

I got a gps antenna and the data from it should be displayed offline.

But in first step the user can select maps with internet connection.

I've found several examples:

My plan is to get the map as png with bounds. The first link showing the procedure with png+bounds.

My example code:

from PySide2 import QtCore, QtGui, QtWidgets
import io
import sys
import folium
from folium.plugins import Draw
from PySide2.QtWebEngineWidgets import QWebEngineView


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        self.webView = QWebEngineView()
        # show webView on Window
        MainWindow.setCentralWidget(self.webView)
        # Map
        coordinate = (55, 7)
        self.map = folium.Map(
            tiles='OpenStreetMap',
            zoom_start=15,
            location=coordinate,
            png_enabled=False
        )

        self.draw = Draw(
            draw_options={
                'polyline': False,
                'rectangle': True,
                'polygon': False,
                'circle': False,
                'marker': False,
                'circlemarker': False},
            edit_options={'remove': True, 'edit': True, 'save': True, 'cancel': False})

        self.draw.add_to(self.map)

        data = io.BytesIO()
        self.map.save(data, close_file=False)

        view = self.webView
        view.setHtml(data.getvalue().decode('utf-8'))

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))


# Main
def main(self):
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    my = Ui_MainWindow()
    main(my)

I can draw a rectangle to the map, but i can not get the bounds of it...

self.map.get_bounds()

gives me

[[None, None], [None, None]]

So i have two problems, getting the boundaries from the rectangle and convert the rectangle_map to png.

how to save a map section in Python using folium

This link shows a possability.

Image

Maybe there is another way to do it ?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Nikololo
  • 21
  • 2

0 Answers0