我可以将请求作为 imageArcgisRest 的 post 请求发送吗?公开赛 6.5

can i send request as post request for imageArcgisRest | OPENLAYERS 6.5

我正在使用 imageArcgisRest 源,我需要在导出层 API 中按 id 过滤数据,id 可以以千为单位。所以得到一个请求是不可能做到的。有什么方法可以使用 OpenLayers imageArcGisRest 源作为 post 方法请求数据?

这是我创建源码的代码:

const source = new ImageArcGISRest({
    url: l.url,
    crossOrigin: 'anonymous',
    params: {
      dpi: 96,
      FORMAT: 'PNG8',
      layers: `show: 1`,
      token: 'api-token-here'
    },
  });

此设置适用于简单测试(使用测试浏览器,因为示例服务器不支持 CORS)以过滤 OpenLayers 示例中的高速公路 https://openlayers.org/en/latest/examples/arcgis-image.html

var url =
  "https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
  "Specialty/ESRI_StateCityHighway_USA/MapServer";

var filter = {
  "0": "(TOLL_RD = 'N') AND (TYPE LIKE 'Paved%' OR TYPE LIKE 'Gravel%')"
};

var layers = [
  new TileLayer({
    source: new OSM()
  }),
  new ImageLayer({
    source: new ImageArcGISRest({
      ratio: 1,
      params: {
        layerDefs: JSON.stringify(filter)
      },
      url: url,
      imageLoadFunction: function (image, src) {
        var xhr = new XMLHttpRequest();
        xhr.responseType = "blob";
        xhr.addEventListener("loadend", function (evt) {
          var data = this.response;
          if (data) {
            var img = image.getImage();
            var url = URL.createObjectURL(data);
            img.addEventListener("loadend", function () {
              URL.revokeObjectURL(url);
            });
            img.src = url;
          }
        });
        var split = src.split("?");
        xhr.open("POST", split[0]);
        xhr.setRequestHeader(
          "Content-type",
          "application/x-www-form-urlencoded"
        );
        xhr.send(split[1]);
      }
    })
  })
];

过滤器可以使用

动态更新
source.updateparams({layerDefs: JSON.stringify(filter)});