zoukankan      html  css  js  c++  java
  • 使用hittest获取点击要素的属性值

    在项目中会用到点击要素,显示当前点击要素的相关属性,需要进行弹窗的显示,而官方自带的popup不符合界面的要求,所以就是想着在获取到对应的属性值,在自己定义的div中进行显示。查阅了很多资料,发现可以使用hittest方法轻松获取到这些属性值。

    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 === csvLayer;//其中这个csvLayer是我项目中使用的图层,即要点击查询的图层换成自己的图层即可
    })[0].graphic; // do something with the result graphic console.log(graphic.attributes["unit_name"]); } }); });

    最初想的是通过query进行查询,可是无法获取支持查询的条件,所以没进行下去。最终找到了hittest方法。

  • 相关阅读:
    工具类-ApplicationContextUtil
    银行联行号-全国地区码
    银行联行号-银行编码(联行号前3位)
    前端防止 JS 调试技巧
    Vue基础框架
    关于5G手机使用4G套餐扫盲
    nginx高级-前端必会
    懒人npm运行和打包命令
    关于虚拟专用网络的一些经验
    JS加密解密
  • 原文地址:https://www.cnblogs.com/1gaoyu/p/15192861.html
Copyright © 2011-2022 走看看