0

在我的应用程序中,我有一个 googlemap 和一些来自 geoserver 的 WMS 图层,我需要选择这些图层上的功能,我遵循了这个示例: http: //openlayers.org/dev/examples/getfeature-wfs.html,我得到了没有错误,当我单击某个功能时,鼠标开始旋转,但根本没有结果,这是我的代码:

var ghyb = new OpenLayers.Layer.Google(
        "Google Hybrid",
        {"type": google.maps.MapTypeId.HYBRID, numZoomLevels: 20}
    );
            var options = {
            controls: [],
            //sphericalMercator:true,
            //projection: new OpenLayers.Projection('EPSG:900913'), // senza la proiezione mi stampa metà layer
            units: "m",
            numZoomLevels: 22,            
            maxResolution: 156543.0339,
            maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
                         20037508.34, 20037508.34)
            };
            var panZoom = new OpenLayers.Control.PanZoom();
        var map = new OpenLayers.Map('map', {
                div: "gmap",
                projection: "EPSG:900913",
                displayProjection: "EPSG:4326",
                //zoomOffset: 5
        controls: [
            panZoom,
            new OpenLayers.Control.Navigation()
        ]
        });
var regioni      = new OpenLayers.Layer.WMS(
            "regioni",
            "http://localhost:8080/geoserver/wms",
            {
            layers: "metmi-italy:reg2011_g" ,
            transparent: "true",
            format: "image/png",
            srs:'EPSG:900913', // old: 'EPSG:2077'
            //zoomOffset: 4,
            },
            {isBaseLayer: false,}
        );
control = new OpenLayers.Control.GetFeature({
        protocol: OpenLayers.Protocol.WFS.fromWMSLayer(regioni),
        box: true,
        hover: true,
        multipleKey: "shiftKey",
        toggleKey: "ctrlKey"
        });
select = new OpenLayers.Layer.Vector("Selezioni", {styleMap: 
        new OpenLayers.Style(OpenLayers.Feature.Vector.style["select"])
        });
map.addLayers([ghyb,regioni,select])
control.events.register("featureunselected", this, function(e) {
            removeFeaturesFromGrid(e.feature.fid);
        select.removeFeatures([e.feature]);

        });
control.events.register("featureselected", this, function(e) {
                console.log('selected')
                select.addFeatures([e.feature]);
                //addFeaturesToGrid(e.feature);         
        });
map.addControl(control);
control.activate()

我认为缺少某些东西,但我没有找到

4

1 回答 1

0

我没有使用 GetFeature 类,但在这种情况下我使用了 WMSGetFeatureInfo。

    var clickControl = new OpenLayers.Control.WMSGetFeatureInfo({
            url: 'http://localhost:8080/geoserver/wms',
            title: 'Some title',
            layers: [regioni],
            queryVisible: true,
            infoFormat: 'application/vnd.ogc.gml',
            maxFeatures: 10
    });

至于调试的一般步骤,我鼓励您使用您的工具来确定您的浏览器正在发出什么 HTTP 请求(如果有)。如果使用 Chrome 或 Safari,您可以右键单击“检查元素”,转到网络选项卡,然后单击地图。请求应显示在网络选项卡中,您可以诊断请求是否正确以及响应是否正确。

于 2013-10-03T16:05:28.890 回答