Refresh KML stylesheet in Google Earth - kml

I have an externally defined stlysheet, named style.kml which defines the different styles I use in my maps. Recently, I added a new style, defined identically to the other styles, just with a different icon, but it wont load into Google Earth.
The style looks like:
Style id="red-dsl">
<LabelStyle>
<color>ffffffff</color>
<colorMode>normal</colorMode>
<scale>0.8</scale>
</LabelStyle>
<IconStyle>
<hotSpot x="0.5" y="0.05" xunits="fraction" yunits="fraction"/>
<Icon>
<href>URL/crimson-d.png</href>
</Icon>
</IconStyle>
<LineStyle>
<color>7f1f1fff</color>
<width>2.0</width>
</LineStyle>
<PolyStyle>
<color>401f1fbf</color>
</PolyStyle>
</Style>
Where URL is our private URL, and is being called with
$placemark->styleUrl = "style.kml#red-dsl";
I know it is assigning correctly, because if I use one of the older style-types, then the icon appears correctly.
I have tried re-compiling the kml file, deleting/refreshing the cache, but no luck so far.
How can I refresh/reload the KML stylesheet for my Google Earth maps?

After checking the map everyday for a week, it started working with the right icon after 9+ days. Im not sure what changed, but it seems like leaving it for a considerable length of time will fix the problem.

Related

Colored polygon outlines displayed as just all white opaque polygons

Someone shared a kml with me that was created in Google Earth Web along with a screenshot of it.
When I opened it up in Google Earth Pro, the colored polygons displayed as solid white.
For a test, I created a test polygon in Google Earth Web and exported it as KML.
Projects > New project > Create KML file
Draw line or shape > create polygon
Set fill color red at 75%
Set color 4px
Select export as KML
Same thing, the polygon shows up as a white box in Google Earth Pro.
The exported KML is structured like this:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns=http://www.opengis.net/kml/2.2 xmlns:gx=http://www.google.com/kml/ext/2.2 xmlns:kml=http://www.opengis.net/kml/2.2 xmlns:atom=http://www.w3.org/2005/Atom>
<Document>
<name>Untitled Project</name>
<gx:CascadingStyle kml:id="__managed_style_147D324643211BD21CEE">
<Style>
<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>
<color>ffa21f7b</color>
<width>3.63636</width>
</LineStyle>
<PolyStyle>
<color>c02f2fd3</color>
</PolyStyle>
<BalloonStyle>
<displayMode>hide</displayMode>
</BalloonStyle>
</Style>
</gx:CascadingStyle>
...
<StyleMap id="__managed_style_0C1991940B211BD21CEE">
<Pair>
<key>normal</key>
<styleUrl>#__managed_style_147D324643211BD21CEE</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#__managed_style_2EB2C27FFE211BD21CEE</styleUrl>
</Pair>
</StyleMap>
<Placemark id="09A507D5E3211BD1D53F">
<name>Test Polygon</name>
<styleUrl>#__managed_style_0C1991940B211BD21CEE</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
0.0287244781654028,51.5286273373769,4.888032506075639 0.03124375777183053,51.52899071640604,5.649232085770059 0.03060716674301966,51.5305703663013,6.296306355936279 0.02835525808849049,51.53027540191405,5.649128389213159 0.0287244781654028,51.5286273373769,4.888032506075639
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>
The <gx:CascadingStyle> does not appear in the KML reference.
https://developers.google.com/kml/documentation/kmlreference
What is going on here?
i am expecting the original colored polygon to appear in Google Earth Pro.
The <gx:CascadingStyle> is an undocumented element that is created in Google Earth Web that is unsupported by Google Earth Pro.
If you make a minor edit to the KML, then it will work as expected.
Make these changes:
Remove <Style> and </Style> elements.
Globally change <gx:CascadingStyle kml:id="xxx"> to <Style id="xxx">.
Replace <gx:CascadingStyle kml:id= with <Style id=
Replace </gx:CascadingStyle> with</Style>
Example:
Old:
<gx:CascadingStyle kml:id="__managed_style_147D324643211BD21CEE">
<Style>
...
</Style>
</gx:CascadingStyle>
New:
<Style id="__managed_style_147D324643211BD21CEE">
...
</Style>
You can globally make the changes to the KML using a text editor; e.g. Notepad++.
The KML is now valid with respect to the OGC KML 2.2 standard and will work in Google Earth Pro.

Multiple icons in one KML Placemark

I have some symbols that I want to add to a KML file (for Google Earth). However, my symbols consist of multiple icons overlayed on top of each other. For other maps that I use I simply draw the icons on top of each other and control the selection/right click actions so that the user only sees it as one object, but in Google Earth if I add each overlayed icon as a separate placemark the user sees multiple objects when they click on it. Is there a way to add a single placemark in kml with multiple icons?
I wanted to do something like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:ns2="http://www.w3.org/2005/Atom" xmlns:ns3="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<Document>
<name>kmlTest</name>
<open>true</open>
<description>description</description>
<StyleMap id="Symbol0Map">
<Pair id="Symbol0MapPairNormal">
<key>normal</key>
<Style id="Symbol0normal">
<IconStyle id="Symbol0iconStyle">
<scale>1.0</scale>
<heading>0.0</heading>
<Icon>
<href>files/images/GenericGround_0.png</href>
</Icon>
<Icon>
<href>files/images/eqp_2.png</href>
</Icon>
</IconStyle>
<LabelStyle id="Symbol0labelStyle">
<color>FF00FFFF</color>
<colorMode>normal</colorMode>
<scale>0.0</scale>
</LabelStyle>
</Style>
</Pair>
<Pair id="Symbol0MapPairHighlight">
<key>highlight</key>
<!-- similar to above -->
</Pair>
</StyleMap>
<Folder>
<name>My Layers</name>
<visibility>true</visibility>
<open>true</open>
<Folder>
<name>My Layer</name>
<visibility>true</visibility>
<open>false</open>
<Folder>
<name>Symbols</name>
<visibility>true</visibility>
<open>false</open>
<Placemark id="Placemark0">
<visibility>true</visibility>
<open>false</open>
<description>Platform</description>
<styleUrl>#Symbol0Map</styleUrl>
<Point>
<coordinates>-123.1569,38.5962,0.0</coordinates>
</Point>
</Placemark>
</Folder>
</Folder>
</Folder>
</Document>
</kml>
where I just have multiple <Icon> tags (or multiple <IconStyle> tags). However, looking at the schema this is not valid and I tried it anyways and it only picks the last one.
Is this even possible or will I need to dynamically create rolled up icons in code and include those in my .kmz file?
A KML placemark can only have one icon image. You will need to combine (roll up) your icons into a single image and then apply that to the placemark.

Is it possible to load KML Icons without a full HREF in their styles?

I have a SIMPLE.KML file generated with ArcMap, with vectors such as this one:
<Placemark id="ID_0001">
<name>0</name>
<styleUrl>#IconStyle00</styleUrl>
<Point>
<altitudeMode>clampToGround</altitudeMode>
<coordinates> -6.745,43.568,1.511693</coordinates>
</Point>
</Placemark>
And this kind of styles:
<Style id="IconStyle00">
<IconStyle>
<Icon><href>SYMBOL_XXX.png</href></Icon>
<scale>1.0</scale>
</IconStyle>
<LabelStyle>
<color>00000000</color>
<scale>0.000000</scale>
</LabelStyle>
<PolyStyle>
<color>ff000000</color>
<outline>0</outline>
</PolyStyle>
</Style>
The file SYMBOL_XXX.png is in the same folder as the SIMPLE.KML.
The problem is that the Icon 'is not found' by OL3 when I try to load the kml in a map (as in http://openlayers.org/en/v3.9.0/examples/kml.html , with extractStyles:true), because it considers the href an absolute url, instead of a relative one.
I would like to know it there is a work-around, without having to edit the .kml (I have a quite high number of kmls and still without a definitive folder structure).
Wouldn't it be useful to have some kind of option in ol.format.KML for this use case ('localResources': true'...)?
Thanks!
You can use the OpenLayers Vector with KML source which will extract and use Styles with absolute or relative URLs.
var vector = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'data/kml/2012-02-10.kml',
//format: new ol.format.KML()
format: new ol.format.KML({extractStyles: true})
})
});
Note extractStyles by default is true so both format lines with and without extractStyles parameter above do the same thing. See http://openlayers.org/en/v3.9.0/apidoc/ol.format.KML.html
However, the trick is that relative icons are relative to the HTML document context not the KML file.
KML Example:
<Style id="style-Restaurant">
<IconStyle>
<scale>0.7</scale>
<Icon>
<href>icon40.png</href>
</Icon>
</IconStyle>
</Style>
If KML is located in "data/kml" and relative icon is referenced then OpenLayers will resolve local icons relative to the HTML document context. Then icon40.png must be co-located with HTML page. If KML file is in the same folder as HTML then all relative links with work normally.

control of label visibility on placemarks

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!!
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>
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

Dynamic KML placemark name display possible?

I am looking to have two names for a placemark, one displayed when the placemark is hovered over, and one when it is not hovered over. The only information I've been able to find is changing the style (icon type, color, opacity, scale) for a highlighted placemark style. Any suggestions? Is this possible?
http://code.google.com/apis/kml/documentation/kml_tut.html#custom_styles
You could use custom icons to present a pseudo name (an image of the text you require) and another roll over pseudo name in the same manner.
This is called "styles for Highlighted Icons", to use it you would need to create and upload the two jpg images
nameImageOver.jpg
and
nameImageNormal.jpg
The kml would look like so:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Highlighted Icon</name>
<description>Mouse over to see the swap</description>
<Style id="highlightPlacemark">
<IconStyle>
<Icon>
<href>http://www.yourserver.com/nameImageOver.jpg</href>
</Icon>
</IconStyle>
</Style>
<Style id="normalPlacemark">
<IconStyle>
<Icon>
<href>http://www.yourserver.com/nameImageNormal.jpg</href>
</Icon>
</IconStyle>
</Style>
<StyleMap id="exampleStyleMap">
<Pair>
<key>normal</key>
<styleUrl>#normalPlacemark</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#highlightPlacemark</styleUrl>
</Pair>
</StyleMap>
<Placemark>
<styleUrl>#exampleStyleMap</styleUrl>
<Point>
<coordinates>-122.0856545755255,37.42243077405461,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
I have achieved this using the Google Earth API. Not sure how this plays in with using KML...
// On mouse over - show name
google.earth.addEventListener(placemark, 'mouseover', function(event) {
placemark.setName('My Placemark Label');
});
// On mouse out - hide (remove) name
google.earth.addEventListener(placemark, 'mouseout', function(event) {
placemark.setName('');
});

Resources