Getting lines to work on Google Earth - kml

So I've been sifting through GE's documentation, and found how to do LineStyle and LineString to style and display a line, but in practice I cannot actually make it work. Here's my KML:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"><Document><Style id="thisStyle">
<LineStyle>
<color>500078F0</color>
<colorMode>Normal</colorMode>
<width>5</width>
</LineStyle>
</Style>
<Placemark>
<name>502-2012-11-19 05:27:03</name>
<description>Speed:0</description>
<Point>
<coordinates>-76.0513,42.0894,247</coordinates>
</Point>
</Placemark>
<Placemark>
<name>502-2012-11-19 05:26:46</name>
<description>Speed:0</description>
<Point>
<coordinates>-76.0517,42.0886,287</coordinates>
</Point>
</Placemark>
....
<Placemark>
<name>525-2012-11-19 04:38:25</name>
<description>Speed:0</description>
<Point>
<coordinates>-76.0512,42.0894,178</coordinates>
</Point>
</Placemark>
<styleUrl>#thisStyle</styleUrl>
<LineString>
<tessellate>1</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
-76.0513,42.0894,247
-76.0517,42.0886,287
....
-76.0512,42.0894,178
</coordinates></LineString></Document></kml>
Note: The above places where "..." appears there are about 50 more coordinate sets, I removed them for the sake of brevity, but since all coordinates are produced by a script if one works I know they all will. Can anyone nudge me in the right direction as to why my placemarks all show up, but no lines?

A LineString element is only valid inside a Placemark (or a MultiGeometry inside a Placemark):
<Placemark>
<LineString>
<tessellate>1</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
-76.0513,42.0894,247
-76.0517,42.0886,287
-76.0512,42.0894,178
</coordinates>
</LineString>
</Placemark>
Example on Google Maps with your KML
Example on Google Maps with a Placemark containing the Linestring

You must either inline Style in the Placemark or reference the style in the Placemark using styleUrl element.
The last Placemark in your example needs to be rewritten like this:
<Placemark>
<name>525-2012-11-19 04:38:25</name>
<description>Speed:0</description>
<styleUrl>#thisStyle</styleUrl>
<LineString>
<tessellate>1</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
-76.0513,42.0894,247
-76.0517,42.0886,287
...
-76.0512,42.0894,178
</coordinates>
</LineString>
</Placemark>
If your KML doesn't view correctly then it usually helps to validate the KML. You can use the KML Validator.

Related

LabelStyle.... Why won't this code produce red font on half size labels?

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.

KML icons on every waypoint

I want to export telephone poles and cables out of our database into a KML file for Google Earth.
For every node we have an array of poles, the cables are always connected towards the next pole in the array.
An export making simple paths seems to be easy enough. But these paths just show a path, they don't show every waypoint (telephone pole).
This is an example in Google Maps what I want to achieve in .kml
If you want paths and points for each of the poles (aka waypoints) then you need your KML to include not only the line segments separate points for each of the positions of the poles.
Your KML will need to be structured like this where poleSyle will have an IconStyle with the icon you want for the points and lineStyle will be a thick green line
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="poleStyle">
...
</Style>
<Style id="lineStyle">
...
</Style>
<Placemark>
<styleUrl>#lineStyle</styleUrl>
<LineString>
<coordinates>...</coordinates>
</LineString>
</Placemark>
<Placemark>
<name>pole1</name>
<description>address pole1</description>
<styleUrl>#poleStyle</styleUrl>
<Point>
<coordinates>...</coordinates>
</Point>
</Placemark>
...
</Document>
</kml>
If you don't want or need a unique name or description for every point then you can combine the points in a single Placemark inside a MultiGeometry like this:
<Placemark>
<styleUrl>#poleStyle</styleUrl>
<MultiGeometry>
<Point>
<coordinates>...</coordinates>
</Point>
<Point>
<coordinates>...</coordinates>
</Point>
</MultiGeometry>
</Placemark>

Google Earth How to animate KML placemarks smoothly

I have some radar data to display with the Google Earth plugin. Generally, it is some ground objects with coordinates and a timestamp. I followed the instructions in https://developers.google.com/kml/documentation/time, tried both timestamp and timespan and it works fine. But the displaying effects are not satisfying.
For the timestamp solution, the placemarks just flash briefly at exactly the time indicated by "" tags. And when I pressed play button, nothing shows up on the map.
Code sample:
<Folder>
<name>Vehicles</name>
<description>Timeline information of vehicles</description>
<Placemark>
<name>2</name>
<description>(-84.114231,39.785436,-0.000216),V(13.411216,37.555181) at 0.00s</description>
<TimeStamp>
<when>2012-09-19T08:00:00Z</when>
</TimeStamp>
<styleUrl>#vehicleStyle</styleUrl>
<Point>
<coordinates>-84.114231,39.785436,-0.000216</coordinates>
</Point>
</Placemark>
<Placemark>
<name>910</name>
<description>(-84.110335,39.788438,-0.000024),V(0.000000,0.000000) at 0.80s</description>
<TimeStamp>
<when>2012-09-19T08:00:30Z</when>
</TimeStamp>
<styleUrl>#vehicleStyle</styleUrl>
<Point>
<coordinates>-84.110335,39.788438,-0.000024</coordinates>
</Point>
</Placemark>
<Placemark>
<name>2</name>
<description>(-84.114133,39.785494,-0.000285),V(13.411216,37.555118) at 0.80s</description>
<TimeStamp>
<when>2012-09-19T08:00:30Z</when>
</TimeStamp>
<styleUrl>#vehicleStyle</styleUrl>
<Point>
<coordinates>-84.114133,39.785494,-0.000285</coordinates>
</Point>
</Placemark>
<Placemark>
<name>910</name>
<description>(-84.110307,39.788410,-0.000046),V(3.499966,307.390012) at 1.60s</description>
<TimeStamp>
<when>2012-09-19T08:01:00Z</when>
</TimeStamp>
<styleUrl>#vehicleStyle</styleUrl>
<Point>
<coordinates>-84.110307,39.788410,-0.000046</coordinates>
</Point>
</Placemark>
</Folder>
...
For the timespan case, the animation is OK but there is always a tail followed by each object: the placemarks in previous frames do not disappear immediately at the beginning of the new time span.
Code sample:
...
<Folder>
<name>Vehicles</name>
<description>Timeline information of vehicles</description>
<Placemark>
<name>2</name>
<description>(-84.114231,39.785436,-0.000216),V(13.411216,37.555181) at 0.00s</description>
<TimeSpan>
<begin>2012-09-19T08:00:00Z</begin>
<end>2012-09-19T08:00:10Z</end>
</TimeSpan>
<styleUrl>#vehicleStyle</styleUrl>
<Point>
<coordinates>-84.114231,39.785436,-0.000216</coordinates>
</Point>
</Placemark>
<Placemark>
<name>910</name>
<description>(-84.110335,39.788438,-0.000024),V(0.000000,0.000000) at 0.80s</description>
<TimeSpan>
<begin>2012-09-19T08:00:10Z</begin>
<end>2012-09-19T08:00:20Z</end>
</TimeSpan>
<styleUrl>#vehicleStyle</styleUrl>
<Point>
<coordinates>-84.110335,39.788438,-0.000024</coordinates>
</Point>
</Placemark>
<Placemark>
<name>2</name>
<description>(-84.114133,39.785494,-0.000285),V(13.411216,37.555118) at 0.80s</description>
<TimeSpan>
<begin>2012-09-19T08:00:10Z</begin>
<end>2012-09-19T08:00:20Z</end>
</TimeSpan>
<styleUrl>#vehicleStyle</styleUrl>
<Point>
<coordinates>-84.114133,39.785494,-0.000285</coordinates>
</Point>
</Placemark>
<Placemark>
<name>910</name>
<description>(-84.110307,39.788410,-0.000046),V(3.499966,307.390012) at 1.60s</description>
<TimeSpan>
<begin>2012-09-19T08:00:20Z</begin>
<end>2012-09-19T08:00:30Z</end>
</TimeSpan>
<styleUrl>#vehicleStyle</styleUrl>
<Point>
<coordinates>-84.110307,39.788410,-0.000046</coordinates>
</Point>
</Placemark>
</Folder>
...
So is there any solution to make the placemarks animate continuously? Thanks.
P.S. Track is not considered, because tracking information between data points are not available for now.
If I understand what you are asking then you could do this by simply toggling the style of the placemarks using the JavaScript api.
To do this you could simply create a style in your Kml document such as.
<Style id="vehicleStyleHighighted">
<IconStyle>
<color>ff00ff00</color>
<colorMode>random</colorMode>
<scale>1.5</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pal3/icon21.png</href>
</Icon>
</IconStyle>
</Style>
You can then use the method setStyleUrl() along with a timer to set each placemark's style. I.E. You would toggle each placemarks style between #vehicleStyleHighighted and '#vehicleStyleHighighted.
If you wanted more than a simple 'on/off' animation then you can define more than two animation states using this method and then simply apply them as required.

How to made KML doesnt import order of multigeometry

Hello Im writing some KML and when and I create the multigeomtry in the order
PlaceMark A
PlaceMark B
I cant select PlMark A beceause B is bigger, but when I have
PlaceMark B
PlaceMark A
Yes, because I think A is smaller and it was the last in be grapicated, my question is I cant have the Placemarks In order,there are any option in Kml to made selectable all the elements.
Thanks.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Document>
<StyleMap id="StyF1"><Pair><key>normal</key><Style><IconStyle><Icon></Icon></IconStyle><PolyStyle><color>7d0000ff</color></PolyStyle></Style></Pair><Pair><key>highlight</key><Style><IconStyle><Icon></Icon></IconStyle><PolyStyle><color>7aFFFF8C</color></PolyStyle></Style></Pair></StyleMap>
<StyleMap id="StyU1"><Pair><key>normal</key><Style><IconStyle><Icon></Icon></IconStyle><PolyStyle><color>7d0000ff</color></PolyStyle></Style></Pair><Pair><key>highlight</key><Style><IconStyle><Icon></Icon></IconStyle><PolyStyle><color>7aFFFF8C</color></PolyStyle></Style></Pair></StyleMap>
<Placemark>
<name>A</name>
<description>
</description>
<visibility>1</visibility>
<tessellate>1</tessellate>
<styleUrl>#StyU1</styleUrl>
<MultiGeometry>
<Point>
<coordinates>-0.18806,39.78366</coordinates>
</Point>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>-0.18806,39.78261
-0.18701,39.7844286533479
-0.18911,39.7844286533479
-0.18806,39.78261</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
<Placemark>
<name>B</name>
<description>
</description>
<visibility>1</visibility>
<tessellate>1</tessellate>
<styleUrl>#StyF1</styleUrl>
<MultiGeometry>
<Point>
<coordinates>-0.18806,39.78501</coordinates>
</Point>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>-0.18806,39.78261
-0.18566,39.7867669219382
-0.19046,39.7867669219382
-0.18806,39.78261</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
</Document></kml>
If you want to order one line or polygon over another you can use the <gx:drawOrder> element.
Features with higher <gx:drawOrder> values are drawn on top of those with lower values so for example if you use a drawOrder of 2 for A and 1 for B then A is drawn on top of B. In other words, the features with lower drawOrder values are drawn first.
Don't forget to add the xmlns:gx="http://www.google.com/kml/ext/2.2" declaration to the kml tag and note that the documentation says it only applies to LineStrings but it also applies to Polygons and LinearRings.
<?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">
...
<Placemark>
<name>A</name>
<MultiGeometry>
<Point>
<coordinates>-0.18806,39.78366</coordinates>
</Point>
<Polygon>
<gx:drawOrder>2</gx:drawOrder>
...
</Polygon>
</MultiGeometry>
</Placemark>
<Placemark>
<name>B</name>
<MultiGeometry>
<Point>
<coordinates>-0.18806,39.78501</coordinates>
</Point>
<Polygon>
<gx:drawOrder>1</gx:drawOrder>
...
</Polygon>
</MultiGeometry>
</Placemark>
Reference: https://developers.google.com/kml/documentation/kmlreference#gxdraworder

Google Earth KML

How do you links cities with a curve (line) in kml for Google Earth?
First, since you are on SO I'm assuming you are asking from a KML perspective and not just in the desktop application.
You would need to have the coordinates of the two cities. Then you would create a kml document like the following from the docs using your coordinates in the coordinates element (note that you don't need the "LookAt" element, but it will bring your camera to the relevant area):
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>LineString.kml</name>
<open>1</open>
<LookAt>
<longitude>-122.36415</longitude>
<latitude>37.824553</latitude>
<altitude>0</altitude>
<range>150</range>
<tilt>50</tilt>
<heading>0</heading>
</LookAt>
<Placemark>
<name>unextruded</name>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<coordinates>
-122.364383,37.824664,0 -122.364152,37.824322,0
</coordinates>
</LineString>
</Placemark>
<Placemark>
<name>extruded</name>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>
-122.364167,37.824787,50 -122.363917,37.824423,50
</coordinates>
</LineString>
</Placemark>
</Document>
</kml>
If you don't have the city altitudes then leave them out and be sure to set the altitudeMode element to "clampToGround" and likely the tesselate element to "1" (meaning true). If you forget this your lines may disappear underground.

Resources