我正在尝试使用 WMS 在 Open Layers 上向 Geoserver 发出 GetFeatureInfo 请求。该请求似乎已按预期进行并在每次点击时加载,但“图像”每次都崩溃。该请求是通过我自己的计算机上的代理发出的,该代理似乎运行良好。这是事件的图像和我一直在使用的代码。由于我对这方面的所有组件都非常缺乏经验,因此将不胜感激。感谢你们。
剧本 :
<script>
var layers = [];
layers[0] = new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'http://localhost:8080/geoserver/AL2/wms?',
params: { LAYERS: 'AL2:A2', 'TILED': true, projection: 'EPSG:4326', VERSION: '1.1.1' },
servertype: 'geoserver'
})
});
layers[1] = new ol.layer.Tile({
source: new ol.source.OSM()
});
layers[2] = new ol.layer.Tile({
source: new ol.source.OSM()
});
var map = new ol.Map({
target: 'map',
layers: layers,
view: new ol.View({
center: ol.proj.fromLonLat([13, 56]),
zoom: 8,
EPSG: 4326,
})
});
function switchLayer(evt) {
layers[evt.value].setVisible(evt.checked);
}
map.on('singleclick', function (event) {
var url = '../../proxy/proxy.aspx?url=' + layers[0].getSource().getFeatureInfoUrl
(event.coordinate,
map.getView().getResolution(), map.getView().getProjection().getCode(),
{
INFO_FORMAT: 'text/html',
Layers: "AL2:A2"
});
if (url) {
document.getElementById('info').innerHTML =
'<iframe seamless src="' + url + '"></iframe>'
}
});
</script>
HTML:
<!DOCTYPE html >
<meta charset = "utf-8"/>
<title > OpenLayers </title>
<link rel = "stylesheet" href = "https://openlayers.org/en/v6.5.0/css/ol.css" type = "text/css">
<script src = "https://openlayers.org/en/v6.5.0/build/ol.js" script type = "text/javascript" ></script>
</head>
<body>