AW: [OpenLayers-Users] OpenLayers.Layer.GML and showing name= of OSMdata

Hendrik Oesterlin hendrikmail2002 at yahoo.de
Fri May 27 03:40:17 EDT 2011


"Arnd Wippermann" arnd.wippermann at web.de wrote on 27/05/2011 at 03:43:11 +1100
subject "AW: [OpenLayers-Users] OpenLayers.Layer.GML and showing name= of OSMdata" :

> You can get access to the attributes by feature.attributes["amenity"] ...

> To get some labels from two attributes use a styleMap with context. With the
> below code you should be able to show your labels.

> Arnd

> var styleMapLabelDS; //DS default and select style

> function set_styleMapLabelDS()
> {
>     var context = {
>         getName : function (ft){
>             var label1 = "";
>             var label2 = "";
>             var theLabel = "";
>             if(ft.attributes.name != undefined)
>                 label1 = ft.attributes.name;
>             if(ft.attributes["karuia:CAP"] != undefined)
>                 label2 = ft.attributes["karuia:CAP"];
>             if(label1 != "" && label2 != "")
>                 theLabel = label1 + ", " + label2;
>             else if(label1 != "")
>                 theLabel = label1;
>             else if(label2 != "")
>                 theLabel = label2;

>             return theLabel;
>         }
>     };
>     var template = {
>         strokeColor: "#0000FF",
>         strokeOpacity: 1,
>         strokeWidth: 3,
>         fillColor: "#00AAFF",
>         fillOpacity: 1,
>         pointRadius: 5,
>         pointerEvents: "visiblePainted",

>         label : "${getName}",

>         labelXOffset: "10",
>         labelYOffset: "-10",
>         fontColor: "blue",
>         fontSize: 10,
>         fontFamily: "Arial",
>         fontWeight: "bold",
>         labelAlign: "lt"
>     };
>     var templateB = {
>         strokeColor: "#FFFF00",
>         strokeOpacity: 1,
>         strokeWidth: 3,
>         fillColor: "#FFFF00",
>         fillOpacity: 1,
>         pointRadius: 5,
>         pointerEvents: "visiblePainted",

>         label : "${getName}",

>         labelXOffset: "10",
>         labelYOffset: "-10",
>         fontColor: "red",
>         fontSize: 10,
>         fontFamily: "Arial",
>         fontWeight: "bold",
>         labelAlign: "lt"
>     };
>     styleMapLabelDS = new OpenLayers.StyleMap( { "default" : new
> OpenLayers.Style(template, {context:context}), "select" : new
> OpenLayers.Style(templateB, {context:context}) } );
> }

> set_styleMapLabelDS();
> Transports["styleMap"]=styleMapLabelDS;
> Transports.redraw();

Thank you very much! This example helps me a lot.

-- 
Sincerely 
Hendrik Oesterlin - email hendrikmail2002 at yahoo.de



More information about the Users mailing list