Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am using openlayers and Geoserver. I have created a base layer using OSM and then added wms layer topp:states. I want to show a world map and on that show US states. I have added onclick functionality to get feature info. However, when I click at any states, it gives incorrect state name or no result. This further worsens when I zoom in/zoom out or change the scale.Here is my code:

CSS:

#map {

            position: relative;
            height:1000px;
            width:1400px;

            float:left;
            margin:0px ;
        }

Script:

 var bounds = new OpenLayers.Bounds(
           -180,-90,0,90
        );

        format = 'image/png';

        var options = {
             controls: [],
            maxExtent: bounds,
            maxResolution: 0.22563114453125,
            projection: "EPSG:4326",
            units: 'degrees',
            displayProjection: new OpenLayers.Projection("EPSG:4326")

        };
        map = new OpenLayers.Map('map', options);
        layer = new OpenLayers.Layer.OSM("Base OpenStreet Map");
     states = new OpenLayers.Layer.WMS(
            "NA states", "http://localhost:8080/geoserver/wms",
            {
                layers: 'topp:states', styles: '', transparent: true,  format: 'image/png'
            },
            { isBaseLayer: false, singleTile: false,displayOutsideMaxExtent: true, ratio: 1,yx : {'EPSG:4326' : true} }
        );
       map.addLayers([layer,states]);

Code with call to getfeatureInfo:

       map.events.register('click', map, function (e) {
                            document.getElementById('nodelist').innerHTML =   "Loading... please wait...";
                            OpenLayers.Request.GET({url:"http://localhost:8080/geoserver/wms",params:{
                                REQUEST: "GetFeatureInfo",
                                EXCEPTIONS: "application/vnd.ogc.se_xml",
                                BBOX: bounds.toBBOX(),
                                 SERVICE: "WMS",
                                INFO_FORMAT: 'text/html',
                                QUERY_LAYERS: [ map.layers[1].params.LAYERS],
                                FEATURE_COUNT: 50,
                                Layers: [map.layers[1].params.LAYERS],
                                 WIDTH: map.size.w,
                                HEIGHT: map.size.h,
                                x: Math.floor(e.xy.x),
                                 y: Math.floor(e.xy.y),

                               }, success:setHTML});
                            OpenLayers.Event.stop(e);
                       });

It may have to do with bounds or extents,but that's just my guess.

share|improve this question
2  
Is your base map really in EPSG:4326? OSM data is usually EPSG:3857 (or some alias of that, like EPSG:900913) –  BradHards Feb 18 '13 at 6:44
    
I am using following code to transform the bounds before making a call to getfeatureInfo: var EPSG4326 = new OpenLayers.Projection("EPSG:4326"); var EPSG900913 = new OpenLayers.Projection("EPSG:900913"); var bounds = map.getExtent().clone(); bounds = bounds.transform(EPSG900913, EPSG4326); –  vyh Feb 18 '13 at 7:32
1  
Since that isn't in the code above, it seems you might not have posted (all) the relevant code. Can you please edit your question to match the code you are actually trying to run? If its long, can you try hosting it somewhere public? –  BradHards Feb 18 '13 at 8:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.