1

Using some examples from internet, I found this code that shows WMSGetfeatureinfo

I don't know where's the problem:

Here goes my code:

<!DOCTYPE HTML>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>MB_OL</title>
<link rel="stylesheet" href="css/google.css">
<link rel="stylesheet" href="css/view_css.css">
<link rel="stylesheet" href="../openlayers/theme/default/style.css" type="text/css" />
<script src="../openlayers/OpenLayers.js"></script>
<script src="../openlayers/OpenLayers.debug.js"></script>
<script src="../openlayers/OpenLayers.light.debug.js"></script>
<script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>
<script>
var map;
var wgs84 = new OpenLayers.Projection("EPSG:4326"); 
var mercator = new OpenLayers.Projection("EPSG:900913"); 
var info;
var mesorregioes =  new OpenLayers.Layer.WMS(
        "MB:meso_domicilios - Tiled", "http://wololo.eti.br:8081/geoserver/MB/wms",
                    {
                        LAYERS: 'MB:meso_domicilios',
                        STYLES: 'estilo_meso',
                        tiled: true,
                        transparent: "true",
                        format: "image/png",

                                           },
                    {
                        buffer: 0,
                        displayOutsideMaxExtent: true,
                        isBaseLayer: false,
                        yx : {mercator : true}
                    } 
                    );
var gmaps =  new OpenLayers.Layer.Google(
                            "Google Streets", // the default
                {numZoomLevels: 20}

            );

function init() {
    map = new OpenLayers.Map('map', {

            layers: [ gmaps,
             mesorregioes,
                      ],
        projection: new OpenLayers.Projection(wgs84),
               displayProjection: new OpenLayers.Projection(wgs84),
        center: new OpenLayers.LonLat(-53.375, -29.813)
            // Google.v3 uses web mercator as projection, so we have to
            // transform our coordinates
           .transform(wgs84, mercator),
        zoom: 7,

    }

    );
info = new OpenLayers.Control.WMSGetFeatureInfo({ 
------> on firebug it shows right here: uncaught typeerror: undefined is not a function
            url: 'http://wololo.eti.br:8081/geoserver/MB/wms', 
            title: 'Identify features by clicking', 
            queryVisible: true,
            /*version: layers[0].params.VERSION, */
            layers: 'MB:meso_domicilios',           
            eventListeners: { 
                getfeatureinfo: function(event) { 
                    map.addPopup(new OpenLayers.Popup.FramedCloud( 
                        "chicken", 
                        map.getLonLatFromPixel(event.xy), 
                        null, 
                        event.text, 
                        null, 
                        true 
                    )); 
                } 
            } 
        }); 
        map.addControl(info); 
        info.activate();  


/*  
function formatLonlats(lonLat) {
        var lat = lonLat.lat;
        var long = lonLat.lon;
        return 'Coordenadas em EPSG-4326:  ' + lat + ', ' + long;
        };


        //funcao que troca de centro para a uniao

        function uniao (){
            map.setCenter(
        new OpenLayers.LonLat(-18.771115, -42.758789).transform(wgs84, mercator),5 )
        }; */
    }

</script>

<body onLoad="init()">
<div id="map" class="mapa"></div>
<div id="info_meso"></div>
</body>
</html>
3
  • 1
    What evidence do you have that there is a problem? An error message? Unexpected behavior? Please be specific and clear in order to make this an answerable question.
    – whuber
    Commented May 5, 2013 at 20:12
  • Make sure your copy of OpenLayers has WMSGetFeatureInfo built-in. OpenLayers is a modular system, and not all the possible features are activated by default in every version/distribution.
    – relet
    Commented May 6, 2013 at 5:47
  • Hi whuber, I'm sorry for the clearness, I was very angry with this problem. I've used firebug to return me that error. This code shows me the map and the wms layer, but doesn't return WMSGetFeatureInfo. Hi relet, thanks for your answer, I'll see if I have this built-in on my geoserver.
    – Ycavazin
    Commented May 6, 2013 at 21:07

1 Answer 1

1

This works:

<!DOCTYPE html>
    <html>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <meta name="apple-mobile-web-app-capable" content="yes">
            <title>OpenLayers Vector Behavior Example</title>
            <link rel="stylesheet" href="http://openlayers.org/dev/theme/default/style.css" type="text/css">
            <link rel="stylesheet" href="http://openlayers.org/dev/examples/style.css" type="text/css">
          <script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>
            <script src="http://openlayers.org/dev/OpenLayers.js"></script>

    </head>

    <body onLoad="init()">
    <div id="map" class="mapa"></div>
    <div id="info_meso"></div>
    <script>


    function init() {
        var map;
        var wgs84 = new OpenLayers.Projection("EPSG:4326"); 
        var mercator = new OpenLayers.Projection("EPSG:900913"); 
        var info;
        var mesorregioes =  new OpenLayers.Layer.WMS(
                "MB:meso_domicilios - Tiled", "http://wololo.eti.br:8081/geoserver/MB/wms",
                            {
                                LAYERS: 'MB:meso_domicilios',
                                STYLES: 'estilo_meso',
                                tiled: true,
                                transparent: "true",
                                format: "image/png",

                                                   },
                            {
                                buffer: 0,
                                displayOutsideMaxExtent: true,
                                isBaseLayer: false,
                                yx : {mercator : true}
                            } 
                            );
        var gmaps =  new OpenLayers.Layer.Google(
                                    "Google Streets", // the default
                        {numZoomLevels: 20}

                    );
        map = new OpenLayers.Map('map', {

                layers: [ gmaps,
                 mesorregioes,
                          ],
            projection: new OpenLayers.Projection(wgs84),
                   displayProjection: new OpenLayers.Projection(wgs84),
            center: new OpenLayers.LonLat(-53.375, -29.813)
                // Google.v3 uses web mercator as projection, so we have to
                // transform our coordinates
               .transform(wgs84, mercator),
            zoom: 7,

        }

        );
        info = new OpenLayers.Control.WMSGetFeatureInfo({ 
                url: 'http://wololo.eti.br:8081/geoserver/MB/wms', 
                title: 'Identify features by clicking', 
                queryVisible: true,
                /*version: layers[0].params.VERSION, */
                layers: 'MB:meso_domicilios',           
                eventListeners: { 
                    getfeatureinfo: function(event) { 
                        map.addPopup(new OpenLayers.Popup.FramedCloud( 
                            "chicken", 
                            map.getLonLatFromPixel(event.xy), 
                            null, 
                            event.text, 
                            null, 
                            true 
                        )); 
                    } 
                } 
            }); 
            map.addControl(info); 
            info.activate();
        }



    </script>

    </body>
    </html>
1
  • Hi Kitex, thanks for the advance on my code. I'll test it.
    – Ycavazin
    Commented May 6, 2013 at 21:09

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.