[OpenLayers-Users] a getfeatureinfo doesn't work

ben afia olfa benafia_olfa at yahoo.fr
Thu May 10 05:13:08 EDT 2007


Hi ,
I tried to follow th exemple given by  Brent Pedersen http://giifweb.cnr.berkeley.edu/fire/wind/gfi/gfi.html
to get a feature info from a map got from geoserver but it dosen't work the problem is with OpenLayers.loadURL ( I use Openlayers 2.3)

and here is my code :


  <head>
    <style type="text/css">
        #map {
            width: 600px;
            height: 600px;
            border: 1px inset black;
        }
    </style>
    <script>
    if(window.console == undefined){ console = {}; console.debug = function(){}}
    </script>
    <script src="../lib/OpenLayers.js"></script>
    <script type="text/javascript">
        var map, layers;


        OpenLayers.Layer.WMS.prototype.getFeatureInfoURL = function(e/*,info_format*/){
            var x = e.xy.x
            var y = e.xy.y
            /*
            var el = Event.findElement(e,'div');
            var p = OpenLayers.Util.pagePosition(el);
            x -= p[0];
            y -= p[1];
            */

          //  var url = this.getURL(this.map.getExtent())
          //          .replace(/getMap/i,'GetFeatureInfo');

            var ms = this.map.getCurrentSize();
            var format = arguments.length > 1 ? arguments[1] : 'text/plain'
            var url = 'http://localhost:8080/geoserver/wms?bbox=-130,24,-66,50&styles=population&format=jpeg&info_format=text/plain&request=GetFeatureInfo&layers=topp:states&query_layers=topp:states&width=550&height=250&x=170&y=160';
            //url = url.replace(/&width=[^&\?$]+/i,'&WIDTH=' + ms.w)
              //       .replace(/&height=[^&\?$]+/i,'&HEIGHT=' + ms.h)
            alert(url);
            return url 
        };




        function init(){

            map = new OpenLayers.Map($('map'),{projection:'EPSG:4326',
                controls: [new OpenLayers.Control.MouseDefaults()],
                maxExtent: new OpenLayers.Bounds(-130,24,-66,50)

            });
            
            muni = new OpenLayers.Layer.WMS( "Cities and Counties",
                    "http://localhost:8080/geoserver/wms?"
                    , {layers: 'topp:states', format: 'image/png' }
                    , { 
                         tileSize: new OpenLayers.Size(512,512)
                        ,isBaseLayer:true
                        ,reproject:false
                      }
            );

            map.addLayer(muni);

            map.addControl(new OpenLayers.Control.PanZoomBar());
            map.addControl(new OpenLayers.Control.LayerSwitcher());

          
            map.zoomToMaxExtent()

            map.events.register('click',map,mapquery);
            


function mapquery(evt){
    var url = muni.getFeatureInfoURL(evt);
    alert(url);
    OpenLayers.loadURL(url,{},this,function(req){   // the problem is here
              alert(req.responseText)  
              
     });
}


        }

    </script>
  </head>

  <body onload="init()">
    <div id="map"></div>
  </body>
</html>





      ____________________________________________________________________________________________
Découvrez le blog Yahoo! Mail : dernières nouveautés, astuces, conseils.. et vos réactions !
http://blog.mail.yahoo.fr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20070510/f3cbe021/attachment.html


More information about the Users mailing list