NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I'm using OpenLayers to display some OSM relations and then add some tags to them. I'm using this code to add xml files to my map.

osm_layer = new OpenLayers.Layer.GML("Polygon", relation.xml, {
format: OpenLayers.Format.OSM,
style: {strokeColor: "blue"},
projection: new OpenLayers.Projection("EPSG:4326")
});

But what I need is to add more than one relation.xml per layer, as relation1.xml, relation2.xml in the SAME layer. Until know I can only show multiple xml if they go in multiple layers.

When using vectors I just created the layer and then added the vectors by something like

polygonFeature = new OpenLayers.Feature.Vector(
                 new OpenLayers.Geometry.Polygon(linearRing), style);

And then

Layer.addFeatures(polygonFeature);

However, I can't make it work with xml / OSM relation format... It should be something like

        i=1;
        while(i<relations_list.length)
        { 
            osm_layer = new OpenLayers.Layer.GML("GML") 
            map.addLayer(osm_layer);

            xml_feature = new Openlayers.Feature.Vector(relation[i], {
                    format: OpenLayers.Format.OSM,
                    style: {strokeWidth: 3},
                    projection: new OpenLayers.Projection("EPSG:4326")
                });

            osm_layer.addFeatures(xml_feature);

            i=i+1;

            if(relations_list[i]=="") {i=relations_list.length;}
        }

Thanks

asked 03 May '12, 17:40

JorgePM's gravatar image

JorgePM
51224
accept rate: 0%


Maybe a look at the source of WIWOSM can help you.

permanent link

answered 05 May '12, 10:10

malenki's gravatar image

malenki
4.7k24683
accept rate: 6%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×710
×236
×122

question asked: 03 May '12, 17:40

question was seen: 5,538 times

last updated: 05 May '12, 10:10

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum