pyqt5 和 3D 地图 HTML 渲染



我尝试在Windows 7上使用PyQt5版本5.8.2从HTML显示3D地图。我使用以下代码。我可以看到 3D 地球,但渲染不正确(不连续 - 见附图(。代码有什么问题?

我尝试使用 PyQt5 的 5.9 版,但出现错误([10552:11880:0820/203012.737:ERROR:gl_context_wgl.cc(78(] 无法共享 GL 上下文(。任何建议为什么我收到此错误?

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import QWidget,QVBoxLayout, QApplication
import bs4
maphtml = '''
<!DOCTYPE HTML>
<html>
<head>
<script src="http://www.webglearth.com/v2/api.js"></script>
<script>
function initialize() {
var earth = new WE.map('earth_div');
WE.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
attribution: '© OpenStreetMap contributors'
}).addTo(earth);
}
</script>
<style>
html, body{padding: 0; margin: 0;}
#earth_div{top: 0; right: 0; bottom: 0; left: 0; position: absolute !important;}
</style>
<title>WebGL Earth API: Hello World</title>
</head>
<body onload="initialize()">
<div id="earth_div"></div>
</body>
</html>
'''
class Browser(QApplication):
def __init__(self):
QApplication.__init__(self, [])
self.window = QWidget()
self.web = QWebEngineView(self.window)
self.web.setHtml(maphtml)
self.layout = QVBoxLayout(self.window)
self.layout.addWidget(self.web)
self.window.show()
self.exec_()
Browser()

渲染不正确的 3D 地球

试试这个(它对我有用(:

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import QWidget,QVBoxLayout, QApplication
# import bs4
maphtml = '''
<!DOCTYPE HTML>
<html>
<head>
<script src="http://www.webglearth.com/v2/api.js"></script>
<script>
function initialize() {
var earth = new WE.map('earth_div');
WE.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
attribution: '© OpenStreetMap contributors'
}).addTo(earth);
}
</script>
<style>
html, body{padding: 0; margin: 0;}
#earth_div{top: 0; right: 0; bottom: 0; left: 0; position: absolute !important;}
</style>
<title>WebGL Earth API: Hello World</title>
</head>
<body onload="initialize()">
<div id="earth_div"></div>
</body>
</html>
'''
class Browser(QApplication):
def __init__(self):
QApplication.__init__(self, [])
self.window = QWidget()
self.web = QWebEngineView(self.window)
self.web.setHtml(maphtml)
self.layout = QVBoxLayout(self.window)
self.layout.addWidget(self.web)
self.window.show()
import sys
if __name__ == "__main__":
app = Browser()
sys.exit(app.exec_())

最新更新