2013-05-14 64 views
3

例如,我可以更改地圖的draggableCursor,但即使我更改了它,多邊形的光標仍然是指針,因爲地圖位於多邊形後面。我想將多邊形的光標設置爲'移動',以清楚地看到多邊形是可拖動的。谷歌地圖api-3:更改多邊形的默認光標

什麼是改變多邊形光標的正確方法?是否有財產或方法來做到這一點? (我已閱讀Google的文檔,但沒有發現任何內容)

ps。 我有理由在多段線上使用多邊形,所以折線不是一個選項。

+1

不幸的是沒有選項可以改變光標。該指針似乎表示該多邊形是可點擊的,但是當您將可點擊選項設置爲false時(在這種情況下將出現拖動光標),該多邊形不再可拖動。 –

回答

6

其實它似乎是可能的。 這是這個想法。
CSS:

.moving, 
.moving * {cursor: move !important;} 

JS:

google.maps.event.addListener(myPolygon, 'mousemove', 
    function(e) { 
     if (!isNaN(e.edge) || !isNaN(e.vertex)) 
      mapCanvas.className = ''; 
     else 
      mapCanvas.className = 'moving';   
    } 
); 

google.maps.event.addListener(myPolygon, 'mouseout', 
    function() { 
     mapCanvas.className = ''; 
    } 
); 

乾杯!

+0

適用於我,但必須添加以下內容:mapCanvas = document.getElementById(「container」); – amackay11

-2

鼠標事件polybon和地圖做到這一點:
光標移到地圖:

document.getElementById("map").children[0].children[0].style.cursor = 'url(res/end.png), auto';

光標移到多邊形:

document.getElementById("map").style.cursor = 'url(res/end.png), auto';

+1

你應該解釋你的代碼並正確格式化。 –

1

您可以設置CSS光標!importantdiv #map上,但它總是覆蓋您的自定義光標。

#map div 
{ 
    cursor: url("your.url.to.cursor.png"), default !important; 
}