当前位置: 首页 > news >正文

arcgis api for js 中使用API的代理页面(跨越配置)

以下仅作为自己阅读官网api的对reques的理解做的备忘笔记。一知半解,仅供参考。

1、获取或者构建第三方代理

官网解释:代理在其自己的 Web 服务器上安装并运行,而不是在 Esri 服务器或安装了 ArcGIS Enterprise 的计算机上安装和运行(除非您的 Web 服务器还托管 ArcGIS Enterprise 实例)。

个人理解:通常使用了arcgis api for js的应用项目,基本都会买arcgis产品,安装在指定服务器上(例如这里的服务器地址端口号是192.168.0.11:8001),并在此地址端口号进行服务的发布。而使用的项目不一定会安装在同一个服务器之上。即:esri服务器与应用项目服务器并不是同一个。

2、代理路径配置

官网解释:为了使应用程序通过代理路由请求,必须向应用程序添加代码,以定义代理的托管位置。如果应用程序中的所有请求都使用相同的代理,请使用请求对象的代理Url 属性指定位置。

require(["esri/config"], function(esriConfig) {esriConfig.request.proxyUrl = "/proxy/Java/proxy.jsp";
});

官网解释:还可以使用特定的代理规则配置应用程序。这些规则指示代理使用具有相同 URL 前缀的特定资源。当应用程序尝试通过此 URL 访问资源时,将通过指定的代理发送请求。请求的 proxyRules 属性是列出所有这些代理规则的对象。要填充它,请使用 urlUtils.addProxyRule()。

require(["esri/core/urlUtils"], function(urlUtils) {urlUtils.addProxyRule({urlPrefix: "http://localhost:6080",//地图服务地址前缀要请求的地址proxyUrl: "http://localhost:8080/Java/proxy.jsp"//部署的代理文件地址});
});

3、request.interceptors拦截器

允许开发人员在发送请求之前或之后修改请求。 将使用与请求 URL 匹配的第一个拦截器。

//官网示例
const featureLayerUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0";esriConfig.request.interceptors.push({// set the `urls` property to the URL of the FeatureLayer so that this// interceptor only applies to requests made to the FeatureLayer URLurls: featureLayerUrl,// use the BeforeInterceptorCallback to check if the query of the// FeatureLayer has a maxAllowableOffset property set.// if so, then set the maxAllowableOffset to 0before: function(params) {if (params.requestOptions.query.maxAllowableOffset) {params.requestOptions.query.maxAllowableOffset = 0;}},// use the AfterInterceptorCallback to check if `ssl` is set to 'true'// on the response to the request, if it's set to 'false', change// the value to 'true' before returning the responseafter: function(response) {if (!response.ssl) {response.ssl = true;}}
});//拦截,在所有服务地址头部添加需要的头部信息(放在加载地图资源之后,调用服务之前)
self.esriConfig.request.interceptors = []self.esriConfig.request.interceptors.push({before: function (params) {const A = "A"const B = "B"params.requestOptions.headers = {A: A,B: B}}});

http://www.lryc.cn/news/261318.html

相关文章:

  • Unity_FairyGUI发布导入Unity编辑器资源报错
  • 1.5【应用开发】缓冲区(二)
  • RTMP流设置超时时间失败
  • 如何一步步让MySQL支撑亿级流量
  • MFC CLXHHandleEngine动态库-自定义设置对话框使用
  • Python生成器(Generator)(继续更新...)
  • Spring Boot 3 整合 Mybatis-Plus 动态数据源实现多数据源切换
  • 快速学习C++中的模板
  • Pandas-DataFtame的索引与切片(第3讲)
  • MySQL低版本中:字符串中的数字、英文字符、汉字提取
  • 多窗口文件管理工具Q-Dir安装以及使用教程
  • Spring入门
  • Linux——进程创建与进程终止
  • 轻量封装WebGPU渲染系统示例<50>- Json数据描述材质等场景信息
  • AtCoder ABC周赛2023 12/10 (Sun) D题题解
  • 基于C/C++的rapidxml加载xml大文件 - 上部分翻译
  • 小程序使用Nodejs作为服务端,Nodejs与与MYSQL数据库相连
  • 深度解读 Cascades 查询优化器
  • Bash 操作审计和安全加固 —— 筑梦之路
  • C/C++常见面试知识总结(三)
  • AR眼镜_AR智能眼镜整机硬件方案定制
  • 2. 皇后的控制力
  • 南京邮电大学数据库实验二
  • 数据库 02-03 补充 SQL的子查询(where,from),子查询作为集合来比较some,exists,all(某一个,存在,所有)
  • 提升英语学习效率,尽在Eudic欧路词典 for Mac
  • 计算机网络英文总结
  • Spring上下文之注解模块ConfigurationMethod
  • 【深度学习】强化学习(三)强化学习的目标函数
  • Python高级算法——人工神经网络(Artificial Neural Network)
  • 深入理解JVM设计的精髓与独特之处