Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i assign two styles to a placemark

Tags:

kml

kmz

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

like image 464
Hynek Avatar asked Mar 23 '14 15:03

Hynek


1 Answers

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.

like image 112
CodeMonkey Avatar answered Oct 20 '22 09:10

CodeMonkey