我正在使用arcgis地图JavaScript API,我想显示带有关闭图标的地图图层图例,但是我无法找到图例加载事件来显示相同的图例。下图显示了图例和关闭图标。enter image description here
通过图例小部件的mapview.ui
属性将其添加到container
后,您可以访问图例小部件的dom节点。
以下脚本摘自sample demo
require([
"esri/views/MapView",
"esri/widgets/Legend",
"esri/WebMap"
], function(MapView, Legend, WebMap) {
var webmap = new WebMap({
portalItem: {
// autocasts as new PortalItem()
id: "4abe6a830b8f466dacf8abfde567a781"
}
});
var view = new MapView({
container: "viewDiv",
map: webmap
});
view.when(function() {
// get the first layer in the collection of operational layers in the WebMap
// when the resources in the MapView have loaded.
var featureLayer = webmap.layers.getItemAt(0);
var legend = new Legend({
view: view,
layerInfos: [
{
layer: featureLayer,
title: "NY Educational Attainment"
}
]
});
// Add widget to the bottom right corner of the view
view.ui.add(legend, "bottom-right");
//Now you can access the legend domNode and add a close button
console.log(legend.container)
});
});