3

this is my code i have included the control for get feature info but it seems like it's trying features for all the layers. how do i specify which layer to display the attributes

  var bounds = new OpenLayers.Bounds(
              4122931 ,-27181,4290853,76966  


             );

             var options = {
  controls: [
        new OpenLayers.Control.Navigation(),
        new OpenLayers.Control.ArgParser(),
        new OpenLayers.Control.Attribution(),
        new OpenLayers.Control.LayerSwitcher(),
        new OpenLayers.Control.MousePosition(),
        new OpenLayers.Control.OverviewMap(),
        new OpenLayers.Control.ScaleLine(),
        new OpenLayers.Control.PanZoomBar(),
        new OpenLayers.Control.KeyboardDefaults(),
        new OpenLayers.Control.WMSGetFeatureInfo({
         autoActivate: true,
      infoFormat: "application/vnd.ogc.gml",
       maxFeatures: 5,
         eventListeners: {
        "getfeatureinfo": function(e) {
    var items = [];
    Ext.each(e.features, function(feature) {
            items.push({
            xtype: "propertygrid",
            title: feature.fid,
            source: feature.attributes
            });
        });
    new GeoExt.Popup({
        title: "Feature Info",
        width: 200,
        height: 300,
        layout: "accordion",
        map: mapPanel,
        location: e.xy,
        items: items
        }).show();
    }
 }

 })
        ],
                             maxExtent: bounds,
                             maxResolution:[],
                             projection: "EPSG:4326",
                             units: 'm',


             };



             map = new OpenLayers.Map('map-id', options, {projection: new OpenLayers.Projection("EPSG:900913")},
    {displayProjection: new OpenLayers.Projection("EPSG:4326")},

    {units: 'm'},
    {allOverlays: true});

       // add OSM as base layer;
     var OSM = new OpenLayers.Layer.OSM("OpenStreetMap"


     );

             var sublocation = new OpenLayers.Layer.WMS(
                             "Meru county sublocations", "http://localhost:8080/geoserver/wms",
                             {
                                     srs: 'EPSG:4326',
                                     layers: 'richy:sublocation',                                       
                                     styles: 'polygon',
                                      format:'image/png',

                             },
                             {singleTiled: true, ratio:1}

             );
             var ponds= new OpenLayers.Layer.WMS(
                             "Meru county fish ponds", "http://localhost:8080/geoserver/wms",
                             {
                                     srs: 'EPSG:4326',
                                     layers: 'richy:ponds_data',
                                     format:'image/png',
                                     extractAttributes: true,
                                     transparent: true,
                                     styles: '',

                             },
                             {singleTiled: true, ratio:1},
                             {visibility:true}

             );
             var rivers = new OpenLayers.Layer.WMS(
                             "Meru county rivers", "http://localhost:8080/geoserver/wms",
                             {
                                     srs: 'EPSG:4326',
                                     layers: 'richy:rivers',
                                     format:'image/png',
                                     transparent:true,
                                     styles: '',

                             },
                             {singleTiled: true, ratio:1}

             );
             var towns = new OpenLayers.Layer.WMS(
                             "Meru county towns", "http://localhost:8080/geoserver/wms",
                             {
                                     srs: 'EPSG:4326',
                                     layers: 'richy:towns',
                                     format:'image/png',
                                     transparent:true,
                                     styles: '',

                             },
                             {singleTiled: true, ratio:1}

             );
            var roads = new OpenLayers.Layer.WMS(
                             "Meru county roads", "http://localhost:8080/geoserver/wms",
                             {
                                     srs: 'EPSG:4326',
                                     layers: 'richy:roads',
                                     format:'image/png',
                                     transparent:true,
                                     styles: '',

                             },
                             {singleTiled: true, ratio:1}
            );


      map.addLayers([OSM,sublocation,ponds,rivers,roads,towns]);

             map.zoomToExtent(bounds);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.