Reputation: 355
KML file:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<name>Name</name>
<description><![CDATA[]]></description>
<Style id="style140"><IconStyle>
<Icon>
<name>Name</name>
<href>icon/green.png</href>
</Icon>
</IconStyle>
</Style>
<Placemark>
<name>Name</name>
<description>Desc Name</description>
<styleUrl>#style140</styleUrl>
<Point>
<coordinates>12.7548360932222,59.2701399304516,0.000000</coordinates>
</Point>
</Placemark>
</Document>
</kml>
And i get this output:
but I want this:
So you can see the name of the point. What Is wrong in the kml file?
Thx!
Upvotes: 3
Views: 2650
Reputation: 99
This is how I solved my problem...hope this helps.
var layerData = new OpenLayers.Layer.Vector("test1", {
renderers: ["SVG", "Canvas", "VML"],
strategies: [new OpenLayers.Strategy.Save({
auto:true
}),new OpenLayers.Strategy.Cluster({
distance: clusteringDistance,
threshold: clusteringThreshold,
shouldCluster: function(cluster, feature) {
updateFeatureStyle(feature);
if (feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point" && boundArea >= maxBoundAreaForClustering) {
return OpenLayers.Strategy.Cluster.prototype.shouldCluster.apply(this, arguments);
} else {
return false;
}
}
})],
styleMap: clusterStyle
});
blankLayer = true;
layerData.setVisibility(false);
function updateFeatureStyle(feature) {
feature.style.label = "\n\n " + feature.attributes.name;
feature.style.labelAlign = 'ct';
feature.style.fontColor = 'red';
feature.style.fontFamily = 'Arial';
feature.style.fontSize = '10px';
feature.style.fontOpacity = 1;
feature.style.graphicTitle = feature.attributes.name;
}
Upvotes: 0
Reputation: 21
I don't know if this helps, but I found that the method that you want to use does not work. I was able to set this programmatically in javascript. This allows you to have a label just above the redcircle icon that you create yourself.
Hope this helps!
javascript (minus other code to build map object etc):
function addLayer(){
var myStyles = new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
strokeColor: "#FFCC33",
strokeWidth:10,
strokeOpacity:1,
fillColor:"#003399",
fillOpacity: 1,
externalGraphic: "icons/redcircle.png",
labelYOffset: 15,
pointRadius: 5,
label:"${label}",
})
});
currentLayer = new OpenLayers.Layer.Vector("KML", {
styleMap: myStyles,
projection: map.displayProjection,
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "/kml/mymap.kml",
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true
})
})
});
KML file:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<description><![CDATA[]]></description>
<Placemark>
<label>Name</label>
<description>Desc Name</description>
<Point>
<coordinates>-122.98676101, 49.16702016,0.000000</coordinates>
</Point>
</Placemark>
</Document>
</kml>
Upvotes: 2
Reputation: 10346
I see the tag of the placemark name rendered in white with full opacity by default in Google Earth. Try specifying a Label Style element in your style to get that color and opacity.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<name>Name</name>
<description><![CDATA[]]></description>
<Style id="style140">
<IconStyle>
<Icon>
<name>Name</name>
<href>icon/green.png</href>
</Icon>
</IconStyle>
<LabelStyle>
<color>ffff55ff</color>
</LabelStyle>
</Style>
<Placemark>
<name>Name</name>
<description>Desc Name</description>
<styleUrl>#style140</styleUrl>
<Point>
<coordinates>12.7548360932222,59.2701399304516,0.000000</coordinates>
</Point>
</Placemark>
</Document>
</kml>
Upvotes: 0