Layer 常用的小知识点汇总(4.18以上)

2023-12-13 04:36:59

如题:想到什么就添加什么的随记

不定时更新

1、GraphicsLayer添加一条数据

let gpc = new Graphic();  // Creates a new graphic
let layer = new GraphicsLayer(); // Creates a new graphics layer
layer.graphics.add(gpc);  // Adds graphic to layer's graphics collection

2、GraphicsLayer添加多条数据

// Creates two new graphics
let gpc1 = new Graphic();
let gpc2 = new Graphic();
let layer = new GraphicsLayer(); // Creates a new graphics layer
layer.graphics.addMany([gpc1, gpc2]);// Adds both graphics to layer's graphics collection

3、获取视图中加载的第一个最后一个图层

// get the layer at the first position
let firstLayer = map.layers.at(0);
// get the layer at the last position
let lastLayer = map.layers.at(-1);

4、every获取满足条件的元素

let meetsStandar = graphicsLayer.graphics.every(function(item, i){
  //return item.geometry > 1000;
   return item.attributes["某一个字段名"] != "某一个值";
});

5、filter获取满足条件的元素(返回一个数组)

let filteredLayers = map.layers.filter(function(layer){
  return !layer.visible;
});

6、find获取满足条件的元素(返回一个对象)

let myLayer = map.layers.find(function(layer){
  return layer.id === "speciesLyr01";
});

7、获取满足条件元素的索引

let gpcIndex = graphicsLyr.graphics.findIndex(function(item){
  return item.attributes.name === "Redlands";
});

8、判断图层集合中是否包含某一图层

if (view.map.layers.includes(myLayer)) {
  // ...
}

9、获取索引

let index = graphicsLayer.graphics.indexOf(graphic);

10、移除图层

let layer = map.layers.at(4);
// Removes the fifth layer from the map
map.layers.remove(layer);
map.layers.removeAt(4);
map.layers.removeAll(); //移除所有图层
let refLayers = [refLyr1, refLyr2, refLyr3];
// Removes three reference layers in the refLayers
// collection from the basemap's referenceLayers
map.basemap.referenceLayers.removeMany(refLayers);
let refLayers = [refLyr1, refLyr2, refLyr3];
// Removes three reference layers in the refLayers
// collection from the basemap's referenceLayers
map.basemap.referenceLayers.removeMany(refLayers);

11、图层移动到指定索引位置

// Get the first two layers in a map
let layer1 = map.layers.at(0);
let layer2 = map.layers.at(1);

// Moves the second layer to the first position in the map.layers Collection
// effectively swapping the positions of layer1 and layer2
map.layers.reorder(layer2, 0);

12、反向重新排序

// Reverse layers from the map
map.layers.reverse();

文章来源:https://blog.csdn.net/baicai_123/article/details/134948285
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。