ArcGIS API For JavaScript官方文档(一)之默认API配置

简介: ArcGIS API For JavaScript官方文档(一)之默认API配置

ArcGIS Javascript API有可以被覆盖的默认选项,所有配置选项的默认值都存储在esri/config模块中。要修改默认值,需要加载该模块,将其命名为esriConfig并将该对象上的属性更新为所需的值。

require(["esri/config"], function(esriConfig) {
// update esriConfig properties here to override defaults
});


一个常见的更改是修改用于地图缩放框的符号。在下面的代码中,创建了一个新符号,并将其转换成JSON对象,然后设置为地图的默认缩放符号。

// AMD
require([
"esri/config",
"esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol", "dojo/_base/Color"
], function(
esriConfig,
SimpleFillSymbol, SimpleLineSymbol, Color
) {
var lineColor = new Color([0,0,255]);
var fillColor = new Color([255,255,0,0.5]);
var zoomSymbol = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT, lineColor, 2),
fillColor
);
esriConfig.defaults.map.zoomSymbol = zoomSymbol.toJson();
});
// legacy
var zoomSymbol = new esri.symbol.SimpleFillSymbol(
esri.symbol.SimpleFillSymbol.STYLE_SOLID,
new esri.symbol.SimpleLineSymbol(
esri.symbol.SimpleLineSymbol.STYLE_DASHDOT,
new dojo.Color([0,0,255]),
2
),
new dojo.Color([255,255,0,0.5]));
esri.config.defaults.map.zoomSymbol = zoomSymbol.toJson();


下面是JavaScript API的配置属性名称和默认值:

①esriConfig.defaults.geometryService

指定小部件和操作使用的默认几何服务

esriConfig.defaults.geometryService = new GeometryService("http://yourdomain.com/geometryService");


②esriConfig.defaults.io.alwaysUseProxy

是否始终使用代理与REST端点通信

esriConfig.defaults.io.alwaysUseProxy = true;

默认值:false

参照其他:使用代理页面


③esriConfig.defaults.io.corsDetection

是否检测服务器对跨域资源共享(cross-origin resource sharing CORS)的支持,将其设置为false将阻止API发送请求,导致浏览器开发工具中报错信息:"XMLHttpRequest无法加载http://some.url.com/ArcGIS/rest/info?f=json. Origin http://yourapp.com is not allowed by Access-Control-Allow-Origin."。但是,如果没有将资源显示添加esriConfig.defaults.io.corsEnabledServers,则API也将无法发现资源支持CORS。

默认值:true


④esriConfig.defaults.io.corsDetectionTimeout

在CORS检测期间等待来自ArcGIS Server响应的秒数。如果检测到在此时间到期之前尚未收到响应,则假设服务器不支持CORS。

默认值:15


⑤esriConfig.defaults.io.corsEnabledServers

为需要进行跨域资源共享的服务器添加URL。跨域资源共享(CORS)允许web应用程序绕过浏览器相同的原始策略文件,并访问不同服务器/域上的资源或服务,当web服务器和浏览器支持CORS时,特别是esri.request将不使用代理来执行跨域请求。API默认包括一些Esri服务器,因此重要的是将项推到这个数组上而不是覆盖它。

require(["esri/config"], function(esriConfig) {
esriConfig.defaults.io.corsEnabledServers.push("http://servicesbeta.esri.com");
esriConfig.defaults.io.corsEnabledServers.push("http://server.organization.com");
});


在3.14版本中,添加了对发送带有凭证的AJAX请求的支持。corsEnabledServers现在可以包含具有hostwithCredentials属性的对象。

require(["esri/config"], function(esriConfig) {
esriConfig.defaults.io.corsEnabledServers.push({
host: "http://server.organization.com",
withCredentials: true
})
});


在2.8版中,默认情况下,列表包含以下服务器:

  1. "http://www.arcgis.com",
  2. "http://tiles.arcgis.com",
  3. "http://services.arcgis.com"

在3.1版中,将下列域添加到列表中:

  1. "http://static.arcgis.com",
  2. "http://utility.arcgisonline.com",
  3. "http://geocode.arcgis.com"

在3.3版中,将下列域添加到列表中:

  1. "http://services1.arcgis.com",
  2. "http://services2.arcgis.com",
  3. "http://services3.arcgis.com"

在3.6版中,将下列域添加到列表中:

"http://geoenrich.arcgis.com

在3.15版中,将下列域添加到列表中:

"http://basemaps.arcgis.com"

在3.21版中,将下列域添加到列表中:

"http://utility.arcgis.com"


指定的Web服务器必须预先配置以支持CORS。浏览enable-cors.org,了解如何为流行的Web服务器启用CORS。


⑥esriConfig.defaults.io.httpsDomains

支持https的已知域后缀列表。当应用程序不在http上运行时,这将自动升级对此类域的请求,以使用https而不是http。注意,端口号不应包含在匹配的域后缀中。

从3.19版开始,默认情况下包含以下域后缀:

https://enable-cors.org/


⑦esriConfig.defaults.io.proxyRules

proxy rule(代理规则)定义了具有相同url前缀的资源集的代理。当使用esri/request时,如果目标URL与规则匹配,则请求将发送到指定的代理。与其填充该数组,不如使用API的addProxyRule方法,规则对象具有以下属性:

  • proxyUrl:关于代理的URL
  • urlPrefix:用于需要通过特定代理访问的资源的URL前缀。


⑧esriConfig.defaults.io.proxyUrl

将大型有效载荷发送到终端时应该使用的代理URL的位置。这必须驻留在于HTML应用程序相同的域上。

esriConfig.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";

默认值:null

查看其他:使用代理页面


⑨esriConfig.defaults.io.timeout

每个通过esri.Request的请求都允许响应长达60000毫秒(即60秒)。如果没有返回响应或返回服务器端错误,则按照这个顺序调用esri.Error和error back处理程序。

默认值:60000毫秒


⑩esriConfig.defaults.io.useCors

通过esri/request发出的请求是否应该尝试使用CORS。如果是true的话,直接向支持CORS的服务器发出AJAX请求。如果使用"with-credentials",在适当的地方设置withCredentials标志。最后,如果是false,不会直接请求,如果代理可用的话,将使用代理。

默认值:"with-credentials"


11esriConfig.defaults.kmlService

这是由KMLLayer使用的,这是kml utility service的URL,而不是由ArcGIS.com托管的服务。(需要Portal for ArcGIS)

esriConfig.defaults.kmlService = "http://servername.domain.suffix/arcgis/sharing/kml";

默认值:null


12、esriConfig.defaults.geoRSSService

这是GeoRSSLayer使用的,是geoRSS utility service的URL,而不是由ArcGIS.com托管的。(需要Portal for ArcGIS)

esriConfig.defaults.geoRSSService = "http://servername.domain.suffix/arcgis/sharing/rss";

默认值:null


13、esriConfig.defaults.map.basemaps

这个对象在API的3.12版中被移除,使用esri/basemaps代替。


14、esriConfig.defaults.map.panDuration

地图从一个extent(范围)到另一个extent经历的时间长度,以毫秒为单位。

默认值:350

示例:Customize pan animation


15、esriConfig.defaults.map.panRate

地图平移到下一个extent的刷新时间,以毫秒为单位

默认值:25

示例:Customize pan animation


16、esriConfig.defaults.map.slider

定义slider(滑块)位置、大小和方向的参数

在版本3.3中,推荐的方法是使用CSS和map构造函数选项的组合来定制地图的slider或zoom按钮。

默认值:{left: "30px", top: "30px", width: null, height: "200px"}

示例:Change slider orientation


17、esriConfig.defaults.map.sliderLabel

定义slider刻度和伴随刻度的标签,如果这是null,那么slider将不会显示刻度线。

再版本3.3中,推荐的方法是使用CSS和构造函数选项的组合来定制地图的slider或zoom按钮

默认值:{tick:5,labels:null,style:"width:2em; font-family:Verdana; font-size:75%;"}

示例:Add labels to slider


18、esriConfig.defaults.map.zoomDuration

地图从一个extent缩放到另一extent经过的时间,单位为毫秒

默认值:500

示例:Customize zoom animation


19、esriConfig.defaults.map.zoomRate

地图缩放到下一个extent刷新的时间,单位为毫秒

默认值:25

示例:Customize zoom animation


20、esriConfig.defaults.map.zoomSymbol

使用SimpleFillSymbol表现RubberBand zoom的color、fill、outline特征,这是SimpleFillSymbol的JSON表现形式。

默认值:{color:[0,0,0,64],outline:{color:[255,0,0,255],width:1.5,style:"esriSLSSolid"},style:"esriSFSSolid"}

示例:Customize zoom box


21、esriConfig.defaults.workers.loaderConfig

修改配置,以指定工作人员加载包的位置,或者定义特征检测(截至3.20版)

esriConfig.defaults.workers.loaderConfig = {
paths: {
dojo: "https://ajax.googleapis.com/ajax/libs/dojo/1.11.2/dojo/"
},
packages: [{
name: "primes",
location: window.location.href.replace(/\/[^/]+$/, "/lib"),
main: "primes"
}],
has: {
"dojo-debug-messages": true
}
};


相关文章
|
10天前
|
JavaScript
Nest.js 实战 (十一):配置热重载 HMR 给服务提提速
这篇文章介绍了Nest.js服务在应用程序引导过程中,TypeScript编译对效率的影响,以及如何通过使用webpackHMR来降低应用实例化的时间。文章包含具体教程,指导读者如何在项目中安装依赖包,并在根目录下新增webpack配置文件webpack-hmr.config.js来调整HMR相关的配置。最后,文章总结了如何通过自定义webpack配置来更好地控制HMR行为。
|
14天前
|
移动开发 JavaScript 前端开发
UniApp H5 跨域代理配置并使用(配置manifest.json、vue.config.js)
这篇文章介绍了在UniApp H5项目中处理跨域问题的两种方法:通过修改manifest.json文件配置h5设置,或在项目根目录创建vue.config.js文件进行代理配置,并提供了具体的配置代码示例。
UniApp H5 跨域代理配置并使用(配置manifest.json、vue.config.js)
|
22天前
|
JSON 前端开发 JavaScript
vue.config.js配置详解
【8月更文挑战第16天】vue.config.js配置详解
25 1
vue.config.js配置详解
|
1月前
|
JavaScript 前端开发
js之DOM 文档对象模型
js之DOM 文档对象模型
12 1
js之DOM 文档对象模型
|
18天前
|
前端开发 API 网络架构
【Azure 应用服务】能否通过 Authentication 模块配置 Azure AD 保护 API 应用?
【Azure 应用服务】能否通过 Authentication 模块配置 Azure AD 保护 API 应用?
|
18天前
|
安全 API 网络安全
【Azure API 管理】APIM如何配置客户端证书的CRL检测策略
【Azure API 管理】APIM如何配置客户端证书的CRL检测策略
|
26天前
|
Java API 数据中心
百炼平台Java 集成API上传文档到数据中心并添加索引
本文主要演示阿里云百炼产品,如何通过API实现数据中心文档的上传和索引的添加。
|
18天前
|
JSON 算法 API
【Azure API 管理】APIM 配置Validate-JWT策略,验证RS256非对称(公钥/私钥)加密的Token
【Azure API 管理】APIM 配置Validate-JWT策略,验证RS256非对称(公钥/私钥)加密的Token
|
18天前
|
API
【Azure 环境】在Azure活动目录中的应用注册,给应用添加API权限时发现API权限配置缺失
【Azure 环境】在Azure活动目录中的应用注册,给应用添加API权限时发现API权限配置缺失
|
19天前
|
前端开发 API
【API管理 APIM】APIM中如何配置使用URL路径的方式传递参数(如由test.htm?name=xxx 变为test\xxx)
【API管理 APIM】APIM中如何配置使用URL路径的方式传递参数(如由test.htm?name=xxx 变为test\xxx)