﻿
function getEarthInstanceCB(pluginInstance) {
    ge = pluginInstance;
    ge.getWindow().setVisibility(true);
    ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
    
}

//google.earth.fetchKml(ge, kmlUrl, finishFetchKml);

function finishFetchKml(kmlObject) {
    // check if the KML was fetched properly
    if (kmlObject) {
        // add the fetched KML to Earth
        currentKmlObject = kmlObject;
        ge.getFeatures().appendChild(currentKmlObject);
    } else {
        alert('Bad KML');
    }
}

var currentKmlObject = null;

function parseKmlFromTextarea() {
    // remove the old parsed KML object if one exists
    if (currentKmlObject)
        ge.getFeatures().removeChild(currentKmlObject);

    var kmlBox = document.getElementById('kml-box');
    var kmlString = kmlBox.value;

    // parse the text in the box and add it to Earth
    try {
        currentKmlObject = ge.parseKml(kmlString);
        ge.getFeatures().appendChild(currentKmlObject);
    } catch (ex) {
        alert('Parse error');
    }
}



//http://code.google.com/apis/ajax/playground/?exp=maps#fetch_user%27s_kml
//http://code.google.com/intl/zh-TW/apis/earth/documentation/advanced.html#maps


//function initCB(instance) {
//    ge = instance;
//    ge.getWindow().setVisibility(true);


//    // add a navigation control
//    ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);

//    // add some layers
//    ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
//    ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);

//    // fly to Santa Cruz
//    var la = ge.createLookAt('');
//    la.set(37, -122,
//          0, // altitude
//          ge.ALTITUDE_RELATIVE_TO_GROUND,
//          0, // heading
//          0, // straight-down tilt
//          5000 // range (inverse of zoom)
//  );
//    ge.getView().setAbstractView(la);

//    // if the page loaded with checkboxes checked, load the appropriate
//    // KML files
//    if (document.getElementById('kml-red-check').checked)
//        loadKml('red');

//    if (document.getElementById('kml-yellow-check').checked)
//        loadKml('yellow');

//    if (document.getElementById('kml-green-check').checked)
//        loadKml('green');

//    document.getElementById('installed-plugin-version').innerHTML =
//      ge.getPluginVersion().toString();
//}

//function failureCB(errorCode) {
//}