0

JavaScript を使用してプラグインを介して Google Earth の上に重ねられたポリゴンで構成されるコロプレス マップを作成しようとしています。

ポリゴンは KML ファイルに存在し、すべてが一意の ID を持ち、サーバー (必ずしも私のものではありません) に存在します。多角形の色を動的に変更して、さまざまなデータ セットを表示できるようにしたいと考えています。

これは実行可能ですか?

KML メカニズムを調べましたが、それは同じサーバー上のファイルでしか機能しません。

ありがとう、

明細書

4

1 に答える 1

2

ネットワークでアクセス可能な任意の URL (同じサーバーまたはそれ以外) からGoogle Earth APIを介してリモート KML を読み込んで解析し、KML オブジェクトを繰り返し処理して、スタイルとポリゴンの色をプログラムで変更できます。

var href = 'http://code.google.com/'
           + 'apis/earth/documentation/samples/kml_example.kml';

google.earth.fetchKml(ge, href, function(kmlObject) {
      if (kmlObject) {
         checkObject(kmlObject);
         // append KML objects to current view
         ge.getFeatures().appendChild(kmlObject);
      }    
});

function checkObject(kmlObject) {
    var type = kmlObject.getType();         
    if (type == 'KmlDocument' || type == 'KmlFolder') {
        var features = kmlObject.getFeatures();
        if (features.hasChildNodes()) {
            var children = features.getChildNodes();                    
            for (i=0; i < children.getLength(); i++) {
                checkObject(children.item(i));                      
            }
        }
    } else if (type == 'KmlPlacemark') {
        // check/set style, change color, etc.
        // ...
    }
}

参照: https://developers.google.com/earth/documentation/kml#fetchkml_and_parsekml

于 2013-09-29T19:22:14.253 に答える