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?

10
  • Did you have any error messages in console?
    – drnextgis
    Commented Oct 15, 2012 at 2:42
  • @drnextgis Yeah one error comes. But i don't know what it is. It is: Uncaught TypeError: undefined is not a function
    – muzaffar
    Commented Oct 15, 2012 at 6:19
  • Try to use uncompressed version of OpenLayers. Instead $OL_HOME/OpenLayers.js include $OL_HOME/lib/OpenLayers.js to your page. In this case you can get link to place in code where error is occured.
    – drnextgis
    Commented Oct 15, 2012 at 6:29
  • @drnextgis This time, error is: Uncaught TypeError: Cannot read property 'events' of null
    – muzaffar
    Commented Oct 15, 2012 at 6:57
  • Could you share all your code or give link to live demo? And try to write 'getfeatureinfo' instead getfeatureinfo (with quotes).
    – drnextgis
    Commented Oct 15, 2012 at 7:54

1 Answer 1

4

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.

1
  • Thanx alot, Its working now. I'm not believing yet that it was the actual Problem :P
    – muzaffar
    Commented Oct 15, 2012 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.