pyqt5和3D地图HTML渲染

时间:2017-08-21 06:29:02

标签: html pyqt5

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

我尝试使用PyQt5的5.9版本,但是我遇到了错误([10552:11880:0820 / 203012.737:错误: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 earth with incorrect rendering

1 个答案:

答案 0 :(得分:0)

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

    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_())