如何在JavaScript中从我的图层列表中移除未命名的图层?

huangapple go评论63阅读模式
英文:

How do I remove the untitled layer from my layer list in JavaScript?

问题

我正在使用HTML、CSS和JavaScript创建一个Web应用程序,具体来说是使用ArcGIS JavaScript API。我已经创建了一个图层列表,以便用户可以打开和关闭他们想要的特定图层。然而,有一个未命名的图层,我不确定它在哪里。当我尝试从图层列表中关闭它时,地图上没有任何变化,这表明没有数据可以切换开关。我已经进行了几周的调试,但一无所获,所以我真的很需要一些帮助。下面是显示确切问题的屏幕截图。

我的图层列表代码如下:

view.when(() => {
  const layerList = new LayerList({
      view: view,
      visible: false,
      selectionEnabled: true
  });
  const expand = new Expand({
      view: view,
      content: layerList
  });

  // 将微件添加到视图的右上角
  view.ui.add(expand, "top-left");
});

如何在JavaScript中从我的图层列表中移除未命名的图层?

英文:

I am creating a web application using html, CSS and JavaScript, specifically arcgis JavaScript API. I have created a layer list so that users can turn on and turn off the specific layers they want. However, there is a untitled layer and I am not sure where it is. When I try to turn it off from the layer list nothing moves from the map which suggests there is no data to toggle on or off. I have done weeks of debugging and I am getting nowhere so I would really appreciate some help. The screenshot showing the exact issue is below.

如何在JavaScript中从我的图层列表中移除未命名的图层?

My code for the layer list looks like this:

view.when(() => {
  const layerList = new LayerList({
      view: view,
      visible: false,
      selectionEnabled: true
  });
  const expand = new Expand({
      view: view,
      content: layerList
  });

  // Add widget to the top right corner of the view
  view.ui.add(expand, "top-left");
});

答案1

得分: 0

你可以提供更多细节吗?也许有一个可工作的 CodePen 示例吗?

你的 JavaScript 代码没问题。看起来在某个地方确实创建了一个名为 "Untitle Layer" 的地图图层。在这种情况下,你可以使用 ListItemPanel widget 中的 listItemCreatedFunction 来确保不渲染特定项目。

英文:

Can you provide more detail? Maybe working codepen?

Your JS is ok. Looks like someone along the way actually created a map layer named "Untitle Layer". That being the case you can use the listItemCreatedFunction in the ListItemPanel widget to make sure that specific item is not rendered.

huangapple
  • 本文由 发表于 2023年7月14日 01:20:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76681879.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定