zoukankan      html  css  js  c++  java
  • openlayers 为元素添加点击和鼠标悬停事件

     let clickSelect = new Select({
            condition: click,
            hitTolerance: 5,
          });
          clickSelect.layerName = 'dangerRiver';
          var _this = this;
          clickSelect.on('select', function (e) {
            if (e.selected.length > 0) {
              let layerName = e.target.getLayer(e.selected[0]).layerName;
              if (layerName == 'evacuationroute') {
                this.getFeatures().clear();
              } else {
                _this.mapComponent.showPopup(e.selected[0], layerName);
                this.getFeatures().clear();
              }
            }
          });
          this.mapComponent.map.addInteraction(clickSelect);

          let pointerMoveSelect = new Select({
            condition: pointerMove,
            hitTolerance: 5,
          });
          pointerMoveSelect.on('select', function (e) {
            let features = e.target.getFeatures().array_;
            if (features.length > 0) {
              let layerName = e.target.getLayer(e.selected[0]).layerName;
              if (layerName == 'evacuationroute') {
                this.getFeatures().clear();
              } else {
                _this.mapComponent.map.getTargetElement().style.cursor = 'pointer';
              }
              //this.getFeatures().clear();
            } else {
              _this.mapComponent.map.getTargetElement().style.cursor = 'auto';
            }
          });
          this.mapComponent.map.addInteraction(pointerMoveSelect);
     
    引入:
    import { click, pointerMove } from 'ol/events/condition.js';
    import Select from 'ol/interaction/Select';
    import Point from 'ol/geom/Point';
    import Feature from 'ol/Feature';
  • 相关阅读:
    svn笔记
    cakephpurl生成
    cakephp加载流程
    jquery validate使用方法
    我需要具备的知识和能力总结
    cakePHP国际化和本地化
    javascript片段收集
    ecmall一个典型的操作
    9. Technical Overview 技术概述
    42. Spring Security Dependencies春季安全依赖
  • 原文地址:https://www.cnblogs.com/maycpou/p/14606505.html
Copyright © 2011-2022 走看看