views:

384

answers:

2

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:

  1. Is this a documented limitation? I can't find anything that indicated it should not be possible.
  2. 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.

+1  A: 

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.

Christopher Schmidt
Thanks for the feedback. I'm also in contact with a couple of google engineers, so if I learn anything, I will keep you posted.
DaveParillo
You are correct. My talk with the google engineers didn't help with this, but did point out that if you want to implement the Google Earth Plugin into a custom-built web application, the local copy of the GE Plugin API (earth_loader_plugin.js) must be loaded and some environment variables must be set to configure the API key and location of the error page for the GEE Server. An example web page loading the Google Earth Plugin, and connecting to a private GEE Server, may be viewed at http://gmdemo.keyhole.com/geplugin/gee-basic-example.html for reference.
DaveParillo
A: 

Can you help me whit code which I need to put in openlayer to see google earth map in it? What is code for it?

Dragan
The code for it is in the question. The google earth layer is var gearth = new OpenLayers.Layer.Google( "Google Earth", {type: G_SATELLITE_3D_MAP}); However, I recommend you do NOT use google earth as a layer in openlayers. They do not play well together.
DaveParillo
Hi, thank you, but I have another problem, I have my own map and in that map lines with same longitude and latitude are not parallel, because country is big and lines goes to the north pol (and because of that they are not parallel), but in openlayer lines with same longitude and latitude are always parallel, how to change this?
Dragan