<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>ArcGIS 切片服务示例</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
<script src="https://js.arcgis.com/4.20/"></script>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/TileLayer",
"esri/config",
], function(Map, MapView, TileLayer,esriConfig) {
// 创建地图对象
var map = new Map();
// 创建切片图层对象-需要替换的地址-换成给你的服务地址
var tileLayer = new TileLayer({
url: "https://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer",
});
esriConfig.request.interceptors.push({
urls: tileLayer.url,
before: function (params) {
// 请求头
params.requestOptions.headers = {
// "Authorization": "xxxxx"
};
// 请求体
params.requestOptions.query['xxxx'] = 'xxx';
params.requestOptions.query['xxxx'] = 'xxxx';
}
})
// 将切片图层添加到地图
map.add(tileLayer);
// 创建地图视图对象
var view = new MapView({
container: "viewDiv",
map: map,
center: [0, 0], // 设置地图中心点
zoom: 2 // 设置初始缩放级别
});
});
</script>
</head>
<body>
<div id="viewDiv">
</div>
</body>
</html>
arcgis api服务添加请求头以及请求体
于 2023-08-28 15:54:56 首次发布