How can I do variable substitution in a kml icon reference? I'm using Google Earth to load the kml, and my image doesn't appear for this simple example:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Document>
<name>TestMap</name>
<Style id="Icon1">
<IconStyle>
<Icon>
<href>$[url]</href>
</Icon>
</IconStyle>
</Style>
<Placemark>
<name>Hello World</name>
<styleUrl>#Icon1</styleUrl>
<ExtendedData>
<Data name="url">
<value>http://magiccards.info/scans/en/al/232.jpg</value>
</Data>
</ExtendedData>
<Point>
<coordinates>
0,0,0
</coordinates>
</Point>
</Placemark>
</Document>
</Document>
</kml>
Variable substitution for extended data in KML only works in context of the description so you could show the placemark's data url via the description balloon.
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Data+BalloonStyle</name>
<Style id="balloon-style">
<BalloonStyle>
<text>
<![CDATA[
$[name]<br>
<img src="$[url]"/>
]]>
</text>
</BalloonStyle>
</Style>
<Placemark>
<name>Hello World</name>
<styleUrl>#balloon-style</styleUrl>
<ExtendedData>
<Data name="url">
<value>http://magiccards.info/scans/en/al/232.jpg</value>
</Data>
</ExtendedData>
<Point>
<coordinates>-111.956,33.5043</coordinates>
</Point>
</Placemark>
</Document>
</kml>
See related tutorial for adding custom data which describes using the BalloonStyle Element as a Template
https://developers.google.com/kml/documentation/extendeddata
If you want to display a custom icon via IconStyle per placemark then you need to define an inline Style for each placemark with the appropriate URL.
<Placemark>
<name>Hello World</name>
<Style>
<IconStyle>
<Icon>
<href>http://magiccards.info/scans/en/al/232.jpg</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>-111.956,33.5043</coordinates>
</Point>
</Placemark>
Related
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 am plotting a LineString. For some reason, I don't seem to effect the LineStyle. My code looks identical to many examples but no matter what color or width I place in the LineStyle, it always comes out as a thick blue line.
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Qtr Min Grid Maker</name>
<LookAt>
<longitude>-121.5</longitude>
<latitude>38</latitude>
<altitude>0</altitude>
<range>740933.8825924395</range>
<tilt>0</tilt>
<heading>0</heading>
</LookAt>
<Folder>
<name>Grids</name>
<Style id="linestyle1">
<LineStyle>
<color>7f0000ff</color>
<width>1</width>
<gx:labelVisibility>1</gx:labelVisibility>
</LineStyle>
</Style>
<Placemark>
<name>QTR</name>
<visibility>0</visibility>
<open>1</open>
<styleUrl>#linestyle1</styleUrl>
<LineString>
<coordinates>
-124.75,40,0
-124.5,40,0
-124.25,40,0
-124,40,0
-123.75,40,0
-123.5,40,0
-123.25,40,0
-123,40,0
</coordinates>
</LineString>
</Placemark>
</Folder>
</Document>
</kml>
It works for me if I move the shared styles to the top level (inside the <Document> tag):
example
From the documentation (see the description of <StyleSelector>):
A style defined within a Feature is called an "inline style" and
applies only to the Feature that contains it. A style defined as the
child of a <Document> is called a "shared style." A shared style must
have an id defined for it. This id is referenced by one or more
Features within the <Document>.
Yours is neither a child of <Document> nor within a <Placemark>
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="linestyle1">
<LineStyle>
<color>7f0000ff</color>
<width>1</width>
<gx:labelVisibility>1</gx:labelVisibility>
</LineStyle>
</Style>
<name>Qtr Min Grid Maker</name>
<LookAt>
<longitude>-121.5</longitude>
<latitude>38</latitude>
<altitude>0</altitude>
<range>740933.8825924395</range>
<tilt>0</tilt>
<heading>0</heading>
</LookAt>
<Folder>
<name>Grids</name>
<Placemark>
<name>QTR</name>
<visibility>0</visibility>
<open>1</open>
<styleUrl>#linestyle1</styleUrl>
<LineString>
<coordinates>
-124.75,40,0
-124.5,40,0
-124.25,40,0
-124,40,0
-123.75,40,0
-123.5,40,0
-123.25,40,0
-123,40,0
</coordinates>
</LineString>
</Placemark>
</Folder>
</Document>
</kml>
How to add custom marker in KML file ? Why my code doesn't work ?
New edited code :
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Style id="mycustommarker">
<IconStyle>
<Icon>
<href>http://www.exemple.com/image.png</href>
</Icon>
</IconStyle>
</Style>
<Placemark>
<name>Name</name>
<description>Description</description>
<Point>
<coordinates>-8.291014,47.813155,0</coordinates>
</Point>
</Placemark>
</kml>
The href attribute of the IconStyle must be a relative file or absolute URL. The value "exemple.com/img.png" in your example is not a fully qualified URL.
Example:
<Style id="randomColorIcon">
<IconStyle>
<Icon>
<href>http://maps.google.com/mapfiles/kml/shapes/airports.png</href>
</Icon>
</IconStyle>
</Style>
Here's a working example to try.
http://kml-samples.googlecode.com/svn/trunk/kml/Style/yellow-paddle.kml
More details can be found in the KML reference documentation:
https://developers.google.com/kml/documentation/kmlreference#iconstyle
Also, when in doubt, use the KML validator to check your KML. You'll notice 3 errors including use of a non-standard namespace - should use xmlns="http://www.opengis.net/kml/2.2" not "http://earth.google.com/kml/2.2".
I exported the KML file from locationhistory of google maps.
Thus, I try to create a Fusion Table using Google drive and importing this file.
During the import I selected the row that contains column names.
The columns created in fusion table are:
description, name and geometry
The Fusion Table import only one row with description and name filled, while geometry field is empty.
Are Geography information on Fusion table fused in geometry type ?
If it's right, why it doesn't work?
If it's wrong, what is the correctly type mapping for these information?
Here the KML file used (removed some entries about gx:coord):
<?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>Location history from 09/21/2014 to 09/28/2014</name>
<open>1</open>
<description/>
<StyleMap id="multiTrack">
<Pair>
<key>normal</key>
<styleUrl>#multiTrack_n</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#multiTrack_h</styleUrl>
</Pair>
</StyleMap>
<Style id="multiTrack_n">
<IconStyle>
<Icon>
<href>http://earth.google.com/images/kml-icons/track-directional/track-0.png</href>
</Icon>
</IconStyle>
<LineStyle>
<color>99ffac59</color>
<width>6</width>
</LineStyle>
</Style>
<Style id="multiTrack_h">
<IconStyle>
<scale>1.2</scale>
<Icon>
<href>http://earth.google.com/images/kml-icons/track-directional/track-0.png</href>
</Icon>
</IconStyle>
<LineStyle>
<color>99ffac59</color>
<width>8</width>
</LineStyle>
</Style>
<Placemark>
<name>Latitude User</name>
<description>Location history for Latitude User from 09/21/2014 to 09/28/2014</description>
<styleUrl>#multiTrack</styleUrl>
<gx:Track>
<altitudeMode>clampToGround</altitudeMode>
<when>2014-09-21T15:23:46.249-07:00</when>
<gx:coord>99.99999 41.99999 0</gx:coord>
<when>2014-09-21T15:23:47.249-07:00</when>
<gx:coord>99.99999 41.99999 0</gx:coord>
</gx:Track>
</Placemark>
</Document>
</kml>
The supported geometry-types when you import KML are Linestring, Polygon and Point (see: https://support.google.com/fusiontables/answer/174680 )
This would work:
<Placemark>
<name>Latitude User</name>
<description>Location history for Latitude User from 09/21/2014 to 09/28/2014</description>
<Point>
<coordinates>99.99999,41.99999,0</coordinates>
</Point>
</Placemark>
I am new to KML and seem to be going round in circles. Hope someone can help.
I want to show a HTML balloon and get rid of the ugly driving directions. I am using 'BalloonStyle' to do this.
Also want to be able to hide the placemark label, so am using 'LabelStyle' to do this.
I can get these to work separately, but don't seem to be able to get them to work together to achieve the desired result.
Below is sample code which replicates the issue. Am I doing something wrong? Or do these two items just not work together? If so, is there another way to get the desired result (a HTML Balloon and a hidden label)?
Thank you
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="randomLabelColor">
<LabelStyle>
<color>ff0000cc</color>
<colorMode>random</colorMode>
<scale>1.5</scale>
</LabelStyle>
</Style>
<Style id="FEXBalloonStyle">
<BalloonStyle>
<bgColor>ffffff</bgColor>
<text><![CDATA[<b><font color="#CC0000" size="+2">$[name]</font></b>
<br><br/><font face="Courier">$[description]</font><br/><br/><br/><br/>]]></text>
</BalloonStyle>
</Style>
<Placemark>
<name>LabelStyle.kml</name>
<styleUrl>#randomLabelColor</styleUrl>
<styleUrl>#FEXBalloonStyle</styleUrl>
<Point>
<coordinates>-122.367375,37.829192,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
You can only have one styleUrl for a Placemark. If you want to have both the <LabelStyle> and <BalloonStyle> applied a single place mark, you have to put them in the same style:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="randomLabelColor">
</Style>
<Style id="FEXBalloonStyle">
<LabelStyle>
<color>ff0000cc</color>
<colorMode>random</colorMode>
<scale>1.5</scale>
</LabelStyle>
<BalloonStyle>
<bgColor>ffffff</bgColor>
<text><![CDATA[<b><font color="#CC0000" size="+2">$[name]</font></b>
<br><br/><font face="Courier">$[description]</font><br/><br/><br/><br/>]]></text>
</BalloonStyle>
</Style>
<Placemark>
<name>LabelStyle.kml</name>
<styleUrl>#FEXBalloonStyle</styleUrl>
<Point>
<coordinates>-122.367375,37.829192,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>