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