openLayers wms pop-up不起作用

时间:2012-07-05 06:43:12

标签: openlayers

我构建了一个openLayers地图,我想实现一个弹出窗口。我正在关注一些google创建的资源: http://lists.osgeo.org/pipermail/openlayers-users//2011-August/021680.html

代码是:

<script type="text/javascript">
   var map;
   var osm;
   var layer;
   var info;
   function init() {
         var bounds = new OpenLayers.Bounds(
                1160036.31025726, 7444371.48007091,
                1160792.70130936, 7444966.36493288
                );
         map = new OpenLayers.Map("map", {
                maxExtent: bounds,
 });
     osm =new OpenLayers.Layer.OSM({visibility: true});
     layer = new OpenLayers.Layer.WMS(
                "Working Field", "http://localhost:8080/geoserver/layer/wms",
                {
                layers: 'layer:layer',
                transparent: true,
                isBaseLayer: false
                },
                {
                sphericalMercator: true,                        
                opacity: 0.5
                }
            );


          map.addLayers([osm,layer]);
          map.zoomToExtent(bounds);
   info = new OpenLayers.Control.WMSGetFeatureInfo({
            url: "http://localhost:8080/geoserver/wms",
            //layerUrls: 'http://localhost:8080/geoserver/layer/wms',
    title: 'Identify features by clicking',
            layers: [acm],
    queryVisible: true,
    infoFormat: 'text/html',
    maxFeatures: 1,
    eventListeners: {
        getfeatureinfo: function(event) {
            if (event.text.indexOf("<table class=\"featureInfo\">") != -1){
                popup = new OpenLayers.Popup.FramedCloud(
                    "chicken", 
                    map.getLonLatFromPixel(event.xy),
                    null,
                    event.text,
                    null,
                    true
                ), {
                    autoSize: false,
                    maxSize: new OpenLayers.Size(5,5)
                };
                map.addPopup(popup);
            }
        }
    }
});
map.addControl(info);
  }
 </script>

任何有关错误的线索都会有所帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

实际上图层:[acm] 未定义,还有一件事我们需要激活信息控件,如:

info.activate();