0

こんにちはスタックオーバーフローの人々!!

正直なところ、これを行う方法があるかどうかはわかりませんが、別の方法がさらに複雑であり、それを達成する方法がはっきりしていないため、あることを願っています. 現在、他のコントロールを備えたページで Google Earth プラグインを実行しています。このページには、モデムの遅延と信号対雑音データのグラフと、モデムのトラブルシューティングに関して ISP が少し改善するのに役立つ大量の追加情報を含むグリッドが表示されるはずです.

質問があります: JavaScript で、KML をいじらずに Google Earth の目印の色を変更する方法はありますか?

KMLでこのようなことができることを知っています

<Style id="normalPlacemark">
  <IconStyle>
    <color>ffffff00</color>
    <scale>5</scale>
    <Icon>
      <href>http://maps.google.com/mapfiles/kml/pushpin/wht-pushpin.png</href>
    </Icon>
  </IconStyle>
</Style>

しかし、C# または JavaScript の AddKMLFromString() を使用して XML 全体の適切な場所に追加するのに問題がありました (私は本当に慣れていません)。ページにそれを認識させます。

現時点で使用している変更されたプラグイン コードは次のとおりです。

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
    var ge;
    google.load("earth", "1");

    //Create an instance of the Earth
    function init() {
        google.earth.createInstance('gmap', initCallback, failureCallback);
    }

    function initCallback(pluginInstance) {
        ge = pluginInstance;
        ge.getWindow().setVisibility(true);

        //URL for KML file which is taken directly from Google
        //The KML in question is Google's giant file for weather data
        var href = 'aurlwherewetherdatalives.kml';

        //Use Google's fetch KML method to get the weather KML file and add it to our plugin's instance
        google.earth.fetchKml(ge, href, function (kmlObject) {
            if (kmlObject) {
                ge.getFeatures().appendChild(kmlObject);
            }
            if (kmlObject.getAbstractView() !== null)
                ge.getView().setAbstractView(kmlObject.getAbstractView());
        });

        //Turn on Country Borders, States, and Cities
        ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);

        //By default, remoteExists uses True where JavaScript wants true
        var jsRemoteExists = <%= remoteExists.ToString().ToLower() %>;

        //If the remote exists, create a placemark and camera at its location using the
        //the latitude and longitude variables retreived in the c#
        if (jsRemoteExists)
            {
                //Variables have been created
                var lat = <%= CSHARPLat %>;
                var lon = <%= CSHARPLong %>;



                ge.getWindow().setVisibility(true);

                // Create the placemark and add it to Earth.
                var placemark = ge.createPlacemark('');

                // Set the placemark's location.  
                var point = ge.createPoint('');
                point.setLatitude(lat);
                point.setLongitude(lon);
                placemark.setGeometry(point);

                // Add the placemark to Earth.
                ge.getFeatures().appendChild(placemark);

                var la = ge.createLookAt('');
                la.setLatitude(lat);
                la.setLongitude(lon);
                la.setRange(150000);
                ge.getView().setAbstractView(la);
        }

    }
    function failureCallback(errorCode) {
    }

    function addKmlFromString(kmlString) {
        var kmlObject = ge.parseKml(kmlString);

        ge.getFeatures().appendChild(kmlObject);
    }


    window.onload = init();
</script>

上記の KML を C# コード ビハインドの文字列に追加し、スタイルを追加するだけの適切な場所を見つけたほうがよいでしょうか? 私は Google の API に注ぎ込み、さまざまな場所に追加しようとしましたが、ほとんどの場合、壊れて天気データや目印が表示されません。最終的な目標は、リモコンが正常か、警報状態か、警告状態かに基づいて、目印の色を変更することです。こことGoogleで答えを探しましたが、JSでは何もしていないようで、KMLを正しい方法で追加して目印の色を変更できないようです。誰にもアイデアはありますか?

4

1 に答える 1

0

私は最終的にこれを自分で理解しました。うまくいけば、答えを探している人なら誰でもここで見つけることができます。

スタイルに基づいてさまざまな色の画像を交換することを提案するものをたくさん見ましたが、その方法を説明している場所を見つけることができませんでした. その理由は、JavaScript が人里離れた場所に隠されているためです。Google の API は、場合によっては非常にユーザー フレンドリーではないことがあります。つまり、検索可能である方が優れていますよね?これが誰かを助けることを願っています。

C# では、画像を保存して JavaScript に渡す場所へのリンク (ローカルは作業を望まないため、絶対パス) を含む switch ステートメントがあります。

var statusURL = '<%= CSHARPstatusURL %>';

KML を動的に生成していたので、私のような他のレイヤーを非表示にしないように、少し後で場所を微調整する必要があるかもしれません。これらの便利な小さな行が必要です。

        // Define a custom icon.
        var icon = ge.createIcon('');
        icon.setHref(statusURL);

        var style = ge.createStyle(''); //create a new style
        style.getIconStyle().setIcon(icon); //apply the icon to the style
        style.getIconStyle().setScale(1.5); //set the icon's size
        placemark.setStyleSelector(style); //apply the style to the placemark

それが、私が望んでいた元の方法であるアイコン スタイルを作成できるようにするものです。自分でいくつかの画像を作成し、GIMP などで彩度を変更すれば、準備完了です。乾杯!

于 2013-05-28T12:55:18.300 に答える