2017-07-31 238 views
0

該示例顯示如何將按鈕單擊事件綁定到畫布,然後返回圖像Example。我怎樣才能改變它,當我用永久鏈接調用openlayers時,它會自動將該圖像返回給我?我想使用一個簡單的從C++程序獲取請求來獲取圖像。我有 例如「#map = 12/1085115.28/6035092.46/0」作爲解析參數。有任何想法嗎? 感謝和問候 梅麗娜在openlayers中返回canvas(圖片)4

到目前爲止,我有參數解析

<!DOCTYPE html> 
<html> 
    <head> 
    <title>OpenStreetMap</title> 
    <link rel="stylesheet" href="https://openlayers.org/en/v4.2.0/css/ol.css" type="text/css"> 
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x --> 
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script> 
    <script src="https://openlayers.org/en/v4.2.0/build/ol.js"></script> 
    </head> 
    <body> 
    <div id="map" class="map"></div> 
    <script> 
     var center = [0,0]; 
     var zoom = 0; 
     var rotation = 0; 
     if (window.location.has !== '') 
     { 
     var hash = window.location.hash.replace('#map=', ''); 
     var parts = hash.split('/'); 
     console.log (parts); 
     if (parts.length === 4) 
     { 
      zoom = parseInt(parts[0],10); 
      center = [ 
      parseFloat(parts[1]), 
      parseFloat(parts[2]) 
      ]; 
      rotation = parseFloat(parts[3]); 
     var rotation = 0; 
     } 
    } 
     var openStreetMapLayer = new ol.layer.Tile({ 
     source: new ol.source.OSM({ 
      attributions: [ 
      'All maps © <a href="http://www.openstreetmap.org">openStreetMapLayer</a>', 
      ol.source.OSM.ATTRIBUTION 
      ], 
      opaque: false, 
     // url: '<myosmserver>/hot/{z}/{x}/{y}.png' 
     }) 
     }); 


     var map = new ol.Map({ 
     layers: [ 
      openStreetMapLayer 
     ], 
     target: 'map', 
     controls: ol.control.defaults({ 
      attributionOptions: /** @type {olx.control.AttributionOptions} */ ({ 
      collapsible: false 
      }) 
     }), 
     view: new ol.View({ 
      maxZoom: 20, 
      center: center, 
      zoom: zoom 
     }) 
     }); 

    </script> 
    </body> 
</html> 

回答

0

您不能添加一個鏈接,會以某種方式下載地圖爲圖像。你需要將它渲染到某個地方。

這是如何工作的。當Openlayers呈現地圖時,它會將其呈現在HTML畫布元素中。下載功能不是Openlayers功能,而是HTML畫布功能。該畫布具有API以拍攝當前畫布的快照。你可以下載它作爲一個圖像。

您既可以在瀏覽器中呈現地圖,也可以在服務器端呈現地圖。我沒有嘗試渲染服務器上的Openlayers地圖,但它應該是可能的。