I want to use my map for further offline calculations. I used the below code referred from ' https://gis.stackexchange.com/questions/313382/click-event-on-maps-with-folium-and-information-retrieval/377726#377726' by user @Vlad Chuenko. When I'm running the below code I'm not getting any error and desired output. How can I use it as offline!

from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
from folium.plugins import Draw
import folium, io, sys, json
import os

dirname = os.path.dirname(__file__)
dir = r"data\map_update.html"
save_location = os.path.join(dirname, dir)

def saveMap():

    if __name__ == '__main__':
        app = QtWidgets.QApplication(sys.argv)

        m = folium.Map(location=[19.5937,79.9629], zoom_start=5)

        draw = Draw(
                'rectangle': True,
                'marker': True,
            edit_options={'edit': False})

        data = io.BytesIO()
        m.save(data, close_file=False)

        class WebEnginePage(QtWebEngineWidgets.QWebEnginePage):
            def javaScriptConsoleMessage(self, level, msg, line, sourceID):
                coords_dict = json.loads(msg)
                coords = coords_dict['geometry']['coordinates'][0]

    view = QtWebEngineWidgets.QWebEngineView()
    page = WebEnginePage(view)

  • Thank you for your time. I tried that, but no change not getting any output, folder is still empty. Is there any other way to do it!!
    – Mithra
    Commented Feb 2, 2022 at 8:49
  • 1
    Your code will not do anything. Everything after save_location = os.path.join(dirname, dir) is inside the def saveMap(): function which you never call. You have if __name__ == '__main__': inside a function which doesn't make sense.
    – user2856
    Commented Feb 2, 2022 at 9:06
  • I'm new to PyQt5. Is there is any way to save this map for offline calculations?
    – Mithra
    Commented Feb 7, 2022 at 9:12
  • Have a go at fixing your code based on the observations I made previously - make sure you call saveMap() and move the if __name__ == '__main__': out of the function.
    – user2856
    Commented Feb 8, 2022 at 6:50


Your Answer

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

Browse other questions tagged or ask your own question.