ArcGIS server for JavaScript开发实践

本文详细介绍了ArcGIS JavaScript API中的FeatureLayer类,包括其构造函数、常用属性与方法等内容,并提供了多个示例代码帮助理解如何在Web应用中使用要素图层。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   不对的地方还望博友们指正

 

要素图层类简介:
Class:FeatureLayer

//调用方式:
require(["esri/layers/FeatureLayer"],function(FeaturLayer){});

/*描述:
要素图层继承几何图层,可以用来显示地图服务中的单一图层的服务或要素服务。
要素图层可以是一个图层后者一个属性表。如果可编辑方法是true的话,要素图层中的要素可以被编辑。
注意:arcgis 和桌面中的符号尺寸使用时点,在API for JavaScript中使用的是像素。
*/
类的层级
esri/layers/Layer
  esri/layers/GraphicsLayer
     esri/layers/FeatureLayer
----------------------------------------------
子类:
CSVLayer,DataAdapterFeatureLayer,StreamLayer
-----------------------------------------------
构造函数:
new FeatureLayer(url,options?)   // 实例化对象, url为REST服务

new FeatrueLayer(featureCollectionObject,options?)//要素特征集实例化对象
-----------------------------------------------
常量:
     Name                                 描述
  MODE_AUTO                     用于缓存,减少服务器的负载
  MODE_ONDEMAND                 此种模式,要素图层可以在服务中检索我们需要的要素。
  MODE_SELECTION                在选择模式下,要素是检索服务仅选择的。此功能只在客户端可用时被选中。
  MODE_SNAPSHOT                 此模式下,要素图层检索所有相关图层资源中要素将其显示在客户端上。
  POPUP_HTML_TEXT               在弹出菜单中显示html或文本信息
  POPUP_URL                     弹出显示URL的类容
  SELECTION_ADD                 将功能添加到当前的选择集
  SELECTION_NEW                 新建一个选择
  SELECTION_SUBTRACT            从选择集中移除要素。
----------------------------------------------------------------------------------------------
常用的属性:

  Name                                            概述
  advancedQueryCapabilities      一个对象,其中包含服务水平层元数据是否支持使用统计、查询命令字段,层次分明,分页,随着距离的查询,并返回查询扩展。
  allowGeometryUpdates           返回true,如果几何特征的层可以被编辑,否则假。
  attributionDataUrl             当URL可用时图层属性将被保存
  capabilities                   支持这一图层的信息功能
  className                      图层节点的类属性
  copyright                      版权信息层
  dataAttributes                 String/String[]类型。 属性列表字段作为自定义数据属性添加到图形节点。
  defaultVisibility              显示默认图层的可见性
  displayField                   显示图层字段的属性名
  editFieldsInfo                 显示编辑字段的字段名
  fields                         图层中的字段数组
  fullExtent                     图层全部范围
  gdbVersion                     地理数据库的版本
  geometryType                   图层要素的集合类型
  graphics                       层中的要素数组
  layerId                        id要素图层
  loaded                         当图层加载,其值为true时可以访问图层属性
---------------------------------------------------------------------------------
常用的方法:
  
    Name                                                    概述      
  addAttachment(objestId,formNode,callback?,errback?)    添加一个附件ObjectId所指定的功能。
  applyEdits(adds?,updates?,Deferred deletes?,callback?,errback?)         编辑应用到功能层
  attr(name,value)                添加一个新的属性或更改现有的属性的值在层的节点上。
  clear()                         清除多有的图形
  clearSelection()                清除当前的选择
  disableMouseEvents()            禁用图形层上的所有鼠标事件。
  enableMouseEvents()             图层上的鼠标事件可用
  getAttributionData()            返回自定义图层的数据
  getDefintionExpression()        返回当前定义的表达式
  getDomain(fieldName,option?)    返回与给定字段相关联的域值
  getEditCapabilities(options?)   返回一个对象,描述的编辑功能层。
  getEditInfo(feature,options?)   返回一个对象描述最近的编辑操作上执行给定的特性,如果可用。
  getField(fieldName)             返回给定字段的名称
  getMap()                        返回的引用添加到图层的控制层
  getOrderByFields()              返回的列表字段顺序功能使用
  getSelectionSynbol()            获取当前选择的要素
  getType(feature)                返回描述描述要素 类型的 FeatureType
  
  queryCount(query,callback?,errback?) 得到一个计数的数量满足输入查询的功能。
  queryFeatures(query,callback?,errback?) 在要素图层中查询要素
  queryIds(query,callback?,errback?)      查询对象ID
  queryRelatedFeatures(relQuery,callback?,errback?) 查询功能或记录,从另一个图层或表,相关功能在这一层。
  
  redraw()                       重绘图层中多有图形
  refresh()                      刷新特征图层中的要素
  remove(graphic)                移除图像
  resume()                       重绘图层
  
  selectFeatures(query,selectionMethod?,callback?,errback?)   在要素图层中选择要素
  setEditable(editable)    FeatureLayer    Set the editability of feature layers created from a feature collection.
  setGDBVersion(versionName)    FeatureLayer                  Set the layer's data source to the specified geodatabase version.
  setInfoTemplate(infoTemplate)    None                        Specify or change the info template for a layer.
  setLabelingInfo(labelingInfo)    None                        Sets labeling info on the layer.
  setMaxAllowableOffset(offset)    None                        Sets the maximum allowable offset used when generalizing geometries.
  setMaxScale(scale)    None                                  Set the maximum scale for the layer.
  setMinScale(scale)    None                                  Set the minimum scale for the layer.
  setOpacity(opacity)    None                                  Initial opacity or transparency of layer.
  
--------------------------------------------------------------------------------- 

构造方法:
------------------------------------------------------------
new FeatureLayer(url,options?)

<string>url  :使用地图下的某一图层,必须标明
<Object>options :可选的参数,参照可选参数表

   options properties
   .....
   
Sample:
  
  require([
  "esri/InfoTemplate","esri/layers/FeatureLayer",...
  ],function(InfoTemplate,FeatureLayer,....){
      var infoTemplate=new InfoTemplate("${FIELD_NAME}",content);
      var featureLayer=new FeatureLayer("http://..../0",{
          mode:FeatureLayer.MODE_ONDEMAND,
          infoTemplate:infoTemplate,
          outFields:["*"]
      });
      ...
  });
----------------------------------------------------------------------  
  new FeatureLayer(featureCollectionObject,options?)
  
  创建一个新的实例层使用FeatureCollection对象的特性。功能层,当初始化功能集合对象有以下行为:
  这种方法可以用来访问的可序列化的表示特性,可以保存在服务器上。
  
  
Sample
  require([
  "esri/layers/FeatureLayr",...
  ],function(FeatureLayer,..){
      var layerDefinition={
          "geometryType":"esriGeometryPolygon",
          "fields":[{
              "name":"BUFF_DIST",
              "type":"esriFieldTypeInteger",
              "alias":"Buffer Distance"
          }]
      }
      var featureCollection={
          layerDefinition:layerDefinition,
          featuerSet:null
      };
      var featureLayer=new FeatureLayer(featureCollection,{
          showLabels:ture
      });
      ....
  });
-------------------------------------------------------------------
Property Details

/*一个对象,其中包含服务水平层元数据是否支持使用统计、查询命令字段,
层次分明,分页,随着距离的查询,并返回查询扩展。这个对象包含现有的
属性supportsStatistics和supportsAdvancedQueries新的supportsOrderBy属性返回的。
为了向后兼容supportsStatistics和FeatureLayer supportsAdvancedQueries仍将属性。*/
Sample

var wildfireResponsePointsFeatureLayer = new FeatureLayer(url, featureLayerOptions);
map.addLayer(wildfireResponsePointsFeatureLayer);

wildfireResponsePointsFeatureLayer.on("load", function featureLayerLoaded(event){
  console.log("advancedQueryCapabilities)",   wildfireResponsePointsFeatureLayer.advancedQueryCapabilities);
  /* Object {supportsStatistics: true, supportsOrderBy: true, supportsDistinct: true} */
});

----------------------------------------------------------------------------
id

//ID分配层。如果不指定,esri。地图分配值。
//默认情况下,层的ID是“层”后跟一个数字。身份证只能在用户定义层的构造函数。

1、在图层构造函数设置层id。添加指定id的动态图层


require([
"esri/layers/ArcGISDynamicMapServiceLayer",...
],function(ArcGISDynamicMapServiceLayer,..){
    var population=new ArcGISDynamicMapServiceLayer("http://....",{id:"population"});
    ...
});
2、设置层的ID后层初始化
population.id="population";
3、检索图层id
function getMapLayers(){
    for(var j=0;jl=map.layers.length;j<jl;j++){
        var currentLayer=map.getLayer(map.layerIds[j]);
        alert("id:"+ currentLayer.id);
    }
}

 ---------------------------------------------------------------------------
 labelingInfo
 标签信息,
 用来显示返回的信息
 Sample
 
 labelingInfo:[{
     "labelExpression":"",
     "labelExpressionInfo":{
         {"value":"City Of {CITY_NAME} has population{POPULATION}"}
     },
     "useCodedValues": ,   //参数字段属性域值时使用
     "labelPlacement":"above-right",
     "symbol":{....},      //用于标签
     "minScale":0,
     "maxScale":5000,
     //fieldInfos结构描述属性字段格式
     "fieldinfos":[
     {fieldName:"created_date", format:{dateFormat:"shortData"}},//时间或日期的格式化
     {fieldName:"last_edited_date",format:{dateFormat:"longDate"}},
     {fieldName:"eventtype",format:{places:6,digitSeparatior:ture}}//数字格式化
     ],
     "where":"POP_RAMK > AND POP_RAMK < 4"//   where 条件句用于标签上
}]

----------------------------------------------------
     
     
 
 
   
   

     


 

转载于:https://my.oschina.net/dongteng/blog/684191

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值