编程语言
首页 > 编程语言> > c# – 如何使用SharpKml创建StyleMap标签?

c# – 如何使用SharpKml创建StyleMap标签?

作者:互联网

我想知道如何使用SharpKml创建以下XML

<StyleMap id="msn_placemark_circle">
    <Pair>
        <key>normal</key>
        <styleUrl>#sn_placemark_circle</styleUrl>
    </Pair>
    <Pair>
        <key>highlight</key>
        <styleUrl>#sh_placemark_circle_highlight</styleUrl>
    </Pair>
</StyleMap>

我尝试了几件事,但没有成功.这是我到目前为止:

public static StyleSelector Generate_M_ylw_pushpin3()
{
    var stylemap = new StyleMapCollection();
    stylemap.Id = "s_ylw-pushpin3";
    var normalPair = new Pair();
    normalPair.Id = "normal";
    normalPair.Selector = StyleGenerator.Generate_s_ylw_pushpin_hl3();
    //normalPair.StyleUrl = new Uri(#sh_placemark_circle_highlight); // Exception by .NET

    var highlightPair = new Pair();
    highlightPair.Id = "highlight";
    highlightPair.Selector = StyleGenerator.Generate_s_ylw_pushpin_hl3();
    //highlightPair.StyleUrl = new Uri(#sh_placemark_circle_highlight); // Exception by .NET

    stylemap.Add(normalPair);
    stylemap.Add(highlightPair);

    return stylemap;
}

// This code just works fine
public static StyleSelector Generate_s_ylw_pushpin_hl3()
{
    var style = new Style();
    style.Id = "s_ylw-pushpin_hl3";
    var iconStyle = new IconStyle();
    iconStyle.Color = Color32.Parse("ff00ff00");
    iconStyle.Scale = 1.18182;
    iconStyle.Icon = new IconStyle.IconLink(new Uri("http://some/url"));
    var labelStyle = new LabelStyle();
    labelStyle.Color = Color32.Parse("00ffffff");

    style.Icon = iconStyle;
    style.Label = labelStyle;

    return style;
}

谁知道如何实现这一目标?

解决方法:

我找到了自己问题的答案:

public static StyleSelector Generate_M_ylw_pushpin3()
{
    var stylemap = new StyleMapCollection();
    stylemap.Id = "s_ylw-pushpin3";
    var normalPair = new Pair();
    normalPair.StyleUrl = new Uri("#sh_placemark_circle", UriKind.Relative); 
    normalPair.State = StyleState.Normal;

    var highlightPair = new Pair();
    highlightPair.StyleUrl = new Uri("#sh_placemark_circle_highlight", UriKind.Relative); 
    highlightPair.State = StyleState.Highlight;

    stylemap.Add(normalPair);
    stylemap.Add(highlightPair);

    return stylemap;
}

标签:c,kml,sharpkml
来源: https://codeday.me/bug/20190628/1318472.html