'kml item' hook needs more flexibility

raintonr - March 18, 2008 - 21:29
Project:KML module
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Hi,

I have recently produced the trackfield.module (http://drupal.org/project/trackfield). As part of this have managed to utilise the 'kml item' hook to place paths in KML output. There is a problem with how things currently work though:

Whatever data you return is added inside the existing <Placemark> element. For example, the trackfield module can return (co-ord list mostly removed for space):

Array
(
    [Linestring] => Array
        (
            [key] => LineString
            [value] => <coordinates>151.234721,-33.768547,0 151.23741,-33.763535,0</coordinates>
        )

)

Which makes KML output for this <Placemark>:

   <Placemark>
    <name>...snip...</name>
    <description>...snip...</description>
    <styleUrl>#NodeStyleMap</styleUrl>
    <TimeStamp><when>2008-03-14T10:01:13Z</when></TimeStamp>
    <Point>
     <altitudeMode>relativeToGround</altitudeMode>
     <coordinates>151.236505,-33.765448,0</coordinates>
    </Point>
    <LineString><coordinates>151.234721,-33.768547,0 151.23741,-33.763535,0</coordinates></LineString>
   </Placemark>

This confuses Google Earth and it seems to be able to treat a <Placemark> as a point or a line, but not both. Luckily for us the <LineString> seems to take precedent over <Point> and the track is displayed, but that's not what is really required. To show both is needed so the line has a label hovering above it.

What seems to be needed is a way to have the hook be able to return something that creates another <Placemark> element inside the KML output, something like:

   <Placemark>
    <name>...snip...</name>
    <description>...snip...</description>
    <styleUrl>#NodeStyleMap</styleUrl>
    <TimeStamp><when>2008-03-14T10:01:13Z</when></TimeStamp>
    <Point>
     <altitudeMode>relativeToGround</altitudeMode>
     <coordinates>151.236505,-33.765448,0</coordinates>
    </Point>
   </Placemark>
   <Placemark>
    <name>...snip...</name>
    <description>...snip...</description>
    <styleUrl>#NodeStyleMap</styleUrl>
    <TimeStamp><when>2008-03-14T10:01:13Z</when></TimeStamp>
    <LineString><coordinates>151.234721,-33.768547,0 151.23741,-33.763535,0</coordinates></LineString>
   </Placemark>

How do you think this would be best achieved?

Maybe if the key in the returned array is <Placemark> then the value could be added as such after the existing one?

#1

raintonr - June 27, 2008 - 03:53

Playing more with this I have discovered the MultiGeometry tag as discussed here:

http://code.google.com/apis/kml/documentation/kmlreference.html#multigeo...

It would seem that this is probably the way to go. One can use this tag to overcome the 'confusion' I first mention and allow both Point and LineString elements to be handled properly inside the same placemark.

I would propose a small patch to the KML module that looked through the args array in kml_format_placemark function and any elements that were themself geometry tags would be placed with the default placemark inside a MultiGeometry tag.

This should be easy enough to do and will work on it shortly.

#2

raintonr - June 28, 2008 - 11:50
Status:active» needs review

As per #1 please find patch attached.

This handles all geometry types and the MultiGeometry tag itself inside the $extra returned from $extra = node_invoke_nodeapi($item, 'kml item');.

For efficient styling it might be nice to add a prior hook call for other modules to add their style information. This can be embedded at the moment but is on a per-node basis rather than using style IDs.

AttachmentSize
kml.module.235986.patch 2 KB

#3

raintonr - July 30, 2008 - 21:31
Status:needs review» fixed

Now committed to cvs:

http://drupal.org/cvs?commit=130675

#4

Anonymous (not verified) - August 13, 2008 - 21:32
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.