diff --git a/lib/OpenLayers/Format/KML.js b/lib/OpenLayers/Format/KML.js index b00bf37b71..49c1d8b51c 100644 --- a/lib/OpenLayers/Format/KML.js +++ b/lib/OpenLayers/Format/KML.js @@ -1020,14 +1020,13 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, { createPlacemarkXML: function(feature) { // Placemark name var placemarkName = this.createElementNS(this.kmlns, "name"); - var name = (feature.attributes.name) ? - feature.attributes.name : feature.id; + var name = feature.style && feature.style.label ? feature.style.label : + feature.attributes.name || feature.id; placemarkName.appendChild(this.createTextNode(name)); // Placemark description var placemarkDesc = this.createElementNS(this.kmlns, "description"); - var desc = (feature.attributes.description) ? - feature.attributes.description : this.placemarksDesc; + var desc = feature.attributes.description || this.placemarksDesc; placemarkDesc.appendChild(this.createTextNode(desc)); // Placemark diff --git a/tests/Format/KML.html b/tests/Format/KML.html index 6f8d0973c5..c798de74b4 100644 --- a/tests/Format/KML.html +++ b/tests/Format/KML.html @@ -195,6 +195,22 @@ t.eq(features[0].attributes.ElevationGain.displayName, "ElevationGain", "read displayName from extendeddata correctly"); } + function test_Format_KML_placemarkName(t) { + t.plan(3); + + var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0,0)); + var f = new OpenLayers.Format.KML(); + + t.eq(f.read(f.write(feature))[0].attributes.name, feature.id, "placemark name from feature.id"); + + feature.attributes.name = "placemark name from attributes.name"; + t.eq(f.read(f.write(feature))[0].attributes.name, feature.attributes.name, "placemark name from attributes.name"); + feature.style = { + label: "placemark name from style.label" + }; + t.eq(f.read(f.write(feature))[0].attributes.name, feature.style.label, "placemark name from style.label"); + } +