KML layer On/Off for integrated Google Maps 3 & GE application

693 views Asked by At

I have a webmap with GMaps & GEarth integrated, in order for the user to switch between different views.

I load 3 KML files and control their visibility using checkboxes. This example here uses the same function stackOverflowQuestion

When I switch views Map - Satellite - Earth I have my KMLs working on Map & Satellite view, BUT not on Earth View.

    function init() {
    map = new google.maps.Map(document.getElementById('map'), {
      zoom: 14,
      center: new google.maps.LatLng(xx, xx),
      mapTypeId: google.maps.MapTypeId.TERRAIN
    });

    googleEarth = new GoogleEarth(map);

    google.maps.event.addListenerOnce(map, 'tilesloaded', addOverlays);

    }//end init

    [...]

    function OnOffKML(i) {

    if(currentKmlObjects[i].getMap() === null) {
        currentKmlObjects[i].setMap(map);
    }
    else {
        currentKmlObjects[i].setMap(null);
    }
}

this function works for Google Maps Api 3, but not for Google Earth plugin... Does this mean I have to use the fetch{} for it to show on GE? Is there a workaround?

Could I exclude my toggleKML{} for the earth view in any way?

2

There are 2 answers

0
giannis On BEST ANSWER

OK, The problem here is that we cannot code for GM Api 3 and expect to have results for GE Api as well.

Sure the two can be integrated but you have to decide that one of the two will have limited functionality. Thus I decided to split the application up, work separately and efficiently.

As for GE method for KML usage, I have used the fetch{} function, along with checkbox selection.

0
Fraser On

That is not strictly true, you would just need to reload your Kml into the earth API.

You could modify your OnOffKML function to act differently depending on the current mode (earth/maps).

The problem you have currently is that you are using Google Maps Api methods, on the Google Earth plugin.

Anyhow, something like the following would work, allowing the method to handle both.

function OnOffKML(i) {
    if(googleEarth.getWindow().getVisibility()) {
       // code for earth api
    } else {
       // code for maps api
    }
}