[OpenLayers-Users] Add labels above the lines.

Alexandre Dubé adube at mapgears.com
Fri Jul 27 06:08:39 PDT 2012


I think I got it.

All vector layers but the one with labels are used by a SelectFeature 
control which is currently active, which makes all the other layers 
always on top. Deactivate the control and you'll that the labels will be 
put on top.

To fix this, you could try adding your labels layer in the SelectFeature 
control as well and behave accordingly if a user click on a label. I 
don't really see any other way to have your labels on top as long as 
this control is active.

Tell me how that sounds.

Alexandre


On 12-07-27 08:57 AM, adidas wrote:
> 27.07.2012 15:49, Alexandre Dubé пишет:
>> Adidas,
>>
>> You could trying using the map setLayerIndex method.
>>
>> http://dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.setLayerIndex 
>>
>>
>> Alexandre
>>
>>
>> On 12-07-27 08:44 AM, adidas wrote:
>>> 27.07.2012 15:38, adidas пишет:
>>>> 27.07.2012 15:28, Alexandre Dubé пишет:
>>>>> Hi Adidas,
>>>>>
>>>>> Layers are displayed on top of each other in the order they were 
>>>>> added to the map : first added is at the bottom, last is on top. 
>>>>> The exception to that rule are layers with baseLayer:true property 
>>>>> set, which are always at bottom.
>>>>>
>>>>> Try to look in what position your label layer is added and push it 
>>>>> to the end.
>>>>>
>>>>> HTH,
>>>>>
>>>>> Alexandre
>>>>>
>>>>>
>>>>> On 12-07-27 06:54 AM, adidas wrote:
>>>>>> Hello! 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}
>>>>>> })
>>>>>> });
>>>>>> map.addLayer(vectorPoint);
>>>>>>
>>>>>> 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) {
>>>>>> layr.features[k].move(ttt);
>>>>>> layr.features[k].attributes.label=title;
>>>>>> 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: http://softez.pp.ua/labels.PNG
>>>>>> Map here: http://softez.pp.ua/fiberms/fiberms/map.php
>>>>>> Thanks!
>>>>>> _______________________________________________
>>>>>> Users mailing list
>>>>>> Users at lists.osgeo.org
>>>>>> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>>>>>
>>>>>
>>>> The layer of labels is ABOVE all.
>>> I meant that the layer with labels to the most recent.
>>> _______________________________________________
>>> Users mailing list
>>> Users at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>>
>>
> It did not help. :(
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users


-- 
Alexandre Dubé
Mapgears
www.mapgears.com



More information about the Users mailing list