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 to add labels above the lines? Labels are added as follows:

    var styleMarkersLabels = new OpenLayers.Style( // стили для надписей узлов
                    strokeWidth: 2,
                    labelYOffset: 10,
                    label: "${label}",
                    fontColor: 'red',
                    fontSize: 9,
                    fontWeight: "bold",
                    labelOutlineColor: "black",
                    labelOutlineWidth: 1
            var vectorPoint = new OpenLayers.Layer.Vector("Узлы (надписи)",
                styleMap: new OpenLayers.StyleMap(
                { "default": styleMarkersLabels,

                "select": { pointRadius: 20}

            function addPoint(lon, lat, title, ident, layr){
                var ttt = new OpenLayers.LonLat(parseFloat(lon), parseFloat(lat));
                ttt.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
                for (var k = 0; k < layr.features.length; k++) {
if(layr.features[k].attributes.PointId==ident) {
                        return false;
                var point0 = new OpenLayers.Geometry.Point(parseFloat(lon), parseFloat(lat));
                point0.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
                layr.addFeatures(new OpenLayers.Feature.Vector(point0, { label: title, name: title, PointId: ident }));

            var lat2, lon2, title, ident;
            for (l = 0; l < nodesLabels_Count; l++) {
                lat2 = nodesLabels_arr[l]["points"][0]["lat"];
                lon2 = nodesLabels_arr[l]["points"][0]["lon"];
                title = nodesLabels_arr[l]["title"];
                ident = nodesLabels_arr[l]["ident"];
                addPoint(lon2, lat2, title, ident, map.layers[4]);

But i got it: The line on top of the label.

Map here: http://softez.pp.ua/fiberms/fiberms/map.php


share|improve this question

1 Answer 1

up vote 1 down vote accepted

I found the solution. Need add labels layer in the SelectFeature control (because the lines layer is added to SelectFeature control). P.S. Thanks Alexandre from OpenLayers Mail List.

share|improve this answer

Your Answer


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.