首页 / 浏览问题 / WebGIS / 问题详情
无法控制子图层的显隐性,选择一个展示对应的而不是全部展示
22EXP 2023年05月29日
let url =

      "http://10.64.101.123/iserver/services/map-GZGQ-3/rest/maps/zjmaproad";

    var list = [];

    this.layerInfoService = new mapboxgl.supermap.LayerInfoService(url);

    this.layerInfoService.getLayersInfo((result) => {

      if (result.result.subLayers.layers) {

        var layers1 = result.result.subLayers.layers;

        console.log(layers1, "!1111111111");

        // 设置图层

        for (var i = 0; i < layers1.length; i++) {

          if (i % 2 == 0) {

            list.push(

              new SuperMap.LayerStatus({

                layerName: layers1[i].name,

                isVisible: "true",

              })

            );

          } else {

            list.push(

              new SuperMap.LayerStatus({

                layerName: layers1[i].name,

                isVisible: "true",

              })

            );

          }

        }

        this.checkData = list;

      }

    });

 statusChange(vals) {

      var index = this.strArr.indexOf(vals.layerName);

      if (index > -1) {

        this.strArr.splice(index, 1); //存在就删除

        //删除

      } else {

        this.strArr.push(vals.layerName);

      }

      this.list=[]

      this.strArr.forEach((j) => {

        this.checkData.forEach((vals) => {

          if (vals.layerName == j) {

            this.list.push(

              new SuperMap.LayerStatus({

                layerName: vals.layerName,

                isVisible: vals.isVisible,

              })

            );

          }

        });

      });

      var style = this.map.getStyle().layers

          console.log(style,"stylestylestyle");

      var p = new SuperMap.SetLayerStatusParameters({

        layerStatusList: this.list,

      });

      this.layerInfoService.setLayerStatus(p, (e) => {

        if (e.result) {

          var t1 = e.result.newResourceID;

          if (this.map.getLayer("simple-tiles")) {

            try {

              this.map.removeLayer("simple-tiles");

              this.map.removeSource("firstLayer");

            } catch {

              console.log("no layer,no source");

            }

          }

          this.map.addSource("firstLayer", {

            type: "raster",

            tiles: [

              "http://10.64.101.123/iserver/services/map-GZGQ-3/rest/maps/zjmaproad/zxyTileImage.png?prjCoordSys=" +

                encodeURIComponent('{"epsgCode":3857}') +

                "&z={z}&x={x}&y={y}&noWrap=true&transparent=true&cacheEnabled=false&layersID=" +

                t1,

            ],

            tileSize: 256,

          });

          this.map.addLayer({

            id: "simple-tiles",

            type: "raster",

            source: "firstLayer",

            minzoom: 0,

            maxzoom: 22,

          });

        }

      });

    },

1个回答

您好,可以在打印LayerStatus所对应图层的显隐情况,是否都为isVisible: "true",

参考https://blog.csdn.net/supermapsupport/article/details/128182266

1,865EXP 2023年05月29日
打印了,选中的是true,未选中的没有展示
...