FeatureTemplatesViewModel

AMD: require(["geoscene/widgets/FeatureTemplates/FeatureTemplatesViewModel"], (FeatureTemplatesVM) => { /* 代码 */ });
ESM: import FeatureTemplatesVM from "@geoscene/core/widgets/FeatureTemplates/FeatureTemplatesViewModel";
类: geoscene/widgets/FeatureTemplates/FeatureTemplatesViewModel
继承于: FeatureTemplatesViewModel Accessor
起始版本: GeoScene API for JavaScript 4.22

为 FeatureTemplates 微件提供逻辑。

示例:
示例代码:
const templatesVM = new FeatureTemplatesViewModel({
  layers: layers
});

const featureTemplates = new FeatureTemplates({
  viewModel: templatesVM
  container: "templatesDiv"
});

构造函数

new FeatureTemplatesViewModel(properties)
参数:
properties Object
optional

所有可传入构造函数的属性,请参见属性列表

属性列表

可以设置、检索或监听的属性。参见 使用属性
展示继承属性 隐藏继承属性
属性 类型 描述
String更多信息

类名。

更多信息Accessor
FilterFunction更多信息

Function 可以定义来帮助过滤模板项微件。

更多信息FeatureTemplatesViewModel
String|GroupByFunction更多信息

可以对模板项进行分组。

更多信息FeatureTemplatesViewModel
TemplateItem[]|TemplateItemGroup[]更多信息

模板项或分组的模板项。

更多信息FeatureTemplatesViewModel
FeatureLayer[]更多信息

与微件关联的 Featurelayers 数组。

更多信息FeatureTemplatesViewModel
String更多信息

微件的状态。

更多信息FeatureTemplatesViewModel

属性详细说明

declaredClass Stringreadonly inherited

类名。类的名称声明格式为 geoscene.folder.className

filterFunction FilterFunction

Function 可以定义来帮助过滤模板项微件。搜索模板时可以使用自定义函数来帮助。它接受一个函数,该函数传入一个包含模板项name 属性的对象。

featureTemplatesFilterFunction

示例代码:
// Filter and display templates only if their names contain the word `Street`
function myFilterFunction(filter) {
  let containsName = filter.label.includes("Street");
  return containsName;
}

// Create the FeatureTemplates widget
const templates = new FeatureTemplates({
  container: "templatesDiv",
  visibleElements = {
    filter: false // does not display the default feature templates filter
  },
  layers: [featureLayer], // in this example, one layer is used
  filterFunction: myFilterFunction
});

可以对模板项进行分组。这可以帮助管理各种模板项以及它们在小部件中的显示方式。以下讨论这些值。

类型 描述 示例
layer 这是 默认 分组。按层对模板项进行分组。 featureTemplatesGroupByLayer
geometry 按几何类型对模板项进行分组。 FeatureTemplatesGroupByGeometry
none 该微件在一个列表中显示所有内容,没有分组。 featureTemplatesGroupByLayer
GroupByFunction 采用包含 FeatureTemplateFeatureLayer 的对象的自定义函数。 FeatureTemplatesGroupByCustomGroupFunction
默认值:layer
示例代码:
// This example shows using a function to check if
// the layer title contains the word 'military'. If so,
// return a group of items called "All Military Templates"
function customGroup(grouping) {
  // Consolidate all military layers
  if (grouping.layer.title.toLowerCase().indexOf("military") > -1) {
    return "All Military Templates"
  }
// Otherwise, group by layer title
  return grouping.layer.title;
}

// Create the FeatureTemplates widget
templates = new FeatureTemplates({
  container: "templatesDiv",
  layers: layers,
  groupBy: customGroup
});

模板项或分组的模板项。

与微件关联的 Featurelayers 数组。这些层在数组中的设置顺序决定了它们在微件中的显示方式。

该微件旨在仅显示启用编辑的图层。它不会显示启用仅编辑属性的图层。

示例代码:
// The layers to display within the widget
let militaryUnits = new FeatureLayer({
  url: "http://sampleserver6.geosceneonline.cn/arcgis/rest/services/Military/FeatureServer/2"
});

let militaryHostile = new FeatureLayer({
  url: "http://sampleserver6.geosceneonline.cn/arcgis/rest/services/Military/FeatureServer/6"
});

let layers = [militaryUnits, militaryHostile];

// Create FeatureTemplates widget
templates = new FeatureTemplates({
  container: "templatesDiv",
  layers: layers
});
state Stringreadonly

微件的状态。可能的值在下表中。

描述
ready 满足依赖关系并具有有效的属性值。
loading 图层仍在加载中,尚未准备好。
disabled 没有可加载的图层。

可选值:"ready"|"loading"|"disabled"

默认值:disabled

方法列表

属性 返回值类型 描述
Boolean更多信息

在实例上触发事件。

更多信息FeatureTemplatesViewModel
Boolean更多信息

指示实例上是否存在与提供的事件名称匹配的事件侦听器。

更多信息FeatureTemplatesViewModel
Object更多信息

在实例上注册事件处理程序。

更多信息FeatureTemplatesViewModel
更多信息

此方法使用提供的过滤器更新模板项

更多信息FeatureTemplatesViewModel
更多信息

选择要使用的模板项

更多信息FeatureTemplatesViewModel

方法详细说明

emit(type, event){Boolean}

在实例上触发事件。仅当创建此类的子类时才应使用此方法。

参数:
type String

事件名称

event Object
optional

事件负载。

返回值:
类型 描述
Boolean 如果侦听器收到通知,则为true 
hasEventListener(type){Boolean}

指示实例上是否存在与提供的事件名称匹配的事件侦听器。

参数:
type String

事件名称

返回值:
类型 描述
Boolean 如果类支持输入事件,则返回 true。
on(type, listener){Object}

在实例上注册事件处理程序。调用此方法将事件与侦听器挂钩

参数:

要监听的 event 或者事件数组

listener Function

事件触发时要调用的函数

返回值:
类型 描述
Object 返回一个remove() 方法的事件处理程序,该方法用以停止侦听事件。
属性 类型 描述
remove Function 当被调用时,从事件中移除监听器。
示例代码:
view.on("click", function(event){
  // event是事件触发后返回的事件句柄。
  console.log(event.mapPoint);
});
refresh()

此方法使用提供的过滤器更新模板项

select(item)

选择要使用的模板项

参数:
optional

要选择的模板项

示例:

Event Overview

属性 类型 描述
{item: TemplateItem,template: FeatureTemplate}
更多信息

选择模板项时触发。

更多信息 FeatureTemplatesViewModel

Event Details

select

选择模板项时触发。这发生在调用 select 方法时。

属性:

选定的模板项。

template FeatureTemplate

与模板项关联的要素模板。

示例:
示例代码:
// Listen for when a template item is selected
templatesVM.on("select", function(evtTemplate) {
  // Access the selected template item's attributes
  attributes = evtTemplate.template.prototype.attributes;

  // Create a new feature with the selected template at cursor location
  const handler = view.on("click", function(event) {
    handler.remove(); // remove click event handler.
    event.stopPropagation(); // stop click event propagation

    if (event.mapPoint) {
      // Create a new feature with the selected template item.
      editFeature = new Graphic({
        geometry: event.mapPoint,
          attributes: {
            "IncidentType": attributes.IncidentType
          }
      });

      // Setup the applyEdits parameter with adds.
      const edits = {
        addFeatures: [editFeature]
      };
      featureLayer.applyEdits(params).then(function(editsResult) {
        if (editsResult.addFeatureResults.length > 0) {
          console.log("Created a new feature.")
        }
      });
    }
  });
});

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.