cleder / fastkml

Fast 🌍️ KML processing for python
https://fastkml.readthedocs.io
217 stars 90 forks source link

Support gx:CascadingStyle #311

Open OxygenCobalt opened 6 months ago

OxygenCobalt commented 6 months ago

Hello,

We've ran into an issue on our end where we cannot extract Polygon colors from the Google Earth KML files we exported on our end, as they are contained within a gx:CascadingStyle extension element that is not read. At minimum it would be useful for fastkml to read this element when it is referenced by styleUrl and then apply the relevant styles to the object being read.

Thanks.

cleder commented 6 months ago

I cannot find documentation about gx:CascadingStyle

OxygenCobalt commented 6 months ago

From what I see it's basically like any other Style element but presumably cascades some inherited style like CSS. I'm not too well-versed on KML though. All I want is for fastkml to recognize it as a Style and use it, the actual functionality isn't needed.

Here's a CascadingStyle from our KML file:

<gx:CascadingStyle kml:id="__managed_style_881999257A2F4EDCAD33">
    <styleUrl>https://earth.google.com/balloon_components/base/1.0.26.0/card_template.kml#main</styleUrl>
    <Style>
        <IconStyle>
            <scale>1.2</scale>
            <Icon>
                <href>https://earth.google.com/earth/rpc/cc/icon?color=1976d2&amp;id=2000&amp;scale=4</href>
            </Icon>
            <hotSpot x="64" y="128" xunits="pixels" yunits="insetPixels"/>
        </IconStyle>
        <LabelStyle>
        </LabelStyle>
        <LineStyle>
            <color>ff2846cc</color>
            <width>3</width>
        </LineStyle>
        <PolyStyle>
            <color>40ffffff</color>
        </PolyStyle>
        <BalloonStyle>
        </BalloonStyle>
    </Style>
</gx:CascadingStyle>

Hope this helps @cleder

cleder commented 5 months ago

The architecture has changed a lot from fastkml 0.x to 1.x.

One of the advantages of these changes is that you can define and add new behaviour at runtime through the registry. What is still missing to be able to add arbitrary XML structures is that **kwargs should be added to the base._XMLObject and propagated through the inheritance chain. This way, the integration of things like gx:CascadingStyle can be implemented by the end user without patching the underlying fastkml library.

Ping me if you are interested in helping to implement this.

cleder commented 3 months ago

https://stackoverflow.com/questions/71744669/colored-polygon-outlines-displayed-as-just-all-white-opaque-polygons https://gis.stackexchange.com/questions/367688/missing-styles-when-loading-kml-file-into-openlayers-created-in-google-earth