Question

i am new to KML and this should be simple but i can't figure it out.

In my KML i have several styles defined and can assign them easily to a specific placemark with the styleUrl-tag. My styles differ only in the background-color from each other but they also contain a rather complicated "BalloonStyle" which is the same for ALL of them. Now i don't want to copy this same ballonstyle into every style i have and increase the size of my KML.

What i need is to assign to a placemark two styles like i would do in CSS:

<styleUrl>#greenArea #myBalloonStyle</styleUrl>

<styleUrl>#redArea #myBalloonStyle</styleUrl>

Or write into my style something that it "inherits" its balloon-style from a second style.

Thank you in advance

Was it helpful?

Solution

A KML feature can only contain a single styleUrl with a single style reference but the feature can also contain an inline Style element. This technique is called a "merged" style.

In the case where a feature has both a shared style and inline style, the shared style is applied first then the inline style overrides whatever is already specified in the former.

If you use the BallonStyle as a shared style then you can override specific elements such as color in the inline style.

<Placemark>
    <styleUrl>#myBalloonStyle</styleUrl>
    <Style>
       <LabelStyle>
          <color>ff0000cc</color>
       </LabelStyle>
    </Style>
</Placemark>

Here's a complete example with a global BalloonStyle. Click "Raw", save contents to a local file, then open in Google Earth.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top