Hello Stack Overflow people!使用JavaScript更改KML地標顏色
我真的不知道是否有辦法做到這一點,但我希望自從替代方案變得更加複雜,我不積極如何實現它。目前,我有一個Google Earth插件在其他控件的頁面上運行。該頁面應顯示調制解調器的延遲和信號噪聲數據圖表,以及包含大量附加信息的網格,以幫助我的ISP在解決調制解調器故障時做得更好。
我的問題是:JavaScript中是否有方法修改Google Earth地標的顏色而不妨礙KML?
我知道你可以做這樣的事情在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>
但我一直有在JavaScript中使用C#或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>
它會更好找到在C#代碼添加上述KML爲字符串後面,找到合適的地方,只是添加風格?我一直在傾吐谷歌的API,並試圖將其添加到不同的地方,大部分時間它只是打破了,並沒有顯示天氣數據或地標。最終目標是根據遙控器是標稱的,處於報警狀態還是處於警告狀態,更改爲地標的顏色。我已經在這裏和谷歌上尋找答案,但似乎沒有在JS中這樣做,我似乎無法以正確的方式追加KML來改變地標顏色。有人有任何想法嗎?