タイプがないと思うので、この質問はGoogleマップv2に関連していたと思います:v3のG_SATELLITE_3D_MAP。
Google マップ v3 用の Google Earth プラグインは、google-maps-utility-library-v3 (googleearth.js) のスクリプトを介して (ベータ版) サポートされています。
著者@jlivniが取ったアプローチは、Google マップ v3 の追加/削除イベントをリッスンし、対応する Google Earth Api オブジェクトを追加することです。OpenLayers でも同様のアプローチを使用できると思います。私は OpenLayers を初めて使用し、これを調査し始めたばかりですが、ここに更新を投稿します。
今追加できる唯一のことは、v3 で異なる Google Earth プラグインの初期化についてです。
function GoogleEarth( olmap ) {
this.olmap_ = olmap;
this.layer_ = new OpenLayers.Layer.Google(
"Google Earth",
{type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22, visibility: false}
);
this.olmap_.addLayers([ this.layer_ ]);
this.map_ = this.layer_.mapObject;
this.mapDiv_ = this.map_.getDiv();
...
var earthMapType = /** @type {google.maps.MapType} */({
tileSize: new google.maps.Size(256, 256),
maxZoom: 19,
name: this.earthTitle_,
// The alt helps the findMapTypeControlDiv work.
alt: this.earthTitle_,
getTile:
/**
* @param {google.maps.Point} tileCoord the tile coordinate.
* @param {number} zoom the zoom level.
* @param {Node} ownerDocument n/a.
* @return {Node} the overlay.
*/
function(tileCoord, zoom, ownerDocument) {
var div = ownerDocument.createElement('DIV');
return div;
}
});
this.map_.mapTypes.set(GoogleEarth.MAP_TYPE_ID, earthMapType);
this.layer_.type = GoogleEarth.MAP_TYPE_ID;
var that = this;
google.maps.event.addListener(map, 'maptypeid_changed', function() {
that.mapTypeChanged_();
});
}
複雑な部分は、Google Earth の新しいマップ タイプを定義し、このタイプを Google マップ オブジェクトに追加する必要があることです。しかし、最初に google.maps.MapTypeId.SATELLITE に設定したタイプのレイヤーを作成しないと、Google マップ オブジェクトは存在しません。あまりきれいではありませんが、少なくとも、Google マップ v3 を使用して、この投稿の著者と同じ状態になります。最後に、関数 findMapTypeControlDiv_() を変更して、OpenLayers コントロールを表示する方法があるかもしれません。
var mapTypeControlDiv = this.findMapTypeControlDiv_();
if (mapTypeControlDiv) {
this.setZIndexes_(mapTypeControlDiv);
this.addShim_(mapTypeControlDiv);
}
[アップデート]
関数 findMapTypeControlDiv_() を変更し、代わりに OpenLayers LayerSwitcher を探します。
GoogleEarth.prototype.findLayerSwitcherDiv_ = function() {
// var title = 'title="' + this.earthTitle_ + '"';
var id = 'LayerSwitcher';
var siblings = this.controlDiv_.parentNode.childNodes;
for (var i = 0, sibling; sibling = siblings[i]; i++) {
if (sibling.id.indexOf(id) != -1) {
return sibling;
}
}
};
LayerSwitcher の z インデックスは正しく設定されており、div は google.earth.createInstance() が呼び出されるまで上に表示され、その後消えます。もう少し時間をかけますが、解決するのは難しくないようです。
【アップデート2】
LayerSwitcher パネルの問題を回避しました。トリックは、Google Earth プラグイン div を適切な div にアタッチすることでした (GMaps の元のコードは、それを Map Controls 配列にアタッチします)。もう 1 つの問題は、LayerSwitcher が一番上にあることを確認するために zIndex を設定することでした。OpenLayers.Event.stop() を呼び出すと、GE プラグインがクラッシュする (Chrome) か、LayerSwitcher が消える (IE8) ようになります。Google から元のコードをフォークして、OpenLayers で動作する GE Plugin Layer を作成したいと考えています。誰かがそれを行う方法を提案できますか? ありがとう。
とにかく、ここに私の最新の変更があります:
GoogleEarth.prototype.findLayerSwitcherDiv_ = function() {
var id = 'LayerSwitcher';
var siblings = this.mapDiv_.parentNode.childNodes;
for (var i = 0, sibling; sibling = siblings[i]; i++) {
if (sibling.id.indexOf(id) != -1) {
return sibling;
}
}
};
GoogleEarth.prototype.addEarthControl_ = function() {
...
inner.appendChild(earthDiv);
var parentNode = this.findLayerSwitcherDiv_().parentNode;
parentNode.appendChild( control );
...
GoogleEarth.prototype.setZIndexes_ = function(mapTypeControlDiv) {
var oldIndex = mapTypeControlDiv.style.zIndex;
var siblings = this.controlDiv_.parentNode.childNodes;
for (var i = 0, sibling; sibling = siblings[i]; i++) {
sibling['__gme_ozi'] = sibling.style.zIndex;
// Sets the zIndex of all controls to be behind Earth.
sibling.style.zIndex = 0;
}
mapTypeControlDiv['__gme_ozi'] = oldIndex;
this.controlDiv_.style.zIndex = 2000;
mapTypeControlDiv.style.zIndex = 2001;
};
[更新 3] ここで github プロジェクトをセットアップしました: https://github.com/ZiglioUK/GoogleEarth-for-OpenLayers