zoukankan      html  css  js  c++  java
  • 获取图层中的属性值

    Arcgis api for js从图层中获取字段的值

    function getGraphics(response) {
    
                  // the topmost graphic from the hurricanesLayer
    
                  // and display select attribute values from the
    
                  // graphic to the user
    
                  if (response.results.length) {
    
                    const graphic = response.results[0].graphic;
    
     
    
                    const attributes = graphic.attributes;
    
                    const category = attributes.CAT;
    
                    const wind = attributes.WIND_KTS;
    
                    const name = attributes.NAME;
    
                    const year = attributes.YEAR;
    
                    const id = attributes.OBJECTID;
    
    }

    调用方式:

    view.hitTest(event, opts).then(getGraphics);

    其中opts是可选项,代表选中的某个要素

    上面是通过函数调用的方式进行的,也可以直接通过事件调用hitTest进行查询

    例如官方样例中的两个例子

    1.通过点击事件触发,获取对应的值

    // Get the screen point from the view's click event
    
    view.on("click", function (event) {
    
      // Search for graphics at the clicked location. View events can be used
    
      // as screen locations as they expose an x,y coordinate that conforms
    
      // to the ScreenPoint definition.
    
      view.hitTest(event).then(function (response) {
    
        if (response.results.length) {
    
          let graphic = response.results.filter(function (result) {
    
            // check if the graphic belongs to the layer of interest
    
            return result.graphic.layer === myLayer;
    
          })[0].graphic;
    
     
    
          // do something with the result graphic
    
          console.log(graphic.attributes);
    
        }
    
      });
    
    });
    
     

    2.pointer-move事件触发,来查询相关值

    // get screenpoint from view's pointer-move event
    
    view.on("pointer-move", function(event){
    
      // Search for graphics on layers at the hovered location
    
      // exclude view.graphics from the hitTest
    
      view.hitTest(event, {exclude: view.graphics}).then(function(response){
    
        // if graphics are returned, do something with results
    
        if (response.results.length){
    
           // do something
    
        }
    
      })
    
    })
  • 相关阅读:
    【Android 工具类】经常使用工具类(方法)大全
    driver: Linux设备模型之input子系统具体解释
    ural 1057 Amount of degrees 【数位dp】
    Java8 Lambda表达式教程
    Java线程池
    NodeJS实战——创建基础应用并应用模板引擎
    【网络】代理服务器
    【HTTP】Wireshark过滤规则
    【HTTP】WireShark中获取Content-Encoding: gzip时的响应内容
    【python】判断字符串日期是否有效
  • 原文地址:https://www.cnblogs.com/1gaoyu/p/15167616.html
Copyright © 2011-2022 走看看