固定策略:它可以处理协议错误吗?

时间:2011-10-04 23:31:43

标签: openlayers

OpenLayers的默认策略是固定的。例如见:

http://openlayers.org/dev/examples/sundials.html

var sundials = new OpenLayers.Layer.Vector("KML", {
            projection: map.displayProjection,
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.HTTP({
                url: "kml/sundials.kml",
                format: new OpenLayers.Format.KML({
                    extractStyles: true,
                    extractAttributes: true
                })
            })
        });

是否可以传递回调来处理协议错误? 如果我使用低级GET请求,我可以很容易地做到这一点,例如:

var loadkml = function() {
      OpenLayers.Request.GET({
          url: "kml/sundials.kml",
          success: parseData,
          failure: function(req) { alert(req.responseText); }
      });
  }

但我不想实施一个全新的策略,固定没问题。

1 个答案:

答案 0 :(得分:2)

OpenLayers.Protocol.HTTP协议接受callback个选项:

Function to be called when the <read>, <create>, <update>, <delete> or <commit> operation completes

但该函数永远不会被调用,bug报告:https://github.com/openlayers/openlayers/pull/81