gpt4 book ai didi

c# - C# 中的 Google 地球插件

转载 作者:太空宇宙 更新时间:2023-11-03 13:28:56 26 4
gpt4 key购买 nike

在本教程中,您可以自定义 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);

最佳答案

您首先需要通过 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();
}

关于c# - C# 中的 Google 地球插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21323831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com