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]; //获取当前选中的节点
    
         })
  • 相关阅读:
    HTTP报文
    Linux命令行下快捷键
    ruby离线安装整理
    Tomcat启动时卡在 INFO HostConfig.deployDirectory Deploy
    ruby在线安装整理
    python_控制台输出带颜色的文字方法
    http proxy模块参数
    upstream模块调度算法
    upstream模块介绍
    nginx的upstream目前支持5种方式的分配
  • 原文地址:https://www.cnblogs.com/1gaoyu/p/15261435.html
Copyright © 2011-2022 走看看