Search code examples
openlayers

How to select a polygon by click its internal space


I make a Select like the openlayers example:

this.select = new Select()
this.map.addInteraction(this.select)
this.selectedFeatures = this.select.getFeatures()

But I can only select polygon at its boundary. How can I select the polygon when clicking at the internal space?


Solution

  • Select:

    style Style for the selected features. By default the default edit style is used (see module:ol/style).

    The default edit style only "highlights" broundaries, but you can create a different style:

    this.select = new Select({
        style: new Style({
            fill: new Fill({
                color: [0, 0, 255, 0.5]
            })
        })
    });
    this.map.addInteraction(this.select);
    

    Here is a working demo:

    https://anatolysukhanov.com/stackoverflow/openlayers/4-select.html