arcgis for js 4.11加载server地图不出来出现The 'Access-Control-Allow-Origin' header has a value 'null'错误

arcgis for js 4.11加载server地图不出来出现The ‘Access-Control-Allow-Origin’ header has a value 'null’错误

这几天一直在弄arcgis for js加载server服务这块,试了3.28、4.3/4.11这几个版本,在上一篇文章中使用前两个版本都以加载成功,但4.11使用同样方法却迟迟加载不出来,google了半天才发现是图层的问题,在4.11的API中有下面这么一段话,

A Collection of Sublayer objects that allow you to alter the properties of one or more sublayers of the MapImageLayer. If this property is not specified, all the sublayers from the service are displayed as defined in the service. If an empty array is passed to this property then none of the sublayers from the service are displayed in the layer.

All sublayers are referenced in the order in which they are drawn in the view (bottom to top). They may be added, removed, or reordered using the Collection methods. Because Sublayer extends Accessor, its properties may be watched.

大意就是要指定一下sublayer的id, 如果将空数组传递给此属性,则该服务中的所有子层都不会显示在该层中。其实我也不太清楚,我只是个代码搬运工。。所以如代码所示solve it!

errror图片

// Only includes the first sublayer from the map service
var layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [{/*这里一定要加上,否则加载不出来,在其他两个版本则不会有这个bug
    id: 0
  }]
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值