Sorry didnt look at the snippet that well.

See it already does use that event :)

I just tried modifing your code and putting in the event...

       if (ge) {
           setTimeout("doStuffWithEarth()",100);
         return;
     }

instead of

if (go)
   return;

And it works :)

Seems the setTimeout is needed, because the plugin has not fully setup
when maptypechanged is called.
(it works first time because its in the callback of getEarthInstance)



On 13 May 2010 15:54, Barry Hunter <[email protected]> wrote:
> I would imagine the ge instance isn't guaranteed to survive being
> 'hidden' and then re-enabled.
>
>
> probably just listen for maptypechanged event, and make sure the ge
> globe is setup as required...
>
> http://code.google.com/apis/maps/documentation/reference.html#GMap2.maptypechanged
>
>
> On 13 May 2010 15:24, Arkaduis <[email protected]> wrote:
>> Hi,
>> I'm trying to integrate the Earth plugin into my website. I'd like to
>> use a <div> with several views (maps, sattelite, terain and earth).
>> That's easy but I want to add some layers to earth (roads, borders and
>> buildings). I'm learing with code playgroud where I paste this code:
>>
>> var map;
>> var ge;
>>
>> google.load("maps", "2.x");
>>
>> function init() {
>>  map = new GMap2(document.getElementById('map3d'));
>>  map.setCenter(new GLatLng(37, -122), 12);
>>
>>  var mapui = map.getDefaultUI();
>>  mapui.maptypes.physical = false;
>>  map.setUI(mapui);
>>
>>  // add 'Earth' as one of the map types
>>  map.addMapType(G_SATELLITE_3D_MAP);
>>
>>  // create a marker
>>  var marker = new GMarker(new GLatLng(37, -122));
>>  GEvent.addListener(marker, "click", function() {
>>    var html = '<div style="width: 210px; padding-right: 10px">Hello
>> world!</div>';
>>    marker.openInfoWindowHtml(html);
>>  });
>>
>>  map.addOverlay(marker);
>>  google.maps.Event.trigger(marker, "click");
>>
>>  // create a polyline (LineString Placemark in KML)
>>  var polyline = new GPolyline([
>>      new GLatLng(37.04, -122.04),
>>      new GLatLng(37.02, -122.02),
>>      new GLatLng(37.03, -122.01),
>>      new GLatLng(37.01, -121.99)
>>    ], "#ff0000", 10);
>>
>>  map.addOverlay(polyline);
>>
>>  // do stuff with Earth when the user switches to it
>>  GEvent.addListener(map, 'maptypechanged', function() {
>>    if (ge)
>>      return;
>>
>>    map.getEarthInstance(function(pluginInstance) {
>>      ge = pluginInstance;
>>      doStuffWithEarth();
>>    });
>>  });
>> }
>>
>> function doStuffWithEarth() {
>>  document.getElementById('installed-plugin-version').innerHTML =
>>    ge.getPluginVersion().toString();
>>
>>    ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
>>    ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
>>    ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
>> }
>>
>> All of this is standard "Maps/Earth Integration" except the last 3
>> lines.
>> After the map is loaded, i can switch to earth and all layers are
>> displayed BUT when i switch back to maps and again to earth then the
>> layers disappear. What's wrong with this code?
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Google Maps API" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to 
>> [email protected].
>> For more options, visit this group at 
>> http://groups.google.com/group/google-maps-api?hl=en.
>>
>>
>



-- 
Barry

- www.nearby.org.uk - www.geograph.org.uk -

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en.

Reply via email to