samcragg / sharpkml

SharpKML is an implementation of the Open Geospatial Consortium (OGC) KML 2.2 standard developed in C#, able to read/write both KML files and KMZ files.
MIT License
158 stars 51 forks source link

StyleResolver.CreateResolvedStyle is unable to resolve style when '#' is missing at the beginning of the style url #36

Closed yvz-dmr closed 3 years ago

yvz-dmr commented 3 years ago

Hi, i am using this library to visualize kml files in unity 2019.2.17f1 and everything is okey except from this behaviour. I am wondering if this is the intended behaviour or is it a bug or i am using it wrong.

I tried to open same file in google earth and everything works fine.

I am loding file from string

 public static KmlFile LoadKmlFileFromXmlString(string xml) {
    if (string.IsNullOrEmpty(xml)) return null;

    var parser = new Parser();
    parser.ParseString(xml, false);

    if (parser.Root == null) return null;

    return KmlFile.Create(parser.Root, true);
}

and this how i try to resolve style

var style = StyleResolver.CreateResolvedStyle(placemark, kmlFile, StyleState.Normal);

In debug mode i can see file has 3 styles, but when i try to resolve it returns nothing as style

You can download file i am having problem here https://public.3.basecamp.com/p/PWeUaJRXWZhuSHorbfmv5gjf

samcragg commented 3 years ago

Thanks for providing the sample.

As you've discovered, the url must start with a # (see this documentation, so I'm not sure I can change anything and still be compliant with the spec.

If it's a file that's generated from another program and you think it's something that should be supported, I can take a look at perhaps providing a compatability setting. For now though, I'll close the issue as the correct form for the style is in the format #styleA but feel free to reopen if there's something that you feel could be changed.