Null select style

by Vladimir Vershinin

HTML

<script src="https://unpkg.com/vue@latest/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io/en/v5.3.0/build/ol.js"></script>
<script src="https://unpkg.com/[email protected]/lib/index.umd.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/lib/style.css">
<div id="app">
  <vl-map ref="map" data-projection="EPSG:4326">
    <vl-view ref="view"
             :zoom.sync="zoom" 
             :center.sync="center"></vl-view>
    <vl-layer-tile>
      <vl-source-osm></vl-source-osm>
    </vl-layer-tile>
    
    <vl-layer-vector>
      <vl-source-vector :features="features"></vl-source-vector>
      <vl-style-func :factory="newLayerStyleFunc"></vl-style-func>
    </vl-layer-vector>
    
    <vl-layer-vector>
      <vl-source-vector>
        <vl-feature id="another">
          <vl-geom-point :coordinates="[-20, -20]"></vl-geom-point>
        </vl-feature>
      </vl-source-vector>
    </vl-layer-vector>
    
    <vl-interaction-select>
      <vl-style-func :factory="newSelectStyleFunc"></vl-style-func>
    </vl-interaction-select>
  </vl-map>  
</div>

CSS

html, body, #app {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

#app {
  display: flex;
  flex-direction: column;
}

.vl-map {
  overflow: hidden;
}

JavaScript

new Vue({
	el: '#app',
  data () {
  	return {
    	zoom: 2,
      center: [0, 0],
      features: [
      	{
        	type: 'Feature',
          id: 'one',
          geometry: {
          	type: 'Point',
            coordinates: [10, 10],
          },
        },
        {
        	type: 'Feature',
          id: 'two',
          geometry: {
          	type: 'Point',
            coordinates: [30, 30],
          },
        },
      ]
    }
  },
  computed: {
  	layerFeatureIds () {
    	return this.features.map(f => f.id)
    },
  },
  methods: {
  	newLayerStyleFunc (scale = 0.1) {
    	return () => {
      	return [
        	new ol.style.Style({
          	image: new ol.style.Icon({
            	src: 'https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678111-map-marker-512.png',
              scale,
            }),
          }),
        ]
      }
    }, 
  	newSelectStyleFunc () {
    	let defStyle = new ol.style.Style({
      	image: new ol.style.Circle({
        	fill: new ol.style.Fill({ color: 'blue' }),
          stroke: new ol.style.Stroke({ color: 'white', widht: 2, }),
          radius: 7,
        }),
      })
      let layerStyleFunc = this.newLayerStyleFunc(0.3)
    
    	return (feature, resolution) => {
      	if (this.layerFeatureIds.includes(feature.getId())) {
        	return layerStyleFunc(feature, resolution)
        }
        
        return [
        	defStyle,
        ]
      }
    },
  }
})