我想這個問題與Google Maps v2有關,因爲我不認爲在v3中有類型:G_SATELLITE_3D_MAP。
的谷歌地球插件通過script from the google-maps-utility-library-v3 (googleearth.js)
這種方法筆者@jlivni已經是聽谷歌地圖V3添加/刪除事件,並添加相應的谷歌地球API對象支持谷歌地圖v3是(測試版)。 我相信類似的方法可以用於OpenLayers。我是OpenLayers的新手,剛開始研究這個,但我會在這裏發佈更新。
我現在可以添加的唯一事情是關於谷歌地球插件的初始化,即在V3不同:
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 Map對象。但是,如果我們不創建一個帶有類型的圖層,Google Map對象不存在,我最初設置爲google.maps.MapTypeId.SATELLITE。 不是很乾淨,但至少它讓我和谷歌地圖v3這篇文章的作者一樣。 最後有可能是一種方法,使的OpenLayers控制可見通過修改功能findMapTypeControlDiv_():
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 Plugin div附加到正確的div(GMaps的原始代碼將其附加到Map Controls陣列)。另一個問題是設置zIndex以確保LayerSwitcher處於最佳狀態。 GE插件運行時我仍然遇到問題,我嘗試最小化LayerSwitcher,調用OpenLayers.Event.stop()會導致GE插件崩潰(Chrome)或LayerSwitcher消失(IE8)。 我想分離Google的原始代碼並製作適用於OpenLayers的GE插件層。 任何人都可以建議如何做到這一點?謝謝。
總之,這裏是我的最新變化:
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/ZiglioNZ/GoogleEarth-for-OpenLayers
[更新4] 對於演示,請訪問http://ziglionz.github.com/GoogleEarth-for-OpenLayers/ol.html
感謝您的反饋。我也與一些谷歌工程師聯繫,所以如果我學到了什麼,我會保持你的發佈。 – DaveParillo 2010-07-21 23:35:14
你是對的。我與谷歌工程師的談話無助於此,但指出如果您想將Google Earth插件實施到定製的Web應用程序中,GE插件API(earth_loader_plugin.js)的本地副本必須是加載並且必須設置一些環境變量來配置API密鑰和GEE服務器錯誤頁面的位置。加載Google地球插件並連接到私有GEE服務器的示例網頁可以在http://gmdemo.keyhole.com/geplugin/gee-basic-example.html上查看以供參考。 – DaveParillo 2010-08-06 17:55:24