在我的应用程序中我有一个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()
我认为有些东西缺失了,但我找不到它
答案 0 :(得分: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,您可以右键单击“检查元素”,转到网络选项卡,然后单击地图。请求应显示在网络选项卡中,您可以诊断请求是否正确以及响应是否正确。