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

In the following code if I use the WMS layer my polygons (the geos variable) are displayed properly. If I switch to the OSM layer the OSM layer displays just fine, but the vector layer disappears from the map (despite being in the layers collection. Any ideas?

var options = {
                projection: "EPSG:4326",
                displayProjection: "EPSG:4326",
                numZoomLevels: 20
            };
            that.map = new OpenLayers.Map('map', options);
//            that.layer = new OpenLayers.Layer.WMS("OpenLayers WMS",
//                "http://vmap0.tiles.osgeo.org/wms/vmap0",
//                { layers: 'basic' });

            that.layer = new OpenLayers.Layer.OSM({ opacity: 50 });

            var featurecollection = {
                "type": "FeatureCollection",
                "features": [
                    { "geometry": {
                        "type": "GeometryCollection",
                        "geometries": geos
                    },
                        "type": "Feature",
                        "properties": {}
                    }
                ]
            };

            var geojson_format = new OpenLayers.Format.GeoJSON();            
            var vector_layer = new OpenLayers.Layer.Vector();

            that.map.addLayers([vector_layer, that.layer]);

            vector_layer.events.register("featureadded", that.map.layers[1], that.zoomToLeftHalf);
            vector_layer.addFeatures(geojson_format.read(featurecollection));

asked 01 Mar '12, 04:09

coreyperkins's gravatar image

coreyperkins
1111
accept rate: 0%

edited 01 Mar '12, 17:08

SomeoneElse's gravatar image

SomeoneElse ♦
36.9k71370866

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
×122
×45
×34

question asked: 01 Mar '12, 04:09

question was seen: 5,424 times

last updated: 01 Mar '12, 17:08

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