Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
    
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

2 Answers 2

up vote 4 down vote accepted

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
        });
share|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?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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