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
Related
I am attempting to generate a KML overlay. I have a grid I am mapping over an area, with colored squares. When I have the altitude mode as 'clampToGround' everything about the polygons I am generating, including their color, works as expected. However, it's not desirable to have the grid deform to map to the ground. When I change the altitude mode such that the overlay hovers a few meters off the ground, the shape of the grid sections is correct, but the color information is discarded and the grid sections are colored black.
Here is a testable excerpt of my KML code. Here is shows the colors correct but the grid deformed to the ground. Changing the value of altitudeMode to:
absolute produces the other behavior.
Is there a way to have this at the correct altitude AND with the correct color at the same time?
<?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">
<Document id="1">
<Document id="2">
<Style id="10">
<PolyStyle id="10">
<color>0xFF0000FF</color>
<colorMode>normal</colorMode>
<fill>1</fill>
<outline>1</outline>
</PolyStyle>
</Style>
<name>Antenna Data</name>
<Camera>
<longitude>-122.30201334502573</longitude>
<latitude>37.87244901754293</latitude>
<altitude>200</altitude>
</Camera>
<Placemark id="5">
<name>region</name>
<styleUrl>#10</styleUrl>
<Polygon id="4">
<altitudeMode>clampToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing id="8">
<coordinates>-122.30243999999999,37.871973499999996,10 -122.30243999999999,37.8719265,10 -122.30238,37.8719265,10 -122.30238,37.871973499999996,10</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</Document>
</kml>
Your KML has several issues.
The polygon is missing the closing vertex. In order to be a valid KML polygon, the first coordinate set (lon,lat,alt) must be repeated as the last coordinate set, so that the polygon closes itself. For your example of a square, you would need 5 coordinate sets, with the first and the last being the same.
Try fixing that first, and if you still see coloring issues, try making sure that the vertex winding direction is correct (anti-clockwise). If it's backwards, then the darker "bottom" of the polygon will be facing upwards, and might appear dark/black. Yours appears correct from looking at the coordinates, but I could be mistaken.
Also, your color is not a valid KML color, as it appears to have an extra "0x" in front. A valid KML color needs four two-character values (each between 00 and ff), representing Alpha, Blue, Green, Red (AABBGGRR, and yes, it's backwards from HTML colors). A solid red would be: FF0000FF.
Below is an updated copy of your KML sample with altitudeMode = absolute, the closing vertex added, and the color corrected... this works for me in Earth Pro.
<?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">
<Document id="1">
<Document id="2">
<Style id="10">
<PolyStyle id="10">
<color>FF0000FF</color>
<colorMode>normal</colorMode>
<fill>1</fill>
<outline>1</outline>
</PolyStyle>
</Style>
<name>Antenna Data</name>
<Camera>
<longitude>-122.30201334502573</longitude>
<latitude>37.87244901754293</latitude>
<altitude>200</altitude>
</Camera>
<Placemark id="5">
<name>region</name>
<styleUrl>#10</styleUrl>
<Polygon id="4">
<altitudeMode>absolute</altitudeMode>
<outerBoundaryIs>
<LinearRing id="8">
<coordinates>-122.30243999999999,37.871973499999996,10 -122.30243999999999,37.8719265,10 -122.30238,37.8719265,10 -122.30238,37.871973499999996,10 -122.30243999999999,37.871973499999996,10</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</Document>
</kml>
The solution I came across was that I could simple de-activate terrain in Google Earth. This seems to work now.
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.
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'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>
Big picture: I'm writing my own KMLs using a custom KML writer in C++. I have a set of placemarks that share some (not all) properties. Currently I store the shared properties as properties of the parent folder the placemarks reside in. These KMLs are viewed in Google Earth.
Users gain access to view this data using a BalloonStyle linked to the ExtendedData stored within each placemark/folder. The placemarks share a balloonstyle for their unique data, and the shared data is displayed using the parent folder's balloon style when they click on the folder in Google Earth.
I can't afford to duplicate the shared data in each placemark, which is why I store it in the parent folder.
Alternative 1: Is there any way to provide a user-clickable link to the parent folder's balloon within the child's balloon?
Alternative 2: Is it possible to display another Placemark/Feature's data in a placemark's info balloon?
As far as I know, both alternatives are impossible.
Edit: Simplified example code:
<?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>MyKml</name>
<Style id="Style8"> <!-- style for child point -->
<BalloonStyle>
<text>
Point: $[name]<br/>
Code: $[code]<br/>
Number of Points: $[numpts] <!-- Alt2: numpts belongs to the parent - this syntax is obviously wrong -->
Link to parent: $[parentid] <!-- Alt1: if I can't display the parent's properties, can I at least give a clickable link to it? -->
</text>
</BalloonStyle>
</Style>
<Style id="Style12"> <!-- style for parent folder -->
<BalloonStyle>
<text>
Point Group: $[name]<br/>
Number of Points: $[numpts]
</text>
</BalloonStyle>
</Style>
<Folder>
<name>Point Group 1</name>
<styleUrl>#Style12</styleUrl>
<ExtendedData>
<Data name="numpts">
<value>4</value>
</Data>
</ExtendedData>
<Placemark>
<name>PT1</name>
<styleUrl>#Style8</styleUrl>
<ExtendedData>
<Data name="code">
<value>TAT1</value>
</Data>
</ExtendedData>
<MultiGeometry>
<Point>
<coordinates>-121,47,110</coordinates>
</Point>
</MultiGeometry>
</Placemark>
<Placemark>
<name>PT2 - PT4</name>
<styleUrl>#Style8</styleUrl>
<ExtendedData>
<Data name="code">
<value>TAT2</value>
</Data>
</ExtendedData>
<MultiGeometry>
<Point>
<coordinates>-121.090,47.430,1224</coordinates>
</Point>
<Point>
<coordinates>-121.470,47.621,122</coordinates>
</Point>
<Point>
<coordinates>-121.990,47.121,122</coordinates>
</Point>
</MultiGeometry>
</Placemark>
</Folder>
</Document>
</kml>
Alternative 1: Is there any way to provide a user-clickable link to the parent folder's balloon within the child's balloon?
This is achieved using feature anchors where you can refer to and link to placemarks by its KML id using <a href="target"> in the description/balloon. If the target Feature has a LookAt or Camera element, the Feature is viewed from the specified viewpoint.
The href can be a fragment URL (that is, a URL with a # sign followed by a KML identifier).
You can also append an action to the URL with a semi-colon (;) and one of these qualifiers:
;flyto (default) - fly to the Feature
;balloon - open the Feature's balloon but do not fly to the Feature
;balloonFlyto - open the Feature's balloon and fly to the Feature
If you want to show the folder balloon from the point's you can update the BalloonStyle text as following and add "id" attribute to the Folder you want to refer to.
<Style id="Style8">
<BalloonStyle>
<text>
<![CDATA[
Point: $[name]<br/>
Code: $[code]<br/>
Number of Points: $[numpts]
<BR>Link to parent
]]>
</text>
</BalloonStyle>
</Style>
<Folder id="parent"> *** Must add "id" attribute to link to it ***
...
</Folder>
Alternative 2: Is it possible to display another Placemark/Feature's data in a placemark's info balloon?
Can't directly include metadata for another placemark in balloon of another but can link to it and switch to showing other's balloon by user clicking the link.
You could add links to the description of the placemarks to link to one another in the same way to link to Folder by its id then add $[description] place holder to the BalloonStyle text.
<Style id="style9"> <!-- style for child point -->
<BalloonStyle>
<text>
<![CDATA[
Point: $[name]<br/>
Code: $[code]<br/>
Link to parent
<br>$[description]
]]>
</text>
</BalloonStyle>
</Style>
...
<Placemark id="pt1">
...
</Placemark>
<Placemark id="pt2">
<name>PT2 - PT4</name>
<description>
<![CDATA[
Show P1<BR>
]]>
</description>
<styleUrl>#style9</styleUrl>
...
</Placemark>