0

次のコードは機能します。ページを読み込んで、地球を表示させることができます。

ナビゲーションコントロールを表示したい。initCBの行のコメントを外すと、機能します。

コードにはスコープの問題があり、それを機能させるには微調整が必​​要だと思います。

ありがとうございました。

declare var google;

class GoogleEarth {

    static pluginInstance;

    static display() {

        google.load("earth", "1");
        google.setOnLoadCallback(init);
    }

    static ShowNavigation() {

        this.pluginInstance.getNavigationControl().setVisibility(this.pluginInstance.VISIBILITY_AUTO);
    }

    private static init() {

        google.earth.createInstance('map3d', initCB, failureCB);
    }

    private static initCB(instance) {

        this.pluginInstance = instance;
        this.pluginInstance.getWindow().setVisibility(true);
        //this.pluginInstance.getNavigationControl().setVisibility(this.pluginInstance.VISIBILITY_AUTO);
    }

    private static failureCB(errorCode) {}
}

GoogleEarth.display();
GoogleEarth.ShowNavigation();
4

1 に答える 1

0

コメントに基づいて更新...

ここには3つの問題の組み合わせがあります。

  1. 変数がコールバックで設定されていたために設定される前に使用されたが、コールバックが発生する前に使用された競合状態。

  2. スコープの問題。コールバック関数が間違ったスコープで実行されていました。

これらは、次のサンプルを使用して修正できます。

declare var google;

class GoogleEarth {

    private pluginInstance;

    constructor (private showNavigation = false){
    }

    display() {
        var self = this;
        google.load("earth", "1");
        google.setOnLoadCallback(function (instance) {
            google.earth.createInstance('map3d', function () {
                this.pluginInstance = instance;
                this.pluginInstance.getWindow().setVisibility(true);
                if (this.showNavigation) {
                    this.pluginInstance.getNavigationControl().setVisibility(this.pluginInstance.VISIBILITY_AUTO);
                }
            }, self.failureCB); 
        });
    }

    ShowNavigation() {

    }

    failureCB(errorCode) {}
}

var earth = new GoogleEarth(true);
earth.display();

私は3つの問題があると言いました!

最後の問題は、instance渡される関数に呼び出される関数がないことgetWindow()です。したがって、コードのこの段階でエラーが発生します。これは、Googleのドキュメントを再確認する場合です。

于 2012-10-24T08:21:54.537 に答える