在本教程中,您可以自定义LINESTRING https://developers.google.com/earth/documentation/geometries?hl=en
但是当我尝试使用C#VS2012时的代码行
var lineStyle = lineStringPlacemark.getStyleSelector().getLineStyle();
我找不到方法getLineStyle()所以我得到了错误;
错误: Error1 GEPlugin.IKmlStyleSelector'不包含'getLineStyle'的定义,并且没有可以找到接受类型'GEPlugin.IKmlStyleSelector'的第一个参数的扩展方法'getLineStyle'(你是否缺少using指令或程序集引用?)
这是我的完整代码:
var lineStringPlaceMark = m_ge.createPlacemark("");
var lineString = m_ge.createLineString("");
lineStringPlaceMark.setGeometry(lineString);
lineString.setExtrude(5);
lineString.setTessellate(500);
lineString.setAltitudeOffset(5);
lineString.setAltitudeMode(m_ge.ALTITUDE_RELATIVE_TO_GROUND);
for (int x = 0; x < arraylat.Length; x++)
{
lineString.getCoordinates().pushLatLngAlt(Convert.ToDouble(arraylat[x]), Convert.ToDouble(arraylong[x]), 0);
}
//lineString.getCoordinates().pushLatLngAlt(Convert.ToDouble(arraylat[counter]), Convert.ToDouble(arraylong[counter]), 0);
lineStringPlaceMark.setStyleSelector(m_ge.createStyle("").getLineStyle());
if (null == lineStringPlaceMark.getStyleSelector())
{
lineStringPlaceMark.setStyleSelector(m_ge.createStyle("").getLineStyle());
}
var lineStyle = m_ge.createStyle("").getLineStyle();
lineStyle.setWidth(100);
lineStyle.getColor().set("9900ffff");
/* var lineStyle = lineStringPlaceMark.getStyleSelector().getLineStyle();
lineStyle.setWidth(lineStyle.getWidth() + 2);
lineStyle.getColor().set("6600ffff");
// The Style of a Feature is retrieved as feature.getStyleSelector().
// The Style itself contains a LineStyle, which is what we manipulate
// to change the color and width of the line.
*/
m_ge.getFeatures().appendChild(lineStringPlaceMark);
答案 0 :(得分:1)
首先需要通过GEPlugin.createStyle()
创建实际样式对象,然后才能使用它。
您的代码中存在一些错误。行
lineStringPlaceMark.setStyleSelector(m_ge.createStyle("").getLineStyle());
和
var lineStyle = m_ge.createStyle("").getLineStyle();
var lineStringPlaceMark = m_ge.createPlacemark(string.Empty);
var lineString = m_ge.createLineString(string.Empty);
lineStringPlaceMark.setGeometry(lineString);
lineString.setExtrude(5);
lineString.setTessellate(500);
lineString.setAltitudeOffset(5);
lineString.setAltitudeMode(m_ge.ALTITUDE_RELATIVE_TO_GROUND);
for (int x = 0; x < arraylat.Length; x++)
{
lineString.getCoordinates().pushLatLngAlt(
Convert.ToDouble(arraylat[x]),
Convert.ToDouble(arraylong[x]), 0);
}
// we know the placemark has no style, so create one for it
lineStringPlaceMark.setStyleSelector(m_ge.createStyle(string.Empty));
// now you can access the style object
var lineStyle = lineStringPlaceMark.getStyleSelector().getLineStyle();
lineStyle.setWidth(100);
lineStyle.getColor().set("9900ffff");
m_ge.getFeatures().appendChild(lineStringPlaceMark);
您还可以创建一个简单的静态方法,返回任何特征的样式选择器,如果它不存在则创建它。
// getStyleSelector wrapper, creates a style object if non is present
static dynamic GetStyleSelector(dynamic ge, dynamic feature) {
if(null == feature.getStyleSelector()) {
feature.setStyleSelector(ge.createStyle(string.Empty));
}
return feature.getStyleSelector();
}