如何使用谷歌地球底图绘制 openlayers 要素
尝试使用 OpenLayers 来(最终)加载标记、矢量和图像。 WMS 位于 Google Earth 插件基础地图之上。 Google 地球似乎“无法与他人很好地合作”。
如果我以“谷歌方式”实例化地图: google.earth.createInstance('地图', initCB, failureCB);
我得到一个谷歌地图,我可以添加谷歌地标,但我无法将该实例传递给 OpenLayers。
使用以下内容:
map = new OpenLayers.Map('ol-map');
map.addControl(new OpenLayers.Control.LayerSwitcher());
var gphy = new OpenLayers.Layer.Google(
"Google Physical",
{type: G_PHYSICAL_MAP}
);
var gmap = new OpenLayers.Layer.Google(
"Google Streets", // the default
{numZoomLevels: 20}
);
var ghyb = new OpenLayers.Layer.Google(
"Google Hybrid",
{type: G_HYBRID_MAP, numZoomLevels: 20}
);
var gsat = new OpenLayers.Layer.Google(
"Google Satellite",
{type: G_SATELLITE_MAP, numZoomLevels: 22}
);
var gearth = new OpenLayers.Layer.Google(
"Google Earth",
{type: G_SATELLITE_3D_MAP}
);
map.addLayers([gphy, gmap, ghyb, gsat, gearth]);
map.setCenter(new OpenLayers.LonLat(-120, 32), 5)
addMarker();
这将创建一个具有 5 个粘性图层的基本 OL 地图。当选择 gearth 时,我可以看到在任何地图图层除了时添加的标记。一旦我加载谷歌地球地图,它就会“接管”整个 div。所有 OL 控件(例如 LayerSwitcher)都消失了,我无法弄清楚如何从 OL 访问 google Earth 实例。
我假设标记仍然存在,但位于底图后面。设置底图的不透明度没有效果。
问题:
- 这是有记录的限制吗?我找不到任何表明这是不可能的事情。
- 有没有一种解决方法可以将 OpenLayers 地图/图层实例传递给 google Earth 的 getEarthInstance 调用?或者反之亦然?这似乎是两全其美,让我可以在需要时访问 GE API,但我可以使用 OL 中的所有 WFS 处理来完成大多数任务。
欢迎半生不熟的想法。
Trying to use OpenLayers to (eventually) load markers, vectors & WMS on top of a google earth plugin base map. Google Earth does not appear to 'play well with others'.
If I instantiate a map in the 'google way':
google.earth.createInstance('map', initCB, failCB);
I get a google map that I can add google placemarks to, but I can't pass that instance to OpenLayers.
Using the following:
map = new OpenLayers.Map('ol-map');
map.addControl(new OpenLayers.Control.LayerSwitcher());
var gphy = new OpenLayers.Layer.Google(
"Google Physical",
{type: G_PHYSICAL_MAP}
);
var gmap = new OpenLayers.Layer.Google(
"Google Streets", // the default
{numZoomLevels: 20}
);
var ghyb = new OpenLayers.Layer.Google(
"Google Hybrid",
{type: G_HYBRID_MAP, numZoomLevels: 20}
);
var gsat = new OpenLayers.Layer.Google(
"Google Satellite",
{type: G_SATELLITE_MAP, numZoomLevels: 22}
);
var gearth = new OpenLayers.Layer.Google(
"Google Earth",
{type: G_SATELLITE_3D_MAP}
);
map.addLayers([gphy, gmap, ghyb, gsat, gearth]);
map.setCenter(new OpenLayers.LonLat(-120, 32), 5)
addMarker();
This creates a basic OL map with 5 googly layers. I can see the marker I add when any of the map layers except when gearth is selected. As soon as I load the google earth map, it 'takes over' the entire div. All the OL controls such as the LayerSwitcher are gone and I haven't been able to figure out how to access the google earth instance from OL.
I'm assuming the markers are still present, but behind the basemap. Setting the opacity on the basemap has no effect.
Questions:
- Is this a documented limitation? I can't find anything that indicated it should not be possible.
- Is there a workaround where I can pass the OpenLayers map/layer instance to google earth's getEarthInstance call? Or vice versa? It seems like that would be the best of both worlds, giving me access to the GE API when needed, but I could use all the WFS processing in OL for most tasks.
Half-baked ideas welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一般来说,OpenLayers 绝对不支持 Google Earth 3D 模式。 (我是 OpenLayers 的开发人员,我只是通过这个问题才意识到这是可能的。)由于 3D 显示代码的工作方式(通过第 3 方插件),我可以无法想象默认的 OpenLayers 工具(用于绘图等)会以任何方式工作:OpenLayers 需要集成的部分根本不存在于 3D API 中。
OpenLayers(主要是一个 2D 绘图客户端)不太可能实现将其所有各种调用转换为 Google 地图/地球 API 调用的功能。
OpenLayers 确实支持协议和格式:理论上,这将允许您在与 Google Earth API 等第三方 API 交互时在某种程度上使用 OpenLayers WFS 处理工具链。但是,我预计在这种情况下,您无法从中获得足够的收益来解决您的问题。
简而言之:这行不通,而且没有简单的解决方案。如果您想要 3D,您可能需要自己构建更多东西。
In general, OpenLayers has absolutely no support for the Google Earth 3D mode. (I'm a developer for OpenLayers, and I only became aware that this was possible via this question.) Because of the way that the 3D display code works (via a 3rd party plugin), I can not imagine any way that the default OpenLayers tools -- for drawing, etc. -- are going to work: the pieces that OpenLayers would need to integrate with simply don't exist in the 3D API.
OpenLayers -- primarily being a 2D drawing client -- is unlikely to ever implement something that would translate all of its various calls into Google Maps/Earth API calls.
OpenLayers does have support for Protocols and Formats: in theory, this would allow you to use the OpenLayers WFS processing toolchain to some extent when interacting with third party APIs like the Google Earth API. However, I expect that in this case, you don't gain sufficiently enough from this to solve your problem.
In short: This doesn't work, and there is no simple solution. If you want 3D, you'll probably need to build a lot more yourself.
我认为这个问题与Google Maps v2有关,因为我认为v3中没有类型:G_SATELLITE_3D_MAP。
Google 地图 v3 的 Google 地球插件(测试版)通过 来自 google-maps-utility-library-v3 (googleearth.js) 的脚本
作者的方法 @jlivni 采取的方法是监听 Google Maps v3 添加/删除事件并添加相应的 Google Earth Api 对象。
我相信 OpenLayers 可以使用类似的方法。我是 OpenLayers 的新手,刚刚开始研究这个问题,但我会在这里发布更新。
我现在唯一可以添加的是关于 Google Earth 插件的初始化,这在 v3 中有所不同:
令人费解的部分是我们需要为 Google Earth 定义一个新的地图类型,并将该类型添加到 Google Map 对象中。但是,如果我们不创建具有类型的图层(我最初将其设置为 google.maps.MapTypeId.SATELLITE),则 Google 地图对象不存在。
不是很干净,但至少它让我使用 Google 地图 v3 达到与本文作者相同的状态。
最后,可能有一种方法可以通过修改函数 findMapTypeControlDiv_() 来使 OpenLayers 控件可见:
[更新]
我已经修改了函数 findMapTypeControlDiv_(),现在我寻找 OpenLayers LayerSwitcher:
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 插件层。
有人能建议如何去做吗?谢谢。
无论如何,这是我的最新更改:
[更新 3]
我在这里建立了一个 github 项目: https://github.com/ZiglioUK/GoogleEarth- for-OpenLayers
I think this question was related to Google Maps v2, since I don't think there's a type: G_SATELLITE_3D_MAP in v3.
The Google Earth Plugin for Google Maps v3 is (beta) supported via a script from the google-maps-utility-library-v3 (googleearth.js)
The approach the author @jlivni has taken is to listen to Google Maps v3 add/remove events and add corresponding Google Earth Api objects.
I believe a similar approach could be used with OpenLayers. I'm new to OpenLayers, and have just started looking into this but I'll post updated here.
The only thing I can add now is about the initialization of the Google Earth plugin, that is different in v3:
The convoluted part is that we need to define a new map type for Google Earth, and add this type to a Google Map object. But the Google Map object doesn't exist if we don't create a layer with a type, that I set initially to google.maps.MapTypeId.SATELLITE.
Not very clean, but at least it gets me to the same state as the author of this post with Google Maps v3.
Finally there may be a way to make OpenLayers controls visible by modifying the function findMapTypeControlDiv_():
[Update]
I've modified the function findMapTypeControlDiv_() and now I look for the OpenLayers LayerSwitcher instead:
The z index of the LayerSwitcher is correctly set and the div shows on top until google.earth.createInstance() is invoked, then it disappears. I'll spend some more time on it, it doesn't look to hard to solve.
[Update 2]
I've worked around the LayerSwitcher panel issue. The trick was attaching the Google Earth Plugin div to the proper div (the original code for GMaps attaches it to the Map Controls array). The other issue was setting the zIndex to make sure the LayerSwitcher is on top.
I'm still having a problem when the GE Plugin is running and I try to minimize the LayerSwitcher, a call to OpenLayers.Event.stop() makes the GE Plugin crash (Chrome) or the LayerSwitcher to disappear (IE8).
I'd like to fork the original code from Google and make a GE Plugin Layer that works on OpenLayers.
Could anyone suggest how to do it? thanks.
Anyway, here are my latest changes:
[update 3]
I've set up a github project here: https://github.com/ZiglioUK/GoogleEarth-for-OpenLayers
我不再熟悉 OpenLayers 中的不同图层类型,但关键是 Google Earth API 和 Google Maps API 确实是不同的东西。乍一看,我不明白为什么您需要将其添加到 Google 地图类型(假设这就是我的想法)。
正如 Chris 已经暗示的那样,只需将您的 Earth API 集成视为一个全新的、独立于任何现有 Google 层的事物即可;这些 API 中的语法和概念并不真正相似,至少据我所知,您无法获得在 OpenLayers 中对现有 Google 地图集成进行子类化的任何优势。
也就是说,我希望 Maps V3/Earth 集成的代码会有所帮助,并且类似于将其与 OpenLayers 集成所需执行的操作。同时,我看到其他一些人也对此进行了尝试,例如这个 geoExt 示例,您可能也会发现它很有用: http://dev.geoext.org/sandbox/cmoullet/ux/GoogleEarthPanel/examples/GoogleEarthPanelExample.html
I am not that familiar with the different layer types in OpenLayers anymore, but the key is that the Google Earth API and the Google Maps API are really different beasts. At first glance I do not see why you would need to add it to a Google Maps type (assuming that's what I think it is).
As Chris implied already, just treat your Earth API integration as an entirely new and separate thing from any existing Google layers; the syntax and concepts in these API's are not really similar enough for you to get any advantage of subclassing the existing Google Maps integration in OpenLayers at least as far as I can tell.
That said I hope the code for the Maps V3/Earth integration will be helpful and analogous to what you need to do to integrate it with OpenLayers. Meanwhile I've seen some other folks also give this a shot, such as this geoExt example which you may also find useful: http://dev.geoext.org/sandbox/cmoullet/ux/GoogleEarthPanel/examples/GoogleEarthPanelExample.html