最近我和OpenLayers一起玩得很開心(http://www.nufosmatic.com),並且因爲討厭而無法解決。我甚至不確定問題在哪裏。OpenLayers 3.0中是否有一些可以禁用的硬件加速默認?
我需要生成一些靜態顯示:我正在將Java替換爲Java,並將其遷移到Python和JavaScript。我發現服用此網頁的截圖一個非常好的例子:
http://webscraping.com/blog/Webpage-screenshots-with-webkit/
它使用Qt「QWebview」來渲染,然後傾倒的網頁。它正在爲Windows XP x86上運行的Virtual Box下的Windows 7 x86_64(Python 2.7.6 x86)和Linux Fedora 20(Python 2.7.5)發佈OpenLayers 2實例。
然後這個星期OpenLayers 3發佈了,當然,我嘗試了這些新的例子(OL 2的例子Git頁面已經消失,但2.10例子似乎工作)。
我收到以下錯誤診斷出來的代碼,我貼在下面:
$ python webscrape_olprob.py
2.0 example
loaded the Generic plugin
saving simple_2_0.0.png
3.0 example
libGL error: failed to load driver: swrast
saving simple_3_0.0.png
似乎有硬件加速和此特定錯誤有一定的關係(「無法加載驅動程序:swrast)。
我想驗證OL3在Windows上也是(sorta/kinda/totally/not)。不幸的是,在可預見的未來,我設置了用於測試的Windows 7環境離我很遠(我討厭需要一個人在電腦前工作的電腦)。
我在這裏發佈,因爲這個論壇表現出優越的多樣性,這個問題可能是Qt/QWebview,VirtualBox,Fedora 20或OpenLayers。鑑於2.0「OSM」和3.0「簡單」又名「OSM」示例之間沒有太大區別,我的資金在OpenLayers上,其硬件加速要求(1)無法關閉[或者(2)可以被關閉,但沒有人抱怨過這種情況,但是指出文檔關閉此功能的指針還沒有出現在各種論壇中。
#
# http://webscraping.com/blog/Webpage-screenshots-with-webkit/
#
import sys
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
class Screenshot(QWebView):
def __init__(self):
self.app = QApplication(sys.argv)
QWebView.__init__(self)
self._loaded = False
self.loadFinished.connect(self._loadFinished)
def capture(self, url, output_file):
self.load(QUrl(url))
self.wait_load()
# set to webpage size
frame = self.page().mainFrame()
self.page().setViewportSize(frame.contentsSize())
# render image
image = QImage(self.page().viewportSize(), QImage.Format_ARGB32)
painter = QPainter(image)
frame.render(painter)
painter.end()
print 'saving', output_file
image.save(output_file)
def wait_load(self, delay=0):
# process app events until page loaded
while not self._loaded:
self.app.processEvents()
time.sleep(delay)
self._loaded = False
def _loadFinished(self, result):
self._loaded = True
s = Screenshot()
print "2.0 example"
s.capture('http://dev.openlayers.org/releases/OpenLayers-2.10/examples/osm.html', 'simple_2_0.0.png')
print "3.0 example"
s.capture('http://openlayers.org/en/v3.0.0/examples/simple.html', 'simple_3_0.0.png')
是
更新 - 冉在Windows操作系統上,並沒有得到任何警告(從Cygwin的殼實例化如下圖):
webkit/webscrape> c:/python27/python webscrape_olprob.py
2.0 example
saving simple_2_0.0.png
3.0 example
saving simple_3_0.0.png
然而,2.0例如渲染的地圖:
和3.0例子沒:
所以3.0仍然有在Windows ...問題,因爲3.0剛剛發佈,我想,我走了......
我需要測試渲染的建議,這必然要求我更改已發佈的示例。我不願意,因爲(1)我需要使用畫布,因爲我要定位的OL功能和(2)我正在尋找一些影響從引擎渲染的方式,因爲這是進行渲染的QWebView ..
謝謝。我只是通過練習來比較渲染器的行爲。 – Nufosmatic 2014-08-29 20:16:37