Some more tests with IE 7.0, I don't know why but when reading a KML IE
uppercase the tag "Multigeometry" while Firefox lowercase it.
So, I've change the "parseFeature" method of the KML format, it seems to work
OK with both IE and Firefox.
/**
* Method: parseFeature
* This function is the core of the KML parsing code in OpenLayers.
* It creates the geometries that are then attached to the returned
* feature, and calls parseAttributes() to get attribute data out.
*
* Parameters:
* node - {<DOMElement>}
*
* Returns:
* {<OpenLayers.Feature.Vector>} A vector feature.
*/
parseFeature: function(node) {
// only accept one geometry per feature - look for highest "order"
var order = ["MULTIGEOMETRY", "Polygon", "LineString", "Point"];
var type, nodeList, geometry, parser;
for(var i=0; i<order.length; ++i) {
type = order[i];
this.internalns = node.namespaceURI ?
node.namespaceURI : this.kmlns;
nodeList = this.getElementsByTagNameNS(node,
this.internalns, type);
if(nodeList.length == 0) {
nodeList = this.getElementsByTagNameNS(node,
this.internalns,
type.toLowerCase());
}
if(nodeList.length > 0) {
// only deal with first geometry of this type
var parser = this.parseGeometry[type.toLowerCase()];
if(parser) {
geometry = parser.apply(this, [nodeList[0]]);
} else {
OpenLayers.Console.error("Unsupported geometry type: " +
type);
}
// stop looking for different geometry types
break;
}
}
// construct feature (optionally with attributes)
var attributes;
if(this.extractAttributes) {
attributes = this.parseAttributes(node);
}
var feature = new OpenLayers.Feature.Vector(geometry, attributes);
var fid = node.getAttribute("id");
if(fid != null) {
feature.fid = fid;
}
return feature;
},
Regards,
Benoit Pesty.
From: [EMAIL PROTECTED]
To: [email protected]
Date: Wed, 7 Nov 2007 17:09:24 +0000
Subject: [OpenLayers-Dev] Multipolygon and KML
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!
_________________________________________________________________
Climb to the top of the charts! Play Star Shuffle: the word scramble
challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_oct_______________________________________________
Dev mailing list
[email protected]
http://openlayers.org/mailman/listinfo/dev