Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using this code to add xml (osm relations) 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


However, I can't make it work with xml / OSM relation format...


share|improve this question
up vote 3 down vote accepted

You should create empty vector layer and then add vector features from your files:

var osm = new OpenLayers.Format.OSM();
var files = ["url1", "url2", "urlN"];
var vector = new OpenLayers.Layer.Vector("OSM Layer");

for (var i = 0; i < files.length; i++){
        url: files[i],
        success: function(e){vector.addFeatures(}
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.