Missing Styles when loading KML file into Openlayers created in Google Earth
The CascadingStyle
tag isn't supported, but this works
<Style id="__managed_style_25EBAAC82614827EFCCB">
<IconStyle>
<scale>1.2</scale>
<Icon>
<href>https://earth.google.com/earth/rpc/cc/icon?color=1976d2&id=2000&scale=4</href>
</Icon>
<hotSpot x="64" y="128" xunits="pixels" yunits="insetPixels"/>
</IconStyle>
<LabelStyle>
</LabelStyle>
<LineStyle>
<width>24</width>
</LineStyle>
<PolyStyle>
<color>80000000</color>
</PolyStyle>
<BalloonStyle>
<displayMode>hide</displayMode>
</BalloonStyle>
</Style>
<Style id="__managed_style_14CDD4276C14827EFCCB">
<IconStyle>
<Icon>
<href>https://earth.google.com/earth/rpc/cc/icon?color=1976d2&id=2000&scale=4</href>
</Icon>
<hotSpot x="64" y="128" xunits="pixels" yunits="insetPixels"/>
</IconStyle>
<LabelStyle>
</LabelStyle>
<LineStyle>
<width>16</width>
</LineStyle>
<PolyStyle>
<color>80000000</color>
</PolyStyle>
<BalloonStyle>
<displayMode>hide</displayMode>
</BalloonStyle>
</Style>
So, finally I came up with the following solution as the OL Parser does not support cascadingStyle Tag:
function removeBadTags (rawSource) {
let result = rawSource;
// remove "cascadingStyle" Tags
result = rawSource.replace(/<.*?cascadingstyle.*?kml:id="(.+)">\s*<style>/gmi, (a, b) => {
return "<Style id=\"" + b + "\">";
});
result = result.replace(/<\/Style>\s*<\/.*?cascadingstyle>/gmi, "</Style>");
// ... remove more tags eventually
return result;
}
Most likely not the most solid and elegant solution, however, it seems to work.