Multigeometry with two points and different names in the points - kml

I have a Multigeometry in KML but when I assign a name to the placemark, both points in my placemark have the same name. Is there any possibility to have different names for points in any placemark?
Here is an example of my code:
<Placemark>
<name>TEST</name>
<description></description>
<visibility>1</visibility>
<tessellate>1</tessellate>
<styleUrl>#StyTEST</styleUrl>
<MultiGeometry>
<Point>
<coordinates>-3.6655,40.4364</coordinates>
</Point>
<Point>
<coordinates>-3.6726,40.4308</coordinates>
</Point>
<LineString>
<tessellate>1</tessellate>
<coordinates>
-3.6655,40.4364
-3.6726,40.4308
</coordinates>
</LineString>
</MultiGeometry>
</Placemark>

KML does not allow multiple names/labels for geometries within a single Feature even using a Multi-geometry. If you have multiple points in a MultiGeometry then the same name of the feature will appear over all points. One Placemark point == one label so if you want different labels on map using KML then must have two Placemarks one at each end of the line.
Simple solution is to structure your KML with multiple Placemarks which you can hide in a Document/Folder using the checkHideChildren listItemType. Then it appears in the Places panel in Google Earth as a single "feature" but multiple name labels display on the map as you want. The trick here is that the Folder name appears in the Places Panel and the Placemark names appear as labels on the map.
The following example illustrates such a KML file.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Example</name>
<open>1</open>
<Style id="hide">
<ListStyle>
<listItemType>checkHideChildren</listItemType>
</ListStyle>
</Style>
<Folder>
<name>TEST1</name>
<styleUrl>#hide</styleUrl>
<Placemark>
<name>TEST1</name>
<MultiGeometry>
<Point>
<coordinates>-3.6726,40.4308</coordinates>
</Point>
<LineString>
<tessellate>1</tessellate>
<coordinates>
-3.6655,40.4364
-3.6726,40.4308
</coordinates>
</LineString>
</MultiGeometry>
</Placemark>
<Placemark>
<name>TEST2</name>
<Point>
<coordinates>-3.6655,40.4364</coordinates>
</Point>
</Placemark>
</Folder>
</Document>
</kml>

A Placemark has only one name. If you need to have each Point have its own name, they need to be separate Placemarks.
From the referenced documentation:
<Placemark>
Syntax
<Placemark id="ID">
<!-- inherited from Feature element -->
<name>...</name> <!-- string -->
<visibility>1</visibility> <!-- boolean -->
<open>0</open> <!-- boolean -->
<atom:author>...<atom:author> <!-- xmlns:atom -->
<atom:link href=" "/> <!-- xmlns:atom -->
<address>...</address> <!-- string -->
<xal:AddressDetails>...</xal:AddressDetails> <!-- xmlns:xal -->
<phoneNumber>...</phoneNumber> <!-- string -->
<Snippet maxLines="2">...</Snippet> <!-- string -->
<description>...</description> <!-- string -->
<AbstractView>...</AbstractView> <!-- Camera or LookAt -->
<TimePrimitive>...</TimePrimitive>
<styleUrl>...</styleUrl> <!-- anyURI -->
<StyleSelector>...</StyleSelector>
<Region>...</Region>
<Metadata>...</Metadata> <!-- deprecated in KML 2.2 -->
<ExtendedData>...</ExtendedData> <!-- new in KML 2.2 -->
<!-- specific to Placemark element -->
<Geometry>...</Geometry>
</Placemark>

A user can't see 40,000 placemarks at once. Take a look at some of the provided Earth Gallery pages like FlightWise (http://mw1.google.com/mw-weather/flightwise/pointer.kml) to see how they use NetworkLink, Region, and Lod tags to split up their data set and present the correct data to the correct view at the correct time.

Related

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>

Linking KML balloons

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>

Getting lines to work on Google Earth

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.

Displaying Names on the Map using KML

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>

KML + Google Earth: Make a Polygon or GroundOverlay clickable?

Pretty simple question.
I've got some Polygons and GroundOverlays defined in KML. Is there a way to specify that they should be clickable, and (in Google Earth, at least) pop up an info balloon or similar when they are clicked?
Similarly, is it possible to give polygons/GroundOverlays any sort of mouseover behavior? e.g. change the icon or color when moused over?
Yes. Giving the Placemark a name and description will make it a clickable object in Google Earth and will open with an info window showing both. You can create rollover/mouseover behavior using stylemaps, here is an example that does both:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Highlighted Icon</name>
<description>Place your mouse over the icon to see it display the new
icon</description>
<StyleMap id="exampleStyleMap">
<Pair>
<key>normal</key>
<!-- you could also use a <styleUrl> here instead of inlining -->
<Style>
<PolyStyle>
<color>7dff0000</color>
</PolyStyle>
</Style>
</Pair>
<Pair>
<key>highlight</key>
<!-- you could also use a <styleUrl> here instead of inlining -->
<Style>
<PolyStyle>
<color>7dffffff</color>
</PolyStyle>
</Style>
</Pair>
</StyleMap>
<!-- and now, a Placemark that uses the StyleMap -->
<Placemark>
<name>Roll over this polygon</name>
<description>this will show up when clicked</description>
<visibility>1</visibility>
<styleUrl>#exampleStyleMap</styleUrl>
<Polygon>
<tessellate>1</tessellate>
<altitudeMode>absolute</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-112.3372510731295,36.14888505105317,1784
-112.3356128688403,36.14781540589019,1784
-112.3368169371048,36.14658677734382,1784
-112.3384408457543,36.14762778914076,1784
-112.3372510731295,36.14888505105317,1784
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>

Resources