0

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)
        folium.LatLngPopup().add_to(m)

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

        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]
                print(coords)

    view = QtWebEngineWidgets.QWebEngineView()
    page = WebEnginePage(view)
    view.setPage(page)
    view.setHtml(data.getvalue().decode())
    view.show()
    sys.exit(app.exec_())
    m.save(save_location)

4
  • 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

0

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.