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.

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?

share|improve this question
    
Did you have any error messages in console? –  drnextgis Oct 15 '12 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 Oct 15 '12 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 Oct 15 '12 at 6:29
    
@drnextgis This time, error is: Uncaught TypeError: Cannot read property 'events' of null –  muzaffar Oct 15 '12 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 Oct 15 '12 at 7:54

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
Thanx alot, Its working now. I'm not believing yet that it was the actual Problem :P –  muzaffar Oct 15 '12 at 10:43

Your Answer

 
discard

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

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