LayerList

AMD: require(["geoscene/widgets/LayerList"], (LayerList) => { /* code goes here */ });
ESM: import LayerList from "@geoscene/core/widgets/LayerList";
类: geoscene/widgets/LayerList
继承于:LayerList Widget Accessor
起始版本:GeoScene Maps SDK for JavaScript 4.2

LayerList 微件提供了一种显示图层列表,以及打开/关闭其可见性的方法。ListItem API 提供了对每个图层属性的访问,允许开发人员配置与图层相关的操作,并可将内容添加到与图层相关的项目中。

要从 LayerList 微件中隐藏地图中的图层,必须将所需图层上的 listMode 属性设置为 hide

有关获得对微件样式完全控制的信息,请参阅样式主题。
另请参阅
示例
let layerList = new LayerList({
  view: view
});
// Adds widget below other elements in the top left corner of the view
view.ui.add(layerList, {
  position: "top-left"
});

构造函数

new LayerList(properties)
参数
properties Object
optional

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

示例
// typical usage
let layerlist = new LayerList({
  view: view
});

属性概述

可以设置、检索或侦听任何属性。请参阅使用属性主题。
显示继承属性 隐藏继承属性
名称 类型 描述
String|HTMLElement

包含微件的 DOM 元素的 ID 或节点。

更多详情
Widget
String

类的名称。

更多详情
Accessor
String

微件的默认 CSS 图标类。

更多详情
LayerList
String

创建微件时分配给微件的唯一 ID。

更多详情
Widget
String

微件的默认的标注。

更多详情
LayerList
ListItemCreatedHandler

每次创建 ListItem 时执行的函数。

更多详情
LayerList
Boolean

指示用户一次是否可以选择多个列表项。

更多详情
LayerList
Collection<ListItem>

表示业务图层的 ListItem 集合。

更多详情
LayerList
Collection<ListItem>

所选 ListItem 的集合,表示用户选择的业务图层。

更多详情
LayerList
Boolean

指示用户是否可以选择列表项。

更多详情
LayerList
MapView|SceneView

MapViewSceneView 的引用。

更多详情
LayerList
LayerListViewModel

此微件的视图模型。

更多详情
LayerList
Boolean

指示微件是否可见。

更多详情
Widget
VisibleElements

微件中显示的可见元素。

更多详情
LayerList

属性详细信息

包含微件的 DOM 元素的 ID 或节点。此属性只能设置一次。以下示例都是使用微件时的有效用例。

示例
// Create the HTML div element programmatically at runtime and set to the widget's container
const basemapGallery = new BasemapGallery({
  view: view,
  container: document.createElement("div")
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});
// Specify an already-defined HTML div element in the widget's container

const basemapGallery = new BasemapGallery({
  view: view,
  container: basemapGalleryDiv
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});

// HTML markup
<body>
  <div id="viewDiv"></div>
  <div id="basemapGalleryDiv"></div>
</body>
// Specify the widget while adding to the view's UI
const basemapGallery = new BasemapGallery({
  view: view
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});
declaredClass Stringreadonly inherited
起始版本:GeoScene Maps SDK for JavaScript 4.7

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

iconClass String
起始版本:GeoScene Maps SDK for JavaScript 4.7

微件的默认 CSS 图标类。

创建微件时分配给微件的唯一 ID。如果不是由开发人员设置的,它将默认为容器 Id,或者如果没有容器 ID,则将自动生成。

label String
起始版本:GeoScene Maps SDK for JavaScript 4.7

微件的默认的标注。

listItemCreatedFunction ListItemCreatedHandler
起始版本:GeoScene Maps SDK for JavaScript 4.4

每次创建 ListItem 时执行的函数。使用此函数可以向列表项添加操作和面板,以覆盖列表项的默认设置。可以使用 ListItem 的 actionsSections 属性将操作添加到列表项。

示例
let layerList = new LayerList({
  view: view,
  // executes for each ListItem in the LayerList
  listItemCreatedFunction: function (event) {

    // The event object contains properties of the
    // layer in the LayerList widget.

    let item = event.item;

    if (item.title === "US Demographics") {
      // open the list item in the LayerList
      item.open = true;
      // change the title to something more descriptive
      item.title = "Population by county";
      // set an action for zooming to the full extent of the layer
      item.actionsSections = [[{
        title: "Go to full extent",
        className: "geoscene-icon-zoom-out-fixed",
        id: "full-extent"
      }]];
    }
  }
});
multipleSelectionEnabled Boolean

指示用户一次是否可以选择多个列表项。必须首先将 selectionEnabled 设置为 true,此属性才能对微件产生影响。

所选项目在 selectedItems 属性中可用。

默认值:false
另请参阅
示例
layerList.selectionEnabled = true;
layerList.multipleSelectionEnabled = true;
operationalItems Collection<ListItem>readonly

表示业务图层的 ListItem 集合。要从 LayerList 微件隐藏图层,请将图层上的 listMode 属性设置为 hide

另请参阅
selectedItems Collection<ListItem>

所选 ListItem 的集合,表示用户选择的业务图层。

另请参阅
selectionEnabled Boolean

指示用户是否可以选择列表项。通过使用鼠标或触摸屏拖动手势,或者使用键盘上的箭头键,可以在列表中对所选项目进行重新排序。

所选项目在 selectedItems 属性中可用。

默认值:false
另请参阅
示例
layerList.selectionEnabled = true;

MapViewSceneView 的引用。设置此选项可将微件链接到特定视图。

此微件的视图模型。此类包含控制此微件行为的所有逻辑。请参阅 LayerListViewModel 类来访问微件上的所有属性和方法。

指示微件是否可见。

如果为 false,微件将不再呈现在 web 文档中。这可能会影响文档中其他元素或微件的布局。例如,如果此微件是与视图 UI 右上角关联的三个微件中的第一个,则当此微件不可见时,其他微件将重新定位。有关更多信息,请参阅 CSS display"none"

默认值:true
示例
// Hides the widget in the view
widget.visible = false;
visibleElements VisibleElements
起始版本:GeoScene Maps SDK for JavaScript 4.15

微件中显示的可见元素。此属性提供了打开/关闭微件显示的各个元素的能力。

示例
layerList.visibleElements = {
  statusIndicators: false,
  errors: true
};

方法概述

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

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

更多详情
Accessor
String

用于为微件的 class 属性构建值的实用方法。

更多详情
Widget

销毁微件实例。

更多详情
Widget
Boolean

在实例上触发事件。

更多详情
Widget
Boolean

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

更多详情
Widget
Boolean

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

更多详情
Accessor
Boolean

isFulfilled() 可用于验证创建类的实例是否已完成 (已解决或已拒绝)。

更多详情
Widget
Boolean

isRejected() 可用于验证创建类的实例是否被拒绝。

更多详情
Widget
Boolean

isResolved() 可用于验证创建类的实例是否已解决。

更多详情
Widget
Object

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

更多详情
Widget

添加一个或多个与微件的生命周期相关联的句柄。

更多详情
Widget

此方法主要由开发人员在实现自定义微件时使用。

更多详情
Widget

移除对象拥有的句柄组。

更多详情
Accessor
Object

此方法主要由开发人员在实现自定义微件时使用。

更多详情
Widget

立即将微件渲染到 DOM。

更多详情
Widget

此方法主要由开发人员在实现自定义微件时使用。

更多详情
Widget

触发 trigger-action 事件并执行给定的操作操作切换

更多详情
LayerList
Promise

一旦创建了类的实例,就可以使用when()

更多详情
Widget

方法详细说明

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

// Handle gets removed when the object is destroyed.
this.addHandles(handle);
参数
handleOrHandles WatchHandle|WatchHandle[]

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

groupKey *
optional

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

classes(classNames){String}inherited
起始版本:GeoScene Maps SDK for JavaScript 4.7

用于为微件的 class 属性构建值的实用方法。这有助于简化 CSS 类设置。

参数
repeatable

类名称。

返回
类型 描述
String 计算的类名。
另请参阅
示例
// .tsx syntax showing how to set CSS classes while rendering the widget

render() {
  const dynamicIconClasses = {
    [CSS.myIcon]: this.showIcon,
    [CSS.greyIcon]: !this.showIcon
  };

  return (
    <div class={classes(CSS.root, CSS.mixin, dynamicIconClasses)} />
  );
}
destroy()inherited

销毁微件实例。

emit(type, event){Boolean}inherited
起始版本:GeoScene Maps SDK for JavaScript 4.5

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

参数
type String

事件的名称。

event Object
optional

事件有效负载。

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

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

参数
type String

事件的名称。

返回
类型 描述
Boolean 如果类支持输入事件,则返回 true。
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");
}
isFulfilled(){Boolean}inherited
起始版本:GeoScene Maps SDK for JavaScript 4.19

isFulfilled() 可用于验证创建类的实例是否已完成 (已解决或已拒绝)。如果满足,则返回 true

返回
类型 描述
Boolean 指示创建类的实例是否已完成 (已解决或已拒绝)。
isRejected(){Boolean}inherited
起始版本:GeoScene Maps SDK for JavaScript 4.19

isRejected() 可用于验证创建类的实例是否被拒绝。如果被拒绝,则返回 true

返回
类型 描述
Boolean 指示创建类的实例是否已被拒绝。
isResolved(){Boolean}inherited
起始版本:GeoScene Maps SDK for JavaScript 4.19

isResolved() 可用于验证创建类的实例是否已解决。如果已解决,则返回 true

返回
类型 描述
Boolean 指示创建类的实例是否已解决。
on(type, listener){Object}inherited

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

参数

要侦听的事件或者事件数组。

listener Function

事件触发时要调用的函数。

返回
类型 描述
Object 返回具有 remove() 方法的事件处理程序,可调用该方法来停止侦听事件。
属性 类型 描述
remove Function 调用时,从事件中移除侦听器。
示例
view.on("click", function(event){
  // event is the event handle returned after the event fires.
  console.log(event.mapPoint);
});
own(handleOrHandles)inherited
起始版本:GeoScene Maps SDK for JavaScript 4.24

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

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

this.own(handle); // Handle gets removed when the widget is destroyed.
参数
handleOrHandles WatchHandle|WatchHandle[]

微件销毁后,标记为要移除的句柄。

postInitialize()inherited

此方法主要由开发人员在实现自定义微件时使用。在微件准备好渲染后执行。

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");
render(){Object}inherited

此方法主要由开发人员在实现自定义微件时使用。它必须由子类实现以进行渲染。

返回
类型 描述
Object 渲染的虚拟节点。
renderNow()inherited

立即将微件渲染到 DOM。

scheduleRender()inherited

此方法主要由开发人员在实现自定义微件时使用。计划微件渲染。此方法对于影响 UI 的更改非常有用。

triggerAction(action, item)

触发 trigger-action 事件并执行给定的操作操作切换

参数

要执行的操作。

与操作关联的项目。

when(callback, errback){Promise}inherited
起始版本:GeoScene Maps SDK for JavaScript 4.19

一旦创建了类的实例,就可以使用when() 。此方法接受两个输入参数:callback 函数和 errback 函数。callback 在类的实例加载时执行。errback 在类的实例无法加载时执行。

参数
callback Function
optional

当 promise 解决时调用的函数。

errback Function
optional

当 promise 失败时执行的函数。

返回
类型 描述
Promise callback 结果返回一个新的 promise
示例
// Although this example uses the BasemapGallery widget, any class instance that is a promise may use when() in the same way
let bmGallery = new BasemapGallery();
bmGallery.when(function(){
  // This function will execute once the promise is resolved
}, function(error){
  // This function will execute if the promise is rejected due to an error
});

类型定义

ListItemCreatedHandler(event)

listItemCreatedFunction 属性的函数定义。有关更多详细信息,请参阅 listItemCreatedFunction 文档中的示例代码段。

参数
event Object

包含由 LayerList 创建的列表项的对象。

规范

由 LayerList 创建的列表项。您可以修改此项目的属性以自定义列表项目的文本、操作、面板内容和可见性。有关详细信息,请参阅 listItemCreatedFunction 的文档。

VisibleElements

微件中显示的可见元素。这提供了打开/关闭微件显示的各个元素的能力。

属性
statusIndicators Boolean
optional

指示是否显示状态指示器。默认为 true

errors Boolean
optional

自 4.25 指示是否显示图层加载错误。默认为 false

事件概述

名称 类型 描述
{action: ActionButton,ActionToggle,item: ListItem}

用户在 LayerList 微件内单击操作操作切换后触发。

更多详情
LayerList

事件详细说明

trigger-action

用户在 LayerList 微件内单击操作操作切换后触发。此事件可用于定义单击特定操作时要执行的自定义函数。

属性

用户单击的操作。

与操作相关联的 ListItem。

您的浏览器不再受支持。请升级您的浏览器以获得最佳体验。请参阅浏览器弃用帖子以获取更多信息