3
我嘗試捕獲出現在Google地圖infowindow中的Streetview全景圖像。我創建了一個調用函數captureImage()的按鈕,但我努力通過它返回到HTML的var = img變量。傳遞canvas.toDataURL返回div
我認爲存在本地變量「contentString」和「content」存在問題。我應該將captureImage()函數寫入initialize()嗎?謝謝。
我的代碼如下:
function initialize() {
//code here
var contentString = '<input type="button" value="Grab this picture" onClick="captureImage()" /> <div id="content" style="width:300px;height:400px;"></div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
//code here
}
function captureImage()
{
var canvas = document.getElementById("content");
var img = canvas.toDataURL("image/png");
document.write('<img src="'+img+'"/>');
}
HTML:
<div id="dialog" title="Image box">
<p>Here is the image from Streetview :</p>
<img scr=""></img>
</div>
從div中捕獲是不可能的。事情不會這樣。 – xiaoyi
謝謝我不知道。另一種方法是請求Google Map Image API。 https://developers.google.com/maps/documentation/imageapis/ – Florent
另一種方法是將HTML內容呈現到畫布中,然後使用'canvas.toDataURL(「image/png」)將'canvas'元素導出爲JPEG ;」。 – Florent