ArcGIS API for Javascript proxy的配置
来源:互联网 发布:网络ip电话怎么打 编辑:程序博客网 时间:2024/05/22 15:40
为什么要使用代理proxy?
答:未配置代理时server发送请求是用get的方式,请求跨域访问或者URL长度超过浏览器限制时,这就需要一个代理文件proxy来转发请求。Arcgis Server 10.0 由于不支持CORS,需要配置代理才能在前端js 程序中范围进行操作,而有时候未配置代理也未出错,例如:用extent进行空间查询 后不报错是因为选择extent 请求的参数字符串较短,jsapi 可以通过jsonp方法绕过跨域限制,但是一旦前端参数较多,例如用circle进行空间查询,可以就无法通过jsonp跨域,这个时候如果要使用 10.0的 Identify task 就必须配置代理;还有Arcgis Server 10.2的打印功能可能也需要配置代理才行。
下载地址:https://github.com/Esri/resource-proxy/releases(注意:不同版本的Arcgis Server应下载对应版本的proxy文件,而该页面中的V1.1.0版本其实是支持10.2和10.3版本的,V1.0版本支持10.0版本,下载后解压可以看到有3中类型:DotNet、Java、PHP的代理proxy文件,此处以Java为例)
修改文件:
V1.1.0版本:该文件下载下来后需要修改proxy.jsp内容,全局搜索“<>”将对应的类型写入,例如:文件中有HashMap<>,未写类型,可能就需要修改为HashMap<String,String>;还需要修改文件“WEB-INF/classes/proxy.config”文件中的“serverUrl”标签的url属性,修改为要调用Arcgis Server的地址,例如:“http://192.168.202.143:9797/arcgis/rest/services”)
(备注:若有多个不同域的服务地址,则需配置多个不同域的服务地址)
V1.0版本:不需要修改proxy.jsp内容,但该版本也需要修改 “WEB-INF/Classes/proxy.config”文件,修改同V1.1.0版本一致。
如何部署?
修改完成后,将“Java"整个文件拷贝到Tomcat的webapps文件下,启动Tomcat。
如何测试是否成功?
访问:http:// 192.168.0.207:9391/Java/proxy.jsp?ping,会看到:
{ "ProxyVersion": "1.1.0", "Configuration File":"OK", "Log File": "OK"},然后再访问:http:// 192.168.0.207:9391/Java/proxy.jsp?http://192.168.202.143:9797/arcgis/rest/services/?f=pjson,如果看到指定Arcgis Server目录下的json数据,如
{"currentVersion":10.21,"folders":["Utilities","XKMSLFH"],"services":[{"name":"DOM2013","type":"ImageServer"}]},则到目前为止,代理配置成功!
如何在项目中使用?
Inorder for your application to route requests through the proxy you must addcode to your application to define the location of the proxy. If all requestsin your application will use the same proxy you can specify the proxy locationusing proxyUrl. You can also specify whether or not the proxy should always beused for communication using alwaysUseProxy
下面2行代码必须在项目中出现才能使该项目使用代理:
esri.config.defaults.io.proxyUrl= "http://192.168.0.207:9391/Java/proxy.jsp";
esri.config.defaults.io.alwaysUseProxy= false;
In the code above,esriConfig refers to the object returned by the esri/config module.
Another option isto setup a proxy rule that defines the proxy for a set of resources with the sameURL prefix. If the request URL matches a rule, then the request will be routedthrough the proxy. To define a proxy rule specify the url for the proxy and theprefix for the resources that need to be accessed through the proxy.
下面的代码可不用出现在项目中,不知道具体有什么影响:
esri.urlUtils.addProxyRule({
urlPrefix:"route.arcgis.com",
proxyUrl:"http://192.168.0.207:9391/Java/proxy.jsp"
});
代理的配置帮助参考:https://developers.arcgis.com/javascript/jshelp/ags_proxy.html
好像下面这2个地址说的配置方式都有点复杂【10.0版本server配置代理:
http://help.arcgis.com/zh-cn/arcgisserver/10.0/help/arcgis_server_dotnet_help/index.html#//00930000009q000000
10.2版本server配置代理:
http://resources.arcgis.com/zh-cn/help/main/10.2/index.html#/Using_a_forward_proxy_server_with_ArcGIS_Server/015400000309000000/】
- ArcGIS API for Javascript proxy的配置
- 对于ArcGIS API for Javascript的配置
- arcgis api for javascript中使用proxy.jsp
- arcgis api for javascript中使用proxy.jsp
- ArcGIS API for JavaScript 初始化配置路径
- ArcGIS API for JavaScript
- ArcGIS API for JavaScript的服务查询
- ArcGIS API For Javascript之服务端配置与应用
- ArcGIS API for JavaScript 4.5安装配置及测试
- arcgis api for JavaScript相关
- arcgis api for JavaScript相关
- ArcGIS API for Javascript热区图
- ArcGIS API for Javascript介绍
- ArcGIS API for JavaScript是什么
- ArcGIS API For JavaScript部署
- Win10下Arcgis api for javascript的本地服务器(IIS)配置
- ArcGIS API for JavaScript获取和配置-ArcGIS Web 开发学习(一)
- ArcGIS Api for javascript实现的拉框查询
- Android开发笔记(一百四十一)读取PPT和PDF文件
- java+mysql实现保存图片到数据库,以及读取数据库存储的图片
- Maven 命令参数 整理
- maven -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environmet
- JSON:(JavaScript 对象表示法)
- ArcGIS API for Javascript proxy的配置
- Flink Basic API Concepts 学习笔记&译文
- mysql跳过 drop语句利用xtrabackup进行恢复
- 腾讯Android客户端开发面试总结
- javaWeb开发之控制层框架Struts2入门知识点总结
- 安装Eclipse插件详解
- Mybatis错误:Parameter 'XXX' not found. Available parameters are [1, 0, param1, param2]
- Implementing a CNN for Text Classification in TensorFlow(用tensorflow实现CNN文本分类) 阅读笔记
- 判断是否是数字