こんにちはスタックオーバーフローの人々!!
正直なところ、これを行う方法があるかどうかはわかりませんが、別の方法がさらに複雑であり、それを達成する方法がはっきりしていないため、あることを願っています. 現在、他のコントロールを備えたページで 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を正しい方法で追加して目印の色を変更できないようです。誰にもアイデアはありますか?