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

ArcGIS API For JS官方文档解析目录

    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("servicesbeta.esri.com");
  esriConfig.defaults.io.corsEnabledServers.push("server.organization.com");
});

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

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

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

"www.arcgis.com",
"tiles.arcgis.com",
"services.arcgis.com"

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

"static.arcgis.com",
"utility.arcgisonline.com",
"geocode.arcgis.com"

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

"services1.arcgis.com",
"services2.arcgis.com",
"services3.arcgis.com"

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

"geoenrich.arcgis.com

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

"basemaps.arcgis.com"

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

"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
  }
};

转载自:https://blog.csdn.net/qq_35732147/article/details/79864698

You may also like...