I've got a question referring to the BalloonStyle Tutorial in the KML documentiation:
BalloonStyle Documentation
Playing around with this KML file:
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>ExtendedData+SchemaData</name>
<open>1</open>
<!-- Create a balloon template referring to the user-defined type -->
<Style id="trailhead-balloon-template">
<BalloonStyle>
<text>
<![CDATA[
<h2>My favorite trails!</h2>
<br/><br/>
The $[TrailHeadType/TrailHeadName/displayName] is <i>$[TrailHeadType/TrailHeadName]</i>.
The trail is $[TrailHeadType/TrailLength] miles. <br/>
The climb is $[TrailHeadType/ElevationGain] meters. <br/><br/>
]]>
</text>
</BalloonStyle>
</Style>
<!-- Declare the type "TrailHeadType" with 3 fields -->
<Schema name="TrailHeadType" id="TrailHeadTypeId">
<SimpleField type="string" name="TrailHeadName">
<displayName><![CDATA[<b>Trail Head Name</b>]]></displayName>
</SimpleField>
<SimpleField type="double" name="TrailLength">
<displayName><![CDATA[<i>The length in miles</i>]]></displayName>
</SimpleField>
<SimpleField type="int" name="ElevationGain">
<displayName><![CDATA[<i>change in altitude</i>]]></displayName>
</SimpleField>
</Schema>
<!-- Instantiate some Placemarks extended with TrailHeadType fields -->
<Placemark>
<name>Easy trail</name>
<styleUrl>#trailhead-balloon-template</styleUrl>
<ExtendedData>
<SchemaData schemaUrl="#TrailHeadTypeId">
<SimpleData name="TrailHeadName">Pi in the sky</SimpleData>
<SimpleData name="TrailLength">3.14159</SimpleData>
<SimpleData name="ElevationGain">10</SimpleData>
</SchemaData>
</ExtendedData>
<Point>
<coordinates>-122.000,37.002</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Difficult trail</name>
<styleUrl>#trailhead-balloon-template</styleUrl>
<ExtendedData>
<SchemaData schemaUrl="#TrailHeadTypeId">
<SimpleData name="TrailHeadName">Mount Everest</SimpleData>
<SimpleData name="TrailLength">347.45</SimpleData>
<SimpleData name="ElevationGain">10000</SimpleData>
</SchemaData>
</ExtendedData>
<Point>
<coordinates>-121.998,37.0078</coordinates>
</Point>
</Placemark>
</Document>
</kml>
When you remove one of the SimpleData elements, Google Earth shows the Entity Replacement from the Balloon Template. For example you remove the line <SimpleData name="ElevationGain">10000</SimpleData>
it shows up in the Balloon like "The climb is $[TrailHeadType/ElevationGain] meters." Which doesn't look very nice.
Any idea how to tell Google Earth, that it shouldn't display the line from the balloon, if there is a missing SimpleData?
Thanks in Advance
I don't think* you can do what you are asking here - i.e. apply conditional logic within this style text. I have had a similar requirement in the past (certain pieces of data were missing from some of my placemarks) and I ended up applying different styles for each of the possible scenarios of missing information when generating the KML.
It felt both very clunky and if you have a large number of scenarios of one or more items being missing while others exist it could quickly be a mess.
*Would love to be wrong.
UPDATE
Just looked at my code for this, and I actually ended up putting all the text in the placemark fields of my schema, and printing out empty nodes when I did not have data - also less elegant, but did not require additional styles in the end. Based on your example something like:
<BalloonStyle>
<text>
<![CDATA[
<h2>My favorite trails!</h2>
$[TrailHeadType/TrailHeadName/displayName]
$[TrailHeadType/TrailLengthBalloonText]
$[TrailHeadType/ElevationGainBalloonText]
]]>
</text>
</BalloonStyle>
<Placemark>
<name>Difficult trail</name>
<styleUrl>#trailhead-balloon-template</styleUrl>
<ExtendedData>
<SchemaData schemaUrl="#TrailHeadTypeId">
<SimpleData name="TrailHeadName">Mount Everest</SimpleData>
<SimpleData name="TrailLength">347.45</SimpleData>
<SimpleData name="ElevationGain">10000</SimpleData>
<SimpleData name="TrailHeadNameBalloonText"><![CDATA[The trail name is Mount Everest</br>]]></SimpleData>
<SimpleData name="TrailLengthBalloonText"><![CDATA[The trail is 347.45 miles.</br>]]></SimpleData>
<SimpleData name="ElevationGainBalloonText"><![CDATA[The climb is 10000 meters.</br>]]></SimpleData>
</SchemaData>
</ExtendedData>
<Point>
<coordinates>-121.998,37.0078</coordinates>
</Point>
</Placemark>
Then when you have no data you leave that item blank:
<Placemark>
<name>Difficult trail</name>
<styleUrl>#trailhead-balloon-template</styleUrl>
<ExtendedData>
<SchemaData schemaUrl="#TrailHeadTypeId">
<SimpleData name="TrailHeadName">Mount Everest</SimpleData>
<SimpleData name="TrailLength">347.45</SimpleData>
<SimpleData name="ElevationGain">10000</SimpleData>
<SimpleData name="TrailHeadNameBalloonText"><![CDATA[The trail name is Mount Everest</br>]]></SimpleData>
<SimpleData name="TrailLengthBalloonText"></SimpleData>
<SimpleData name="ElevationGainBalloonText"></SimpleData>
</SchemaData>
</ExtendedData>
<Point>
<coordinates>-121.998,37.0078</coordinates>
</Point>
</Placemark>
As my data are changing somehow quite often, I'm now providing a xml file linked to an css file and embed it as an iframe in the description. For offline use, create a kmz and put the xml and css into it.
For a small tutorial have a look here:
http://www.w3schools.com/xml/xml_display.asp
In the kml, it looks as follows:
<description>
<![CDATA[
<iframe src="http://www.w3schools.com/xml/cd_catalog_with_css.xml"></iframe>
]]>
</description>
Related
I notice certain behaviour using ExtendedData in KML which I feel renders the use of ExtendedData questionable, especially if the trackway crosses itself.
I would like to know if there is a fix or workaround?
GoogleEarth (v7.3.2.5491 (32-bit)) appears to do calculation on the fly to calculate the nearest waypoint to the clicked position. This is a problem if the nearest waypoint by crow-flies distance is further away along the trackway taking time into account. I have an MRE here...
<kml xmlns="http://earth.google.com/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document xmlns="http://earth.google.com/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<name>2018-08-27_Mon</name>
<Schema id="schema">
<gx:SimpleArrayField name="gps_coords" type="string">
<displayName>GPS Coords</displayName>
</gx:SimpleArrayField>
<gx:SimpleArrayField name="ping_time" type="string">
<displayName>Ping Time</displayName>
</gx:SimpleArrayField>
</Schema>
<Folder xmlns="http://earth.google.com/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<name>Tracks</name>
<Placemark xmlns="http://earth.google.com/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<name>Trackway</name>
<styleUrl>#my_track</styleUrl>
<gx:Track xmlns="http://earth.google.com/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<altitudeMode>clampToGround</altitudeMode>
<when>1970-01-01T05:02:28Z</when>
<when>1970-01-01T09:04:00Z</when>
<when>1970-01-01T11:06:00Z</when>
<when>1970-01-01T14:59:30Z</when>
<when>1970-01-01T15:02:00Z</when>
<when>1970-01-01T17:03:11Z</when>
<gx:coord>-8.460239 54.253286 0</gx:coord>
<gx:coord>-8.460439 54.256286 0</gx:coord>
<gx:coord>-8.460639 54.259286 0</gx:coord>
<gx:coord>-8.467867 54.262505 0</gx:coord>
<gx:coord>-8.462653 54.256286 0</gx:coord>
<gx:coord>-8.460599 54.250317 0</gx:coord>
<ExtendedData>
<SchemaData schemaUrl="#schema">
<gx:SimpleArrayData name="gps_coords">
<gx:value>No 1. 54.253286 -8.460239</gx:value>
<gx:value>No 2. 54.256286 -8.460439</gx:value>
<gx:value>No 3. 54.259286 -8.460539</gx:value>
<gx:value>No 4. 54.262505 -8.467867</gx:value>
<gx:value>No 5. 54.256286 -8.462653</gx:value>
<gx:value>No 6. 54.250317 -8.460599</gx:value>
</gx:SimpleArrayData>
<gx:SimpleArrayData name="ping_time">
<gx:value>2018-08-27T05:02:28Z</gx:value>
<gx:value>2018-08-27T09:04:00Z</gx:value>
<gx:value>2018-08-27T11:06:00Z</gx:value>
<gx:value>2018-08-27T14:59:30Z</gx:value>
<gx:value>2018-08-27T15:02:00Z</gx:value>
<gx:value>2018-08-27T17:03:11Z</gx:value>
</gx:SimpleArrayData>
</SchemaData>
</ExtendedData>
</gx:Track>
</Placemark>
</Folder>
<Folder>
<Placemark>
<TimeStamp>
<when>1970-01-01T05:02:28Z</when>
</TimeStamp>
<description>Desc No 1. 54.253286 -8.460239</description>
<styleUrl>#waypoint</styleUrl>
<Point>
<coordinates>-8.460239 54.253286 0</coordinates>
</Point>
</Placemark>
<Placemark>
<TimeStamp>
<when>1970-01-01T09:04:00Z</when>
</TimeStamp>
<description>Desc No 2. 54.256286 -8.460439</description>
<styleUrl>#waypoint</styleUrl>
<Point>
<coordinates>-8.460439 54.256286 0</coordinates>
</Point>
</Placemark>
<Placemark>
<TimeStamp>
<when>1970-01-01T11:06:00Z</when>
</TimeStamp>
<description>Desc No 3. 54.259286 -8.460539</description>
<styleUrl>#waypoint</styleUrl>
<Point>
<coordinates>-8.460639 54.259286 0</coordinates>
</Point>
</Placemark>
<Placemark>
<TimeStamp>
<when>1970-01-01T14:59:30Z</when>
</TimeStamp>
<description>Desc No 4. 54.262505 -8.467867</description>
<styleUrl>#waypoint</styleUrl>
<Point>
<coordinates>-8.467867 54.262505 0</coordinates>
</Point>
</Placemark>
<Placemark>
<TimeStamp>
<when>1970-01-01T15:02:00Z</when>
</TimeStamp>
<description>Desc No 5. 54.256286 -8.462653</description>
<styleUrl>#waypoint</styleUrl>
<Point>
<coordinates>-8.462653 54.256286 0</coordinates>
</Point>
</Placemark>
<Placemark>
<TimeStamp>
<when>1970-01-01T17:03:11Z</when>
</TimeStamp>
<description>Desc No 6. 54.250317 -8.460599</description>
<styleUrl>#waypoint</styleUrl>
<Point>
<coordinates>-8.460599 54.250317 0</coordinates>
</Point>
</Placemark>
</Folder>
</Document>
</kml>
Clicking on the trackway midway between #4 and #5 pops up the ExtendedData for #3. Same with #5 and #6 resulting in #1 opening. It kind of makes senses because the trackway is just painted as the straight line between two points and does not have its own geometry. So, I could live with that even though a naive user might expect a precise popup for the intermediate positions. However, if I move the time slider to exclude/disappear points #1, #2, and #3, I would now expect #1, #2, and #3 to be excluded from the calculations. But this is not the case. The same results as above obtain. That is not what I would expect.
In this MRE it is not a problem as such but on a large trackway with several hundred points and the trackway going over and back across itself throughout the day, then such ExtendedData popups are, IMO, ususable.
To work around it, I have created a CDATA description for the each waypoint in the track which is acceptable
Is there a KML workaround for this behaviour or is it just the way GE implements it? Any other suggestions perhaps?
Liam
Google Earth Pro behaves in such a way that when clicking the segment of track past the mid-point gives the metadata for the next waypoint. This is what you are seeing when clicking on a track and seeing metadata for another point.
Also note the KML above does not conform to the KML 2.2 standard. Couple of validation issues.
There should not be any whitespace in the point coordinates. The whitespace should be replaced with a comma (,):
old:
<Point>
<coordinates>-8.460239 54.253286 0</coordinates>
</Point>
new:
<Point>
<coordinates>-8.460239,54.253286,0</coordinates>
</Point>
The namespace should be xmlns="http://www.opengis.net/kml/2.2" rather than the old form of http://earth.google.com/kml/2.2.
Some of the element are out of sequence. KML 2.2 has a strict order of elements (see reference) but Google Earth generally ignores the order of elements. The correct order of elements is as follows:
<Placemark>
<description>...</description>
<TimeStamp>...</TimeStamp>
<styleUrl>...</styleUrl>
<Point>...</Point>
</Placemark>
I'm doing a proof-of-concept map. Goal is half sized labels, with red font, and no icon. I've tried everything, even copy pasting from the google KML reference manuals and many examples posted here. What am I missing? I'm trying to display the map in both Google's "My maps" and also as a called data file at the browser utility gmap4. The test map should show four labels with Google streetmap of Pennsylvania for a baselayer...... Thanks for any help.
<?xml version="1.0" standalone="yes"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<Style id="NoIconRedTextHalfSize">
<IconStyle>
<scale>.1</scale>
<Icon>
<href>https://maps.google.com/mapfiles/kml/paddle/grn-stars.png</href>
</Icon>
</IconStyle>
<LabelStyle>
<Color>FF1400FF</Color>
<Scale>.5</Scale>
</LabelStyle>
</Style>
<Folder>
<Placemark>
<name>Hs-4-C.Sonney</name>
<styleUrl>#NoIconRedTextHalfSize</styleUrl>
<Point>
<coordinates>1,1,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Hs-5-B.Jozwiak</name>
<styleUrl>#NoIconRedTextHalfSize</styleUrl>
<Point>
<coordinates>1,1,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Hs-6-B.Roae</name>
<styleUrl>#NoIconRedTextHalfSize</styleUrl>
<Point>
<coordinates>1,1,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Hs-7-M.Longietti</name>
<styleUrl>#NoIconRedTextHalfSize</styleUrl>
<Point>
<coordinates>1,1,0</coordinates>
</Point>
</Placemark>
</Folder>
</Document>
</kml>
The KML syntax includes a number of tags that are not supported by plain Google maps (my map) or by sotfware based on the Google map API. One of the non-supported tags is .
See: https://developers.google.com/maps/documentation/javascript/kmllayer#supported-elements
To make a label with no icon try making a transparent icon.
I have a KML file with some locations, the problem is that the names are not displayed beside the placemark in Google Earth.
KML Part
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Schema name="feverlocs" id="feverlocs">
<SimpleField name="block" type="string"></SimpleField>
<SimpleField name="lat" type="float"></SimpleField>
<SimpleField name="long" type="float"></SimpleField>
</Schema>
<Folder><name>feverlocs</name>
<Placemark>
<ExtendedData><SchemaData schemaUrl="#feverlocs">
<SimpleData name="block">Garhi</SimpleData>
<SimpleData name="lat">29.598867</SimpleData>
<SimpleData name="long">79.469856</SimpleData>
</SchemaData></ExtendedData>
<Point><coordinates>79.469856,29.598867</coordinates></Point>
</Placemark>
<Placemark>
<ExtendedData><SchemaData schemaUrl="#feverlocs">
<SimpleData name="block">SodaSaroli</SimpleData>
<SimpleData name="lat">30.278907</SimpleData>
<SimpleData name="long">78.137521</SimpleData>
</SchemaData></ExtendedData>
<Point><coordinates>78.137521,30.278907</coordinates></Point>
</Placemark>
I am not able to understand the problem.
So basically SodaSaroli should appear on it's placemark
Only the <name> field appears as a label on the map as defined in the KML. The ExtendedData elements would appear in the description balloon when a placemark is clicked unless you have an explicit description element.
The scope of the name is described in the KML Reference.
If want name to appear then need to add <name> field to the placemarks:
<Placemark>
<name>SodaSaroli</name> ***
<ExtendedData><SchemaData schemaUrl="#feverlocs">
<SimpleData name="block">SodaSaroli</SimpleData>
<SimpleData name="lat">30.278907</SimpleData>
<SimpleData name="long">78.137521</SimpleData>
</SchemaData></ExtendedData>
<Point><coordinates>78.137521,30.278907</coordinates></Point>
</Placemark>
I have a KML file with individual placemarks for gas station locations in the the city. (I had created this in GeoMedia and exported to KML).
I would like to revise the balloon style of each of the placemarks to something similar to one of these balloon styles -
http://earth.google.com/outreach/tutorial_balloon.html
Is there any manner in which I can apply the balloon style to each placemark in the file? Would I have to do it point by point, or can I place the balloon style at the top of the file and have the other placemarks reference that style?
I am very new to KML so any insight would be appreciated.
Thanks
#Matt - I have used your suggestions and tried various iterations but just cant seem to get it right. The file already has the placemarks created - and I want to just edit the style which includes adding logo, remove the directions, and so on.
The new style appears, but the schema text is not appearing in the placemark balloon.
I have pasted some of the code below - any thoughts would be appreciated.
<Schema name="" id="Schema20">
<SimpleField type="xsd:int" name="Building_ID"></SimpleField>
<SimpleField type="xsd:string" name="Building Name"></SimpleField>
<SimpleField type="xsd:string" name="Street Address"></SimpleField>
<SimpleField type="xsd:string" name="Office Type"></SimpleField>
<SimpleField type="xsd:double" name="GFA (m2)"></SimpleField>
<SimpleField type="xsd:string" name="GFA_(sqft)"></SimpleField>
<SimpleField type="xsd:int" name="Storeys"></SimpleField>
<SimpleField type="xsd:int" name="Year Built/Occupied">
</SimpleField></Schema>
<Style id="TestStyle">
<BalloonStyle>
<bgColor>ffffffbb</bgColor>
<text><![CDATA[<b><font color="#CC0000" size="+3">$[name]</font></b><br/><br/>
<font face="Courier">$[description]</font><br/><br/> $[geDirections] ]]>
</text>
</BalloonStyle>
</Style>
<Folder>
<name>Office Buildings</name>
<Placemark>
<name>539</name>
<styleUrl>#TestStyle</styleUrl>
<ExtendedData>
<SchemaData schemaUrl="#Schema20">
<SimpleData name="Building_ID">111</SimpleData>
<SimpleData name="Building Name">Name</SimpleData>
<SimpleData name="Street Address">Address</SimpleData>
<SimpleData name="Office Type">Secondary Office</SimpleData>
<SimpleData name="GFA (m2)">100</SimpleData>
<SimpleData name="GFA_(sqft)">1000</SimpleData>
<SimpleData name="Storeys">5</SimpleData>
<SimpleData name="Year Built/Occupied">2010</SimpleData>
</SchemaData>
</ExtendedData><Point>
<coordinates>-122.370533,37.823842,0</coordinates></Point>
</Placemark>
..... 1000 more like this
#Matt -
What I am running into is that if I use in the balloon style, then the data from the Schema which I referenced in my earlier post does not appear in the balloon.
If I leave the blank then the Schema will appear in the balloon.
Do you know how I can have both appear?
Thanks,
<BalloonStyle>
<text>
<![CDATA[<img align="right" src="http://www.website.com/logo.jpg" width="175">]]>
$[description]
</text>
<bgColor>ffffffbb</bgColor>
</BalloonStyle>
you can use styleUrl for you placemarks (which you will need to apply to all of your placemarks that you want to have a selected style):
<styleUrl>#someIDforStyle</styleUrl>
if the style section is in a different file then just add in the link:
<styleUrl>styles\pathToFile\StyleFile.kml#someIDforStyle</styleUrl>
both above will link a certain Style with that ID similar to:
<Style id='someIDforStyle'>
<BalloonStyle>
<text>
<![CDATA[ ....
your are going to want to add html here to make your balloons similar to that link
...
]]>
</text>
</BalloonStyle>
</Style>
you might check this kml link out for adding Custom Data: https://developers.google.com/kml/documentation/extendeddata
I have some nice data from research aircrafts that I put into kml-files like the example below. If you check the elevation profile, you find the
extended Data plotted nicely.
My problem: my data contains missing values. If I try an empty in place of the missing data, the extended data doesn't appear
more in the profile frame (you can delete one of the floats in the gx-value pair to see).
My question to you: Is there any hack to make GoogleEarth draw the profile without the missing values (i.e. interrupted)?
Or do you know a way to give the GE developers a feedback?
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<Document id="feat_1">
<Style id="stylesel_0">
<LineStyle>
<color>ff0000ff</color>
<colorMode>normal</colorMode>
<width>4</width>
</LineStyle>
</Style>
<visibility>1</visibility>
<Schema id="schema_1" name="Flight Track">
<gx:SimpleArrayField name="bb" type="int">
<displayName>Flight Track</displayName>
</gx:SimpleArrayField>
</Schema>
<Placemark id="feat_2">
<name>example</name>
<styleUrl>#stylesel_0</styleUrl>
<gx:Track>
<gx:coord>-140.0 10.0 0.0</gx:coord>
<gx:coord>-133.572123903 7.66044443119 4131.75911167</gx:coord>
<gx:coord>-130.15192247 1.73648177667 9698.46310393</gx:coord>
<gx:coord>-131.339745962 -5.0 7500.0</gx:coord>
<gx:coord>-136.579798567 -9.39692620786 1169.77778441</gx:coord>
<gx:coord>-143.420201433 -9.39692620786 1169.77778441</gx:coord>
<gx:coord>-148.660254038 -5.0 7500.0</gx:coord>
<gx:coord>-149.84807753 1.73648177667 9698.46310393</gx:coord>
<gx:coord>-146.427876097 7.66044443119 4131.75911167</gx:coord>
<gx:coord>-140.0 10.0 5.99864288729e-28</gx:coord>
<altitudeMode>absolute</altitudeMode>
<ExtendedData>
<SchemaData schemaUrl="#schema_1">
<gx:SimpleArrayData name="ext">
<gx:value>0.00217237382056</gx:value>
<gx:value>0.107224360838</gx:value>
<gx:value>1.99669920652</gx:value>
<gx:value>14.0278818114</gx:value>
<gx:value>37.1819210687</gx:value>
<gx:value>37.1819210687</gx:value>
<gx:value>14.0278818114</gx:value>
<gx:value>1.99669920652</gx:value>
<gx:value>0.107224360838</gx:value>
<gx:value>0.00217237382056</gx:value>
</gx:SimpleArrayData>
</SchemaData>
</ExtendedData>
</gx:Track>
</Placemark>
</Document>
</kml>
This does look like a bug.
I have created an issue at http://code.google.com/p/earth-issues/issues/detail?id=1399
If you star it then you will be notified of any updates.
Meanwhile you may wish to preprocess your KML data and place interpolated values where you have missing ExtendedData.