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>
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".
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>
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>