Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Openlayers 有人能帮我让WMSGetFeatureInfo工作吗?_Openlayers_Wms - Fatal编程技术网

Openlayers 有人能帮我让WMSGetFeatureInfo工作吗?

Openlayers 有人能帮我让WMSGetFeatureInfo工作吗?,openlayers,wms,Openlayers,Wms,我是Openlayers的新手,非常感谢能为WMSGetFeatureInfo提供一些帮助。我试过几个例子,每次我把它粘贴到我的代码中,我都会得到相同的结果:当我点击获取信息时,我的鼠标就变成了等待符号 我决定尝试准确地复制这个OpenLayers示例: 我复制了源代码,并将源代码从相对更改为绝对。我让它运行-除了我有同样的问题!当我从网站上运行这个例子时,我得到了弹出窗口。当我运行我的本地版本(见下文)时,当我点击地图时,我只得到思考符号。我错过了什么 <!DOCTYPE html PU

我是Openlayers的新手,非常感谢能为WMSGetFeatureInfo提供一些帮助。我试过几个例子,每次我把它粘贴到我的代码中,我都会得到相同的结果:当我点击获取信息时,我的鼠标就变成了等待符号

我决定尝试准确地复制这个OpenLayers示例:

我复制了源代码,并将源代码从相对更改为绝对。我让它运行-除了我有同样的问题!当我从网站上运行这个例子时,我得到了弹出窗口。当我运行我的本地版本(见下文)时,当我点击地图时,我只得到思考符号。我错过了什么

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>GetFeatureInfo Popup</title>

<script src="http://openlayers.org/dev/OpenLayers.js">
</script>
<link rel="stylesheet" href="http://openlayers.org/dev/theme/default/style.css" type="text/css">
<link rel="stylesheet" href="http://openlayers.org/dev/examples/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://demo.opengeo.org/geoserver/wms", 
        {'layers': 'topp:tasmania_state_boundaries', transparent: true, format: 'image/gif'},
        {isBaseLayer: true}
    );

    var roads = new OpenLayers.Layer.WMS("Roads",
        "http://demo.opengeo.org/geoserver/wms", 
        {'layers': 'topp:tasmania_roads', transparent: true, format: 'image/gif'},
        {isBaseLayer: false}
    );

    var cities = new OpenLayers.Layer.WMS("Cities",
        "http://demo.opengeo.org/geoserver/wms", 
        {'layers': 'topp:tasmania_cities', transparent: true, format: 'image/gif'},
        {isBaseLayer: false}
    );

    var water = new OpenLayers.Layer.WMS("Bodies of Water",
        "http://demo.opengeo.org/geoserver/wms", 
        {'layers': 'topp:tasmania_water_bodies', transparent: true, format: 'image/gif'},
        {isBaseLayer: false}
    );

    var highlight = new OpenLayers.Layer.Vector("Highlighted Features", {
        displayInLayerSwitcher: false, 
        isBaseLayer: false 
    });

    map.addLayers([political, roads, cities, water, highlight]); 

    info = new OpenLayers.Control.WMSGetFeatureInfo({
        url: 'http://demo.opengeo.org/geoserver/wms', 
        title: 'Identify features by clicking',
        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">WMS, GetFeatureInfo, popup</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>

GetFeatureInfo弹出窗口
OpenLayers.ProxyHost=“proxy.cgi?url=”;
var图,信息;
函数加载(){
map=新的OpenLayers.map({
分区:“地图”,
maxExtent:new OpenLayers.Bounds(143.834,-43.648148.479,-39.573)
});
var political=new OpenLayers.Layer.WMS(“州边界”,
"http://demo.opengeo.org/geoserver/wms", 
{'layers':'topp:tasmania_state_bounders',透明:true,格式:'image/gif'},
{isBaseLayer:true}
);
var roads=新的OpenLayers.Layer.WMS(“道路”,
"http://demo.opengeo.org/geoserver/wms", 
{'layers':'topp:tasmania_roads',透明:true,格式:'image/gif'},
{isBaseLayer:false}
);
var cities=new OpenLayers.Layer.WMS(“城市”,
"http://demo.opengeo.org/geoserver/wms", 
{'layers':'topp:tasmania_cities',透明:true,格式:'image/gif'},
{isBaseLayer:false}
);
var water=新的OpenLayers.Layer.WMS(“水体”,
"http://demo.opengeo.org/geoserver/wms", 
{'layers':'topp:tasmania_water_body',透明:true,格式:'image/gif'},
{isBaseLayer:false}
);
var highlight=new OpenLayers.Layer.Vector(“突出显示的功能”{
displayInLayerSwitcher:错误,
isBaseLayer:错误
});
地图。添加图层([政治、道路、城市、水、突出显示]);
info=新建OpenLayers.Control.WMSGetFeatureInfo({
网址:'http://demo.opengeo.org/geoserver/wms', 
标题:“通过单击来识别特征”,
queryVisible:是的,
eventListeners:{
getfeatureinfo:函数(事件){
map.addPopup(新建OpenLayers.Popup.FramedCloud(
“鸡”,
map.getLonLatFromPixel(event.xy),
无效的
event.text,
无效的
真的
));
}
}
});
map.addControl(info);
info.activate();
addControl(新的OpenLayers.Control.LayerSwitcher());
zoomToMaxExtent();
}
弹出窗口中的功能信息
WMS,GetFeatureInfo,弹出窗口

演示用于从WMS(通过GetFeatureInfo请求)获取职位信息的WMSGetFeatureInfo控件。结果显示在弹出窗口中


这听起来像是跨域请求的问题。对于WMS getMap,请求的是图像,因此可以使用任何域。对于GetFeatureInfo,请求是针对XML的,因此必须针对同一域

为了解决这个问题,OpenLayers中有一个代理设置


基本上,您必须设置
OpenLayers.ProxyHost
设置以指向代理cgi脚本,OpenLayers src中提供了该脚本的示例。

我发现了我的示例的错误之处。我将脚本和链接引用从相对更改为绝对,但以下内容保持不变:

OpenLayers.ProxyHost = "proxy.cgi?url=";
当我把它改成:

OpenLayers.ProxyHost = "http://openlayers.org/dev/examples/proxy.cgi?url=";

该示例在我的电脑上运行良好。

感谢您的快速响应!我看了你发给我的链接,我正在努力理解。因此,我是否正确地理解了它没有正常运行,即使它是相同的代码,因为我试图在我的PC上运行它,这会导致跨域问题?我不明白你说的“将OpenLayers.ProxyHost设置为指向代理cgi脚本”是什么意思。这方面的例子在哪里?对不起,所有的问题-不要放弃我!