Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/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
Javascript OpenLayers从其他站点加载GML文件_Javascript_Openlayers_Same Origin Policy_Gml Geographic Markup Lan - Fatal编程技术网

Javascript OpenLayers从其他站点加载GML文件

Javascript OpenLayers从其他站点加载GML文件,javascript,openlayers,same-origin-policy,gml-geographic-markup-lan,Javascript,Openlayers,Same Origin Policy,Gml Geographic Markup Lan,我很难将GML文件加载到OpenLayers中。我将问题归结为以下几点: -复制/通过以下位置的示例: -将所有链接替换为绝对链接 这将产生我从localhost运行的以下文件/代码(文件://): OpenLayers向量行为示例 var映射; 函数init(){ map=newOpenLayers.map('map'); var wms=new OpenLayers.Layer.wms( “OpenLayers WMS”http://vmap0.tiles.osgeo.org/wms/vm

我很难将GML文件加载到OpenLayers中。我将问题归结为以下几点: -复制/通过以下位置的示例: -将所有链接替换为绝对链接

这将产生我从localhost运行的以下文件/代码(文件://):


OpenLayers向量行为示例
var映射;
函数init(){
map=newOpenLayers.map('map');
var wms=new OpenLayers.Layer.wms(
“OpenLayers WMS”http://vmap0.tiles.osgeo.org/wms/vmap0",
{layers:'basic'}
);
var layer=新的OpenLayers.layer.Vector(“GML”{
策略:[新建OpenLayers.Strategy.Fixed()],
协议:新OpenLayers.protocol.HTTP({
url:“http://openlayers.org/dev/examples/gml/polygon.xml",
格式:新建OpenLayers.format.GML()
})
});
map.addLayers([wms,layer]);
zoomToExtent(新的OpenLayers.Bounds(
-3.92, 44.34, 4.87, 49.55
));
}
向量行为示例(Fixed/HTTP/GML)
向量,策略,策略,协议,高级,gml,http,固定

具有固定策略、HTTP协议和GML格式的向量层。

所示的向量层使用固定策略,HTTP协议, 和GML格式。 固定策略是一种简单的策略,只获取一次功能 永远不要重新请求新数据。 HTTP协议使用HTTP谓词发出请求。应该是 使用与功能集合相对应的url构造 (某个服务器上的资源)。 GML格式用于序列化功能。
问题是GML没有显示(其他一切都很好)。我在控制台中没有错误,但请求的状态为200 OK(在FF控制台和FireBug网络选项卡中)。
我错过了什么?同源策略失败应该会显示一些错误,否?

它确实在Chrome中提供了访问控制允许源错误

无法加载XMLHttpRequest . 起源不是 允许的 访问控制允许源

对于FF,如您所述,它确实给出了200响应代码,但响应不包含任何数据


为了保护用户不受脚本向远方服务器发送信息的影响,有一项“同源策略”,规定您只能通过HTTP请求从与当前查看页面相同的服务器接收数据

这就解释了为什么wireshark拥有这些信息,而firebug没有:浏览器不允许传输这些信息

JSON-p是解决这个问题的一个技巧:


如果您无法访问JSONP源或不希望使用JSONP方法,则必须使用代理,代理将您的请求转发到远方的服务器,并返回信息,就像它来自您自己的服务器一样。浏览器将无法判断通信最终将发送到一个遥远的服务器,并将允许HTTP请求。

响应在FireBug中不包含数据,但在Wireshark中包含数据,因此我要查找FireBug中的一个错误。无论如何,非常感谢你的回答。有关于如何继续的建议吗?您可以使用代理,例如使用jsonp获取请求:**%20from%20xml%20where%20url%3D%27http%3A//openlayers.org/dev/examples/gml/polygon.xml%27I我不明白它为什么工作:yahoo服务器返回以下标题:访问控制允许原始:*
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <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>OpenLayers Vector Behavior Example</title>
        <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 src="http://openlayers.org/dev/OpenLayers.js"></script>

        <script type="text/javascript">
            var map;

            function init(){
                map = new OpenLayers.Map('map');
                var wms = new OpenLayers.Layer.WMS(
                    "OpenLayers WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0",
                    {layers: 'basic'}
                );

                var layer = new OpenLayers.Layer.Vector("GML", {
                    strategies: [new OpenLayers.Strategy.Fixed()],
                    protocol: new OpenLayers.Protocol.HTTP({
                        url: "http://openlayers.org/dev/examples/gml/polygon.xml",
                        format: new OpenLayers.Format.GML()
                    })
                });

                map.addLayers([wms, layer]);
                map.zoomToExtent(new OpenLayers.Bounds(
                    -3.92, 44.34, 4.87, 49.55
                ));
            }
        </script>
    </head>
    <body onload="init()">
        <h1 id="title">Vector Behavior Example (Fixed/HTTP/GML)</h1>
        <div id="tags">
            vector, strategy, strategies, protocoll, advanced, gml, http, fixed
        </div>
        <p id="shortdesc">

            Vector layer with a Fixed strategy, HTTP protocol, and GML format.
        </p>
        <div id="map" class="smallmap"></div>
        <div id="docs">
            The vector layer shown uses the Fixed strategy, the HTTP protocol,
            and the GML format.
            The Fixed strategy is a simple strategy that fetches features once
            and never re-requests new data.
            The HTTP protocol makes requests using HTTP verbs.  It should be
            constructed with a url that corresponds to a collection of features
            (a resource on some server).
            The GML format is used to serialize features.
        </div>
    </body>
</html>