How can I display labels for features in a KML file on an OpenLayers map. I was thinking of using popup messages, but labels are more attractive and eye-catching.

I want to replicate the labeling method of Google Earth:

enter image description here

Any hints? Thanks in advance.

  • zearth, didn't you mean labling features imported from a KML file? The example has lables but it's labling features that are defined in the same file... – user3956 Aug 16 '11 at 15:00
  • John Doe, oh yeah. It's like we are using imported KML file. The labeling method shown below are features, not KML. – zearth Aug 17 '11 at 2:37

Have you checked the OpenLayers Labeled features example?

enter image description here

        var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {
            styleMap: new OpenLayers.StyleMap({'default':{
                strokeColor: "#00FF00",
                strokeOpacity: 1,
                strokeWidth: 3,
                fillColor: "#FF5500",
                fillOpacity: 0.5,
                pointRadius: 6,
                pointerEvents: "visiblePainted",
                // label with \n linebreaks
                label : "name: ${name}\n\nage: ${age}",

                fontColor: "${favColor}",
                fontSize: "12px",
                fontFamily: "Courier New, monospace",
                fontWeight: "bold",
                labelAlign: "${align}",
                labelXOffset: "${xOffset}",
                labelYOffset: "${yOffset}"
            renderers: renderer
| improve this answer | |
  • Thanks @underdark. Besides, I already using this example too. But, I'm thinking more like KML label that refresh simultaneously. Is that even possible? Like we view in Google Earth. – zearth Aug 11 '11 at 0:55
  • Currently using this coding till I find better answer. – zearth Aug 17 '11 at 2:36

My homework on this suggests placemark labels in google maps are hardly supported. But I find that hard to believe. I'd like to be using placemark labels on google maps kml which originates from Spreadsheet Mapper 2.0. Anyone done that?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.