CustomContent

AMD: require(["geoscene/popup/content/CustomContent"], (CustomContent) => { /* code goes here */ });
ESM: import CustomContent from "@geoscene/core/popup/content/CustomContent.js";
类: geoscene/popup/content/CustomContent
继承于:CustomContent Content Accessor
起始版本:GeoScene Maps SDK for JavaScript 4.16

CustomContent 弹窗元素用于提供一种自定义 popup 内容的方法。这些内容可以是元素的组合,例如元素 StringHTMLElementWidgetPromise

另请参阅
示例
// Create the custom content for the CustomContent popup element
// Creates some custom content
let customContentWidget = new CustomContent({
  outFields: ["*"],
  creator: (event) => {
    // creator function returns either string, HTMLElement, Widget, or Promise
  }
});

构造函数

new CustomContent(properties)
参数
properties Object
optional

有关可能传递给构造函数的所有属性的列表,请参见属性

属性概述

所有属性都可以设置、获取和监听。请参阅使用属性主题。
显示继承属性 隐藏继承属性
名称 类型 描述
PopupTemplateContentCreator

为创建自定义内容元素而调用的函数。

更多详情
CustomContent
String

类的名称。

更多详情
Accessor
PopupTemplateContentDestroyer

不再需要时清理自定义内容的调用函数。

更多详情
CustomContent
String[]

PopupTemplate 中使用的字段名称数组。

更多详情
CustomContent
String

显示的弹出元素的类型。

更多详情
CustomContent

属性详细信息

为创建自定义内容元素而调用的函数。确保 outFields 在此自定义内容中指定。

另请参阅
示例
// This custom content contains a widget
let customContentWidget = new CustomContent({
  outFields: ["*"],
  creator: () => {
    home = new Home({
      view: view
    });
  return home;
  }
});
// This custom content returns a promise
let customContentWidget = new CustomContent({
  outFields: ["*"],
  creator: () => {
      const image = document.createElement("img");
      image.src = "<url to image>";
      image.width = 100;
      return image;
  }
});
// This custom content contains the resulting promise from the query
const customContentQuery = new CustomContent({
 outFields: ["*"],
 creator: (event) => {
   const queryObject = new Query({
     geometry: event.graphic.geometry,
     outFields: ["*"],
     spatialRelationship: "intersects",
     returnGeometry: true
   });
   return query.executeForCount(queryUrl, queryObject).then((count) => {
     return `There are ${count} features that intersect with ${event.graphic.attributes["field_name"]}.`;
   },
   (error) => {
     console.log(error);
   });
 }
});
declaredClass Stringreadonly inherited

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

不再需要时清理自定义内容的调用函数。

示例
// Destroy the custom content
let customContent = new CustomContent({
  ...
  destroyer: () => {
    // destroy custom content here
  }
});
outFields String[]

PopupTemplate 中使用的字段名称数组。使用此属性来指定完全渲染模板的自定义内容所需的字段。如果通过函数来设置 content,则这一点很重要,因为成功渲染所需的所有字段均需在此处指定。

要从所有字段中获取值,请使用 ["*"]

type Stringreadonly

显示的弹出元素的类型。

对于 CustomContent,类型总是 "custom"

默认值:custom

方法概述

显示继承的方法 隐藏继承的方法
名称 返回值类值 描述

添加一个或多个与对象生命周期相关联的句柄

更多详情
Accessor
CustomContent

创建 CustomContent 类的深度克隆。

更多详情
CustomContent
*

创建此类的新实例并使用从 GeoScene 产品生成的 JSON 对象值对其进行初始化。

更多详情
CustomContent
Boolean

如果存在指定的句柄组,则返回 true。

更多详情
Accessor

移除对象拥有的句柄组。

更多详情
Accessor
Object

将此类的实例转换为其 GeoScene Portal JSON 表示。

更多详情
CustomContent

方法详细说明

addHandles(handleOrHandles, groupKey)inherited
起始版本:GeoScene Maps SDK for JavaScript 4.25

添加一个或多个与对象的生命周期相关联的句柄。当对象被销毁时,将移除句柄。

// Manually manage handles
const handle = reactiveUtils.when(
  () => !view.updating,
  () => {
    wkidSelect.disabled = false;
  },
  { once: true }
);

this.addHandles(handle);

// Destroy the object
this.destroy();
参数
handleOrHandles WatchHandle|WatchHandle[]

对象销毁后,标记为要移除的句柄。

groupKey *
optional

标识句柄应添加到的组的键。组中的所有句柄稍后都可使用 Accessor.removeHandles() 进行删除。如果未提供键,则句柄将被添加到默认组。

clone(){CustomContent}

创建 CustomContent 类的深度克隆。

返回
类型 描述
CustomContent CustomContent 实例的深度克隆。
fromJSON(json){*}static

创建此类的新实例并使用从 GeoScene 产品生成的 JSON 对象值对其进行初始化。传入到输入 json 参数的对象通常来自对 REST API 中查询操作的响应或来自另一个 GeoScene 产品的 toJSON() 方法。

参数
json Object

GeoScene 格式实例的 JSON 表示。

返回
类型 描述
* 返回该类的新实例。
hasHandles(groupKey){Boolean}inherited
起始版本:GeoScene Maps SDK for JavaScript 4.25

如果存在指定的句柄组,则返回 true。

参数
groupKey *
optional

组键。

返回
类型 描述
Boolean 如果存在指定的句柄组,则返回 true
示例
// Remove a named group of handles if they exist.
if (obj.hasHandles("watch-view-updates")) {
  obj.removeHandles("watch-view-updates");
}
removeHandles(groupKey)inherited
起始版本:GeoScene Maps SDK for JavaScript 4.25

移除对象拥有的句柄组。

参数
groupKey *
optional

要移除的组键或组键的数组或集合。

示例
obj.removeHandles(); // removes handles from default group

obj.removeHandles("handle-group");
obj.removeHandles("other-handle-group");
toJSON(){Object}

将此类的实例转换为其 GeoScene Portal JSON 表示。有关详细信息,请参阅使用 fromJSON() 指南主题。

返回
类型 描述
Object 此类实例的 GeoScene Portal JSON 表示。

类型定义

PopupTemplateContentCreator(event){String|HTMLElement|Widget|Promise}

为创建自定义内容元素而调用的函数。

参数
optional

包含用于表示要素的图形的事件。

返回
类型 描述
String | HTMLElement | Widget | Promise 创建的自定义内容元素。
PopupTemplateContentDestroyer(event)

为销毁自定义内容元素而调用的函数。

参数
optional

包含用于表示要素的图形的事件。

PopupTemplateCreatorEvent

包含用于表示要素的图形的事件。

属性
graphic Graphic

用于表示要素的 Graphic

您的浏览器不再受支持。请升级您的浏览器以获得最佳体验。