无法打开使用 wxPython 在 folium 中生成的本地 HTML 文件 [英] Unable to open a local HTML file generated in folium using wxPython

查看:23
本文介绍了无法打开使用 wxPython 在 folium 中生成的本地 HTML 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试将 GPS 坐标绘制为地图上的标记并在 wxPython 中显示结果.

I am currently trying to plot GPS coordinates as markers on a map and displaying the result within wxPython.

我使用folium来绘制坐标标记并生成一个HTML文件:

I have used folium to plot coordinate markers and generate an HTML file:

import folium
fmap = folium.Map([-43.5321,172.6362], zoom_start=12)
folium.Marker([-43.5321,172.6362], popup='Marker1').add_to(fmap)
fmap.save('maparea.html')

我可以在 Firefox 中打开这个 HTML 文件,没有任何问题.

I am able to open this HTML file in Firefox without any issues.

我需要在 wxPython 中创建一个程序来显示这个 HTML 文件,我尝试实现以下代码:

I need to create a programme in wxPython to display this HTML file, and I tried implementing the following code:

import wx 
import wx.html2 

class MyBrowser(wx.Dialog): 
    def __init__(self, *args, **kwds): 
        wx.Dialog.__init__(self, *args, **kwds) 

        sizer = wx.BoxSizer(wx.VERTICAL) 
        self.browser = wx.html2.WebView.New(self)
        self.browser.LoadURL("maparea.html")
        sizer.Add(self.browser, 1, wx.EXPAND, 10) 

        self.SetSizer(sizer) 
        self.SetSize((1280, 720)) 

if __name__ == '__main__': 
  app = wx.App() 
  dialog = MyBrowser(None) 
  dialog.Show() 
  app.MainLoop() 

然而,我得到的只是一个空白页.如果我将代码中的 URL 更改为一个网站(例如 http://www.google.com),上面的代码没有问题.

However, all I get is a blank page. If I change the URL in the code to a website (e.g. http://www.google.com), the code above works without issues.

为什么我无法在 wxPython 中查看 HTML 文件?有没有另一种方法可以在 wxPython 中加载和显示 HTML 文件?我更喜欢使用 HTML 文件而不是在 wxPython 中显示屏幕截图,因为我想保留平移、缩放和点击地图中标记的能力.

Why am I unable to view the HTML file in wxPython? Is there another way to load and display an HTML file in wxPython? I would prefer to use the HTML file over displaying a screenshot in wxPython, since I would like to retain the ability pan, zoom and click on markers within the map.

(我在 Ubuntu 18.04 上运行 Python 3.6.8 和 wxPython 4.0.3 gtk3 (phoenix) wxWidgets 3.0.5.)

推荐答案

除了文件路径需要是 file:///url 之外,似乎还有一些无效字符的问题.
无需询问 folium.Marker 即可尝试,您应该会看到基督城的地图.

In addition to the file path needing to be a file:///url there appears to be some issue with an invalid character.
Try it without asking for the folium.Marker and you should see a map of Christchurch.

folium 将 Marker 用于单引号 ' 的错误字符,它在 var 声明中使用 ` 代替.即而不是

folium is using for the Marker the wrong character for a single quote ' it's using ` instead in it's var declarations. i.e. instead of

var html_280344edc4004eb6b0012ec2e57f9b85 = $('<div id="html_280344edc4004eb6b0012ec2e57f9b85" style="width: 100.0%; height: 100.0%;">Marker1</div>')[0]; 

它提供:

var html_280344edc4004eb6b0012ec2e57f9b85 = $(`<div id="html_280344edc4004eb6b0012ec2e57f9b85" style="width: 100.0%; height: 100.0%;">Marker1</div>`)[0];

您可以替换它们或使用 webbrowser 而不是 wx.html2

You can replace them or use webbrowser rather than wx.html2

这篇关于无法打开使用 wxPython 在 folium 中生成的本地 HTML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆