[OpenLayers-Dev] Multipolygon and KML

Benoit PESTY tchule at hotmail.com
Wed Nov 7 12:09:24 EST 2007


Hello,

I'm currently trying to play with the KML Format and I have in the data I'm using some Multipolygon objects.
I know that its not completely supported yet and that I should submit a patch with a real test case but I'm very short on time on my projet and I've done a few ugly hacks that make things work with Firefox (but not IE yet).

So, I'm just posting this in case someone have more time than me to look at this subject.

For the export, the "buildGeometry.collection" method in the KML format is not working because "this" is refering to the "buildGeometry" object instead of the "KML" object.
I've added an ugly "var obj = new OpenLayers.Format.KML();" to make things work, but it's probably not the best way to do.


        /**
         * Method: buildGeometry.collection
         * Given an OpenLayers geometry collection, create a KML MultiGeometry.
         *
         * Parameters:
         * geometry - {<OpenLayers.Geometry.Collection>} A geometry collection.
         *
         * Returns:
         * {DOMElement} A KML MultiGeometry node.
         */
        collection: function(geometry) {
            var obj = new OpenLayers.Format.KML();
            var kml = obj.createElementNS(obj.kmlns, "MultiGeometry");
            var child;
            for(var i=0; i<geometry.components.length; ++i) {
                child = obj.buildGeometryNode.apply(obj,
                                                     [geometry.components[i]]);
                if(child) {
                    kml.appendChild(child);
                }
            }
            return kml;
        }
    },

For the import, the parser doesn't seems to support the presence of the "id" attribute in the Placemark tag, i've commented the following line of the "createPlacemarkXML" method :
placemarkNode.setAttribute("id", feature.fid);

And last thing, the "MultiGeometry" node is not found by the parser, i've put the node names in lowercase in the "parseFeature" method :
var order = ["multigeometry", "polygon", "linestring", "point"];
        
I'll try to correct this for Internet Explorer too and to give more informations ...

Best Regards,

Benoit Pesty.
_________________________________________________________________
Windows Live Hotmail and Microsoft Office Outlook – together at last.  Get it now.
http://office.microsoft.com/en-us/outlook/HA102225181033.aspx?pid=CL100626971033
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20071107/d58e9f7b/attachment.html


More information about the Dev mailing list