zoukankan      html  css  js  c++  java
  • openLayer点击要素获取对应的属性信息

    点击要素获取对应的属性信息的两种方法

    1.首先是map的点击事件

     const map = this.map;
           map.on('click', function(evt) {
              var coordinate = evt.coordinate;      //获取点击要素的位置coordinate[0]为精度coordinate[1]为纬度
            /****************************************************/
            //判断当前单击处是否有要素,捕获到要素时弹出popup
            var feature = map.forEachFeatureAtPixel(evt.pixel, function(feature, layerVetor) { return feature; });
             if (feature) { //捕捉到要素
    
                // featuerInfo = feature.getProperties().features[0].N.attribute;
                console.log("获取到点击的要素" + "jingdu:" + coordinate[0] + feature.get('lei'));  //其中lei是定义的属性
             }
           })

    2.使用Select进行要素的选择

    //定义select控制器,点击标注后的事件
          const map = this.map;
          var select = new Select();
          //map加载该控件,默认是激活可用的
          map.addInteraction(select);
          select.on("select", function (e) {
            console.log("选中要素");
            // console.log(e.selected[0].get('name')); //打印已选择的Feature的name属性
                  var currentRome = e.selected[0]; //获取当前选中的节点
    
         })
  • 相关阅读:
    C++ 概念易错点
    C++的位操作符备忘
    C++关键词
    在ubuntu下安装drupal6
    C++符号优先级一览
    开启drupal的clear urls
    VC6.0使用PlaySound函数报错
    小记一下以非string为结束条件的循环
    C++中查看数据类型的方法
    在ubuntu下安装和配置drupal
  • 原文地址:https://www.cnblogs.com/1gaoyu/p/15261435.html
Copyright © 2011-2022 走看看