2012-03-28 6 views

答えて

1

これは、mouseupまたはclickイベントをリッスンし、シムオーバーレイ技術を使用してカスタムコンテキストメニューを表示することで実現できます。

イベントリスナーのコードは、次のようなものになります。

// Listen for all mouseup events in the plugin. 
// Where 'ge' is an instance of the GEPlugin 
google.earth.addEventListener(ge.getWindow(), 'mouseup', eventHandler); 

イベントハンドラは次のようになります。

// Handles mouseup events (e is a KmlMouseEvent) 
var eventHandler = function(e) 
{ 
    // if it is a right-click 
    if (e && e.getButton() == 2) 
    { 
    event.preventDefault(); // optional, depending on your requirements 
    event.stopPropagation(); // optional, depending on your requirements 
    openMenu(e.getScreenX(), e.getScreenY()); 
    } 
} 

最後に、カスタムメニューを開くためのコードは次のようになります。

// Insert a custom iframe at the x, y screen position 
var openMenu = function(x, y) 
{ 
    var iframe = document.createElement('iframe'); 
    iframe.frameBorder = 0; 
    iframe.scrolling = 'no'; 
    iframe.style.position = 'absolute'; 

    // build the menu as you require... 
    // then position and show it. 
    iframe.style.left = x + 'px'; 
    iframe.style.top = y + 'px'; // you may want to offset the position... 

    document.body.appendChild(iframe); // show the menu 
} 

明らかにメニューに何を入れて、それをどのようにスタイルするかはあなた次第です。メニュー項目をクリックすると(メニューが消えるなど)、おそらくiframeを削除する場合もあります。

ここにこだわってしまうとイベントを扱う素晴らしい参考資料です。 https://developers.google.com/earth/documentation/events

はまた、ここではiframeシム技術の実施例である: http://earth-api-samples.googlecode.com/svn/trunk/demos/customcontrols/index.html

+0

私が見つけた、あなたは答えの前に、この技術を使用しますが、あなたの答えは私の実装のようにほぼ正確です。私は左と上のために 'px'を使用しなかった、それは必要ですか?返信フレイザーありがとう! – goodwince

+0

いいこと...はい、左と上の定義は "auto | length |%| inherit"です。明示的に長さ単位を追加することは、ピクセルまたはパーセントを意図しているかどうかのあいまいさを取り除くので、非常に良い考えです。一部のブラウザでは、ユニット(FireFox)がピクセル(IE)にデフォルト設定されている必要があり、他のブラウザはさらに別のことを行います。ピクセルを使用する場合は、それらを使用してください。 – Fraser

+0

Doh!あなたが正しい!!私はピクセル対パーセンテージについて完全に忘れていました。そのような簡単なことは簡単に忘れてしまった。もう一度ありがとう。 – goodwince

1

現在、IFRAME SHIMSを使用する必要があります。うまくいけば、それはいつか変わるだろう。

あなたが興味を持っている場合、あなたはオーバーiframeのシムを使用して、私のWebページを見ることができます例 http://earth-api-samples.googlecode.com/svn/trunk/demos/customcontrols/index.html

ために、このページをチェックして、いくつかの詳細情報 How can I place a html div over the Google Earth plugin? Involves wmode, I imagine

用SO上でこの他の質問をチェックアウトgoogle earth here http://www.3dwhistler.com/

関連する問題