control of label visibility on placemarks

11,019

Solution 1

To control the display of labels in your KML you can either use Regions as you mentioned and/or a StyleMap with a normal and highlighted LabelStyle.

If you capture the HTTP traffic to Google Earth you'll notice the Borders and Labels default layer (among others) are implemented as KML files using Regions and nested NetworkLinks.

Regions

If you don't want to create a Region on every placemark then you could group your placemarks into folders and have a Region on the folder to control when placemarks are visible. Creating the regions correctly takes some trial and error. You may not even need to specify the min/max altitude -- an appropriate minLodPixels value to the region dimensions may be enough.

A tutorial on Regions can be found here.
https://developers.google.com/kml/documentation/regions

StyleMap

You may want to create a StyleMap where the normal Style has a LabelStyle with a scale of 0 to suppress the labels entirely or a smaller value to simply reduce the clutter.

    <Style id="sn_style">
        <LabelStyle>
            <scale>0</scale>
        </LabelStyle>
    </Style>

    <Style id="sh_style">
        <LabelStyle>
            <scale>1.1</scale>
        </LabelStyle>
    </Style>

   <StyleMap id="msn_style">
        <Pair>
            <key>normal</key>
            <styleUrl>#sn_style</styleUrl>
        </Pair>
        <Pair>
            <key>highlight</key>
            <styleUrl>#sh_style</styleUrl>
        </Pair>
    </StyleMap>

Solution 2

Had the Same Problem and I couldn't find any quick solution for the as my .kml contained almost 10k POI's. So what I did was adding the code offered by the FAQ, so my header would look like this:

<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document><Folder><name>name</name><Style id="hideLabel"><LabelStyle><scale>0</scale></LabelStyle></Style>

And I changed the first placemark to this:

Placemark>
    <name>name</name>
    <styleUrl>#hideLabel</styleUrl>
    <ExtendedData><SchemaData schemaUrl="#name">
        <SimpleData name="Name">name</SimpleData>
        <SimpleData name="Latitude">xxxx</SimpleData>
        <SimpleData name="Longitude">yyyy</SimpleData>
    </SchemaData></ExtendedData>
      <Point><coordinates>xxxx,yyyy</coordinates></Point>
  </Placemark>

After that I loaded the .kml into Google Earth and right-clicked onto it to select Properties. Select "Style, Color" tab and it should state the following:

The descendant(s) of this folder do not share the same Style. Click the button below if you want to force all descendants to share the same Style

Click the button below "Share Style" and it will temporarily hide all the labels.

Kind regards,

Thomas

Share:
11,019
Admin
Author by

Admin

Updated on June 16, 2022

Comments

  • Admin
    Admin almost 2 years

    I have a kml file with many simple point placemarks each with a name that cover the USA. I am trying to find a way to control their label display so that the view is not cluttered at higher altitudes. I've seen mention the use of Regions but it appears this would have to be applied on each placemark. I know something must be available for this since GE is doing this very thing on the default layers, i.e. Populated Places. Further, there seems to be some default at work when I zoom far enough out the labels disappear without any input on my kml.

    Any comments are appreciated!!