2015-07-10 162 views
1

這是我的版本。但它不起作用。顯示畫布,但不響應拖輪和縮放。如何將base64解碼圖像添加到開發圖中?

   var layer = new ol.layer.Image({ 
       source: new ol.source.ImageCanvas({ 
        canvasFunction: function(){ 
         var canvas = document.createElement('canvas'); 
         var context = canvas.getContext('2d'); 
         var image = new Image(); 

         canvas.setAttribute('width', attachment.width); 
         canvas.setAttribute('height', attachment.height); 

         image.onload = function(){ 
          context.drawImage(image, 0, 0); 
         }; 

         image.src = attachment.src; 

         return canvas; 
        }, 
        projection: view.getProjection() 
       }) 
      }); 
+0

您可以提交您自己的問題的答案。當你自己發現解決方案時,實際上是推薦的事情。 – Jason

回答

3

我找到答案!只需使用ol.source.ImageStatic和imageLoadFunction:

  var layer = new ol.layer.Image({ 
      source : new ol.source.ImageStatic({ 
       imageExtent : view.getProjection().getExtent(), 
       size : [attachment.width, attachment.height], 
       imageLoadFunction : function(image){ 
        image.getImage().src = attachment.src; 
       }, 
       projection : view.getProjection(), 
       url : '' 
      }) 
     });