[OpenLayers-Users] How to achieve getfeatureinfo-popup in my local computer.

zhoujian_ab zhoujian_ab at 163.com
Thu Oct 8 21:07:50 EDT 2009


Hi:
   I am following the example of getfeatureinfo-popup to write down the code. And I want to use geoservers example to get the feature in my local computer like the example when click the object I can see its feature in a popup window. However, I can't. I don't know why. Please help me . Thanks a lot.

<html>
  <head>
    <title>GetFeatureInfo Popup</title>
    <script src="openlayers/OpenLayers.js"></script>
    <link rel="stylesheet" href="source/style1.css" type="text/css" />
    <link rel="stylesheet" href="source/style.css" type="text/css" />
    <script>
    OpenLayers.ProxyHost = "proxy.cgi?url=";
    
    var map, info;
    
    function load() {
        map = new OpenLayers.Map({
            div: "map",
            maxExtent: new OpenLayers.Bounds(143.834,-43.648,148.479,-39.573)
        });
        var political = new OpenLayers.Layer.WMS("State Boundaries",
            "http://localhost:8081/geoserver/wms", 
            {'layers': 'topp:tasmania_state_boundaries', transparent: true, format: 'image/gif'},
            {isBaseLayer: true}
        );
        var water = new OpenLayers.Layer.WMS("Bodies of Water",
            "http://localhost:8081/geoserver/wms", 
            {'layers': 'topp:tasmania_water_bodies', transparent: true, format: 'image/gif'},
            {isBaseLayer: false}
        );
       //what's mean of the red code?(I capy form the example)
        var highlight = new OpenLayers.Layer.Vector("Highlighted Features", {
            displayInLayerSwitcher: false, 
            isBaseLayer: false 
        });
        
        map.addLayers([political,water, highlight]); 
        info = new OpenLayers.Control.WMSGetFeatureInfo({
            url: 'http://localhost:8081/geoserver/wms', 
            'layers': 'topp:tasmania_water_bodies',
            queryVisible: true,
            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();
        map.addControl(new OpenLayers.Control.LayerSwitcher());
        map.zoomToMaxExtent();
    }
  </script>
  </head>
  <body onload="load()">
      <h1 id="title">Feature Info in Popup</h1>
      <div id="tags"></div>
      <p id="shortdesc">
        Demonstrates the WMSGetFeatureInfo control for fetching information
        about a position from WMS (via GetFeatureInfo request).  Results
        are displayed in a popup.
      </p>
      <div id="map" class="smallmap"></div>
    <div id="docs"></div>
  </body>
</html>
      
2009-10-09 



zhoujian_ab 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20091009/4ccbf929/attachment.html


More information about the Users mailing list