2017-05-05 47 views
-2

我需要將圖像放入自定義大小的多邊形中,就像在圖片中一樣。我怎樣才能得到這個?我認爲這是一個壞主意。 彩色區域應該填充任何圖像而不是顏色。如何將圖像放入多邊形谷歌地圖

https://i.stack.imgur.com/qzJpu.png

+0

您可以使用圖像疊加https://開頭developers.google.com/maps/documentation/javascript/examples/maptype-image-overlay – scaisEdge

+0

謝謝,我alr eady使用它,但對於矩形區域。對於任意多邊形,這是行不通的。 –

+0

你添加一個圖像..如果圖像不是矩形但透明區域應該工作.. – scaisEdge

回答

0

也許在你的情況自定義背景畫面將是有益的: 檢查這個exmaple

代碼片段:

var bounds = new google.maps.LatLngBounds(
      new google.maps.LatLng(62.281819, -150.287132), 
      new google.maps.LatLng(62.400471, -150.005608)); 

     // The photograph is courtesy of the U.S. Geological Survey. 
var srcImage = 'https://developers.google.com/maps/documentation/' + 
      'javascript/examples/full/images/talkeetna.png'; 

     // The custom USGSOverlay object contains the USGS image, 
     // the bounds of the image, and a reference to the map. 
overlay = new USGSOverlay(bounds, srcImage, map); 
+0

謝謝@Artem,但這不適用於任意多邊形。你的例子只需要兩個邊界並只填充矩形區域。 –

+0

@pablo_ch你不能使用png與透明背景嗎?.. –

+0

我正在使用已經繪製的項目裏面的畫布。 我想要什麼==> http://image.prntscr.com/image/c5f7c82c0b7b45479ea315d922f363f9.png –