[GIS] OpenLayers code didn’t response popup featureinfo

openlayers-2

Hey I'm trying to popup the featureinfo of WMS layer using OpenLayers code. But it does'nt work. Instead the cursor moves in the state of continous moving when I click on map. Here is my code:

<title>Untitled 1</title>
        <script src="http://localhost:8080/geoserver/openlayers/OpenLayers.js" type="text/javascript">
    </script>
    <script type="text/javascript">
        var map;
         var wms;
         var wms1;

        function init(){

            alert("inside function");
            var bounds = new OpenLayers.Bounds( 143.853, -43.648,
                148.479, -39.574);


        var options = {
        controls: [],
        maxExtent: bounds,
        maxResolution: 0.0180703125,
        projection: "EPSG:4326",
        units: 'm'
        };


            map = new OpenLayers.Map('map', options);
            wms = new OpenLayers.Layer.WMS("Peoples Colony", 
                               "http://localhost:8080/geoserver/wms",
                               { 
                                   LAYERS: "topp:tasmania_state_boundaries",
                                   STYLES: '',
                                   format: "image/jpeg",
                                   transparent: "true",
                                   tiled: 'true'

                               },
                               {

                    isBaseLayer: true,
                    yx : {'EPSG:4326' : true}

                               }
                               );
                               wms1 = new OpenLayers.Layer.WMS("tasmania_roads", 
                               "http://localhost:8080/geoserver/wms",
                               { 
                                   LAYERS: "topp:tasmania_roads",
                                   STYLES: '',
                                   format: "image/jpeg",
                                   transparent: "true",
                                   tiled: 'true'

                               },
                               {

                    isBaseLayer: false,
                    yx : {'EPSG:4326' : true}

                               }
                               );
        map.addLayers([wms,wms1]);
        map.zoomToMaxExtent();

             map.addControl(new OpenLayers.Control.Navigation());
              map.addControl(new OpenLayers.Control.Scale($('location')));


        var info = new OpenLayers.Control.WMSGetFeatureInfo({
        url: "http://localhost:8080/geoserver/wms", 
        title: 'Identify features by clicking',
        queryVisible: true,
        eventListeners: {
            "getfeatureinfo": function(event) {
                map.addPopup(new OpenLayers.Popup.FramedCloud(
                    "chicken", 
                    map.getLonLatFromPixel(event.xy),
                    null,
                    event.text,
                    null,
                    true
                ));
            }
        }
    });
    map.addPopup(info);
    info.activate();





}


</script>

Anyone plz help me out? I think that I didn't mention the layers here. Is this the problem?

Best Answer

This error, is because of the Openlayers library that you are using. The Library that comes with Geoserver, is a reduced, wms read only version , that does not have many functions & classes.

OpenLayers.Control.WMSGetFeatureInfo is one of the classes that is not present in the version that you are using.

Use the complete library by downloading it from the OpenLayers website.