Reputation: 305
I am importing KML files to overlay on a map.
OL3 does a great job with the geometry, but seems to ignore the text labels that should show up with them.
This snippet will put up a pin, but will not show the text in the <name>
element as it did in Google Earth and Maps
<Placemark>
<name>Text I want to show</name>
<Point>
<coordinates>-81.11918192120308,32.27372446636573,0</coordinates>
</Point>
</Placemark>
Upvotes: 0
Views: 1475
Reputation: 12581
There is nothing in the specification of KML that states that the <name>
tag of a <Placemark>
should be rendered along with a pushpin or icon -- Google just chose to implement it that way.
If you look at the OpenLayers Swiss hotels KML example, you will probably agree that automatically showing the text labels would make the screen too busy. However, it is fairly straightforward to add labels on mouseover, using the map.forEachFeatureAtPixel
function, as is done in this kml earthquake exmaple, which pushes the name attribute of the KML tag into an info div, as you can see in this code snippet:
var feature = map.forEachFeatureAtPixel(pixel, function(feature, layer) {
return feature;
});
if (feature) {
info.tooltip('hide')
.attr('data-original-title', feature.get('name'))
.tooltip('fixTitle')
.tooltip('show');
} else {
info.tooltip('hide');
}
So, the <name>
tag of <Placemark>
is parsed, but the display is left up to you in OpenLayers, by design, not by defect.
Upvotes: 1