FeatureLayer图层的属性查询方式(query的使用方法)

以csvLayer为例:

 view
          .whenLayerView(csvLayer)
          .then(function(csvLayerView) {
      const queryStations = csvLayerView.createQuery();
             queryStations.where = "state = 'ME'";    //如果需要进行模糊查询的话可以将=改为like并在字符前后加上% 例如: state like '%M%'
            
            csvLayerView.queryFeatures(queryStations).then((result) => {

              const feature = result.features[0];             

              let features = [];
              for(var i = 0 ; i < result.features.length;i++)
              {             
                console.log(result.features[i].attributes["unit_name"])
              }
            })
  })

其他的图层的使用大方与此类似,例如使用webScene进行的查询

webScene.when(() => {
//从webScene中获取Layer,如果是直接引入的FearureLayer可以省略这一步
const stationLayer = webScene.layers.getItemAt(1);
    view.whenLayerView(stationLayer).then((layerView) => {
          const queryStations = stationLayer.createQuery();
          queryStations.where = `nom='123'`;
              stationLayer.queryFeatures(queryStations).then((result) => {                
                
                const feature = result.features[0];
console.log(result.features[i].attributes["unit_name"])
  }); }) })

 

posted on 2021-08-26 09:43  一往无前!  阅读(258)  评论(0编辑  收藏  举报