Colored polygon outlines displayed as just all white opaque polygons - kml

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.

Related

Displaying vectors with origin and direction in Google Earth

Would like to display direction vectors at defined locations in Google Earth. In a 3D tool direction vectors differ from a position vector (i.e. 2 geographical points connected via a line) that the displayed size is independant of the zoom level, just dependant on the aspect angle (projection).
Side mote: Finally I would like to display 3 direction vectors which span a orthoganal coordinate frame. So each "vector" would point in 3D Space.
Any solution existing? Or any idea of workaround for it?
I am familiar with KML and already reached my first goal to display a ground track and to highlight areas of interests using polygons. However I have found no solution for my request.
You can create points with icon images that look like an arrow, and rotate them with the appropriate tags, like in the KML below. Try copy/pasting that into Earth Pro.
Note that in this example I used an easily available icon where the arrow points down, but you might want to use your own where the arrow points up, so that the icon heading matches the compass angle. Also, you can play with the icon hotspot tag, to define what part of the icon image is anchored at your point's lat/lon. In this case I used the center of the image, but you could use the origin or tip of the arrow if you wanted.
<?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>arrow icons with headings</name>
<Placemark>
<name>heading: 0</name>
<Style>
<IconStyle>
<scale>3</scale>
<heading>0</heading>
<Icon>
<href>http://maps.google.com/mapfiles/kml/shapes/arrow.png</href>
</Icon>
<hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
</IconStyle>
</Style>
<Point>
<coordinates>-90,38</coordinates>
</Point>
</Placemark>
<Placemark>
<name>heading: 75</name>
<Style>
<IconStyle>
<scale>3</scale>
<heading>75</heading>
<Icon>
<href>http://maps.google.com/mapfiles/kml/shapes/arrow.png</href>
</Icon>
<hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
</IconStyle>
</Style>
<Point>
<coordinates>-85,38</coordinates>
</Point>
</Placemark>
<Placemark>
<name>heading: 150</name>
<Style>
<IconStyle>
<scale>3</scale>
<heading>150</heading>
<Icon>
<href>http://maps.google.com/mapfiles/kml/shapes/arrow.png</href>
</Icon>
<hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
</IconStyle>
</Style>
<Point>
<coordinates>-80,38</coordinates>
</Point>
</Placemark>
</Document>
</kml>

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.

Displaying Names on the Map using KML

I am able to display polygons, circles, etc etc, using KML.
Now i want to display only some Names using KML. Is this Possible ?
If you want to suppress displaying the label of placemarks (via KML) on the map of Google Earth then you can add a LabelStyle to your placemarks with a 0 scale (see sn_hide style in example below). If you want to suppress the label name on the map until you hover over the icon then StyleMaps are your best bet.
The first placemark in example below has its name shown in the places panel but hidden from the map using the LabelStyle. The second placemark #2 uses a StyleMap to hide the label until the user highlights or mouses over the icon in which it activates the highlight style showing the label. The third placemark #3 uses the default style that always shows the label.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Hide and show labels</name>
<Style id="sn_hide">
<LabelStyle>
<scale>0</scale>
</LabelStyle>
</Style>
<Style id="sh_style">
<LabelStyle>
<scale>1.1</scale>
</LabelStyle>
</Style>
<StyleMap id="msn_hide">
<Pair>
<key>normal</key>
<styleUrl>#sn_hide</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#sh_style</styleUrl>
</Pair>
</StyleMap>
<Placemark>
<name>Placemark 1</name>
<description>Label name always hidden</description>
<styleUrl>#sn_hide</styleUrl>
<Point>
<coordinates>-119.232195,36.016021</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Placemark 2</name>
<description>Hover over place to show label</description>
<styleUrl>#msn_hide</styleUrl>
<Point>
<coordinates>-119.2324,36.0155</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Placemark 3</name>
<description>Always showing</description>
<Point>
<coordinates>-119.232672,36.014837</coordinates>
</Point>
</Placemark>
</Document>
</kml>

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('');
});

KML + Google Earth: Make a Polygon or GroundOverlay clickable?

Pretty simple question.
I've got some Polygons and GroundOverlays defined in KML. Is there a way to specify that they should be clickable, and (in Google Earth, at least) pop up an info balloon or similar when they are clicked?
Similarly, is it possible to give polygons/GroundOverlays any sort of mouseover behavior? e.g. change the icon or color when moused over?
Yes. Giving the Placemark a name and description will make it a clickable object in Google Earth and will open with an info window showing both. You can create rollover/mouseover behavior using stylemaps, here is an example that does both:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Highlighted Icon</name>
<description>Place your mouse over the icon to see it display the new
icon</description>
<StyleMap id="exampleStyleMap">
<Pair>
<key>normal</key>
<!-- you could also use a <styleUrl> here instead of inlining -->
<Style>
<PolyStyle>
<color>7dff0000</color>
</PolyStyle>
</Style>
</Pair>
<Pair>
<key>highlight</key>
<!-- you could also use a <styleUrl> here instead of inlining -->
<Style>
<PolyStyle>
<color>7dffffff</color>
</PolyStyle>
</Style>
</Pair>
</StyleMap>
<!-- and now, a Placemark that uses the StyleMap -->
<Placemark>
<name>Roll over this polygon</name>
<description>this will show up when clicked</description>
<visibility>1</visibility>
<styleUrl>#exampleStyleMap</styleUrl>
<Polygon>
<tessellate>1</tessellate>
<altitudeMode>absolute</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-112.3372510731295,36.14888505105317,1784
-112.3356128688403,36.14781540589019,1784
-112.3368169371048,36.14658677734382,1784
-112.3384408457543,36.14762778914076,1784
-112.3372510731295,36.14888505105317,1784
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>

Resources