ol

254 阅读1分钟
  • hover事件或者click事件
  pointerFocusFeatures: function(results) {
    this.pointerFocusLayer.getSource().clear();
    results = results || [];
    results.forEach(feature => {
      if (feature.get('type') === 'some') {
  
        const style = feature.getStyle();
        const image = style.getImage().getImage().src;
        const coordinates = feature.getGeometry().getCoordinates();
        const f = this.createFeature(coordinates);
        f.setStyle(
          new ol.style.Style({
            image: new ol.style.Icon({
              anchor: [0.5, 0.5],
              opacity: 0.8,
              anchorXUnits: 'fraction',
              anchorYUnits: 'fraction',
              src: image,
              scale: 0.7
            })
          })
        );
        this.pointerFocusLayer.getSource().addFeature(f);
      }
    });
  },