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