0

GML ファイルを OpenLayers にロードするのに問題があります。問題を次のように取り除きました: - 例をコピーして貼り付けます: http://openlayers.org/dev/examples/behavior-fixed-http-gml.html - すべてのリンクを絶対リンクに置き換えます

これにより、localhost (file:///) から実行した次のファイル/コードが生成されます。

<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>

問題は、GML が表示されないことです (他のすべては問題なく動作します)。コンソールにエラーはありませんが、リクエストのステータスは 200 OK です (FF コンソールと FireBug Network タブの両方で)。私は何が欠けていますか?同一オリジン ポリシーの失敗は何らかのエラーを表示するはずですよね?

4

2 に答える 2

1

ChromeではAccess-Control-Allow-Originエラーが発生します。

XMLHttpRequestは http://openlayers.org/dev/examples/gml/polygon.xmlをロードできません。Origin http://fiddle.jshell.netは、Access-Control-Allow-Originでは許可されていません。

FFの場合、あなたが述べたように200の応答コードが返されますが、応答にはデータが含まれていません。

http://jsfiddle.net/niklasvh/F76Hp/3/

于 2011-05-30T21:43:02.153 に答える
0

遠く離れたサーバーに情報を送信するスクリプトからユーザーを保護するために、現在表示しているページと同じサーバーからの HTTP 要求を介してのみデータを受信できることを示す "same origin policy" があります。

これは、wireshark に情報があり、firebug にはない理由を説明しています。ブラウザは情報の転送を許可していません。

JSON-P は、これを回避するためのトリックです。

http://en.wikipedia.org/wiki/JSONP

JSONP ソースにアクセスできない場合、または JSONP アプローチを使用したくない場合は、プロキシを使用する必要があります。プロキシは、リクエストを遠く離れたサーバーに転送し、自分のサーバーから来たかのように情報を返します。ブラウザーは、通信が最終的に遠く離れたサーバーに送信されることを認識できず、HTTP 要求を許可します。

于 2011-08-16T09:17:15.540 に答える