AW: [OpenLayers-Users] OpenLayers.Layer.GML and showing name= of
OSMdata
Arnd Wippermann
arnd.wippermann at web.de
Thu May 26 12:43:11 EDT 2011
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();
-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Hendrik
Oesterlin
Gesendet: Donnerstag, 26. Mai 2011 12:07
An: openlayers-users at lists.osgeo.org
Betreff: [OpenLayers-Users] OpenLayers.Layer.GML and showing name= of
OSMdata
Hello,
I'm trying to make an overlay to display some circle and the name of bus
stops using OpenStreetMap data.
I have extracted the amenity=bus_station and highway=bus_stop using osmosis.
I have figured out how to put some circle over the map to show the bus stops
using this code:
var Transports = new OpenLayers.Layer.GML("Transports", "arrets-bus.osm",
{format: OpenLayers.Format.OSM, styleMap:new OpenLayers.StyleMap({
"default": {
pointRadius: 4,
fillColor: "#00DD00",
strokeColor: "#ff0000",
fillOpacity: 0.2
}
})
});
map.addLayer(Transports);
An example is here: http://oesterlin.ile.nc/test/20110526atelier.html
I was not able to display any name= or other custom key beside or below the
circles. In this example, displaying "name=" and "karuia:MNCP=" would be
useful.
Is there a possibility to make OpenLayers filter by itself the required key
from an OpenStreetMap-XML file and display the contents?
Can someone give me some hints or even better some example how to do this?
Many thanks!
Hendrik Oesterlin
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users
More information about the Users
mailing list