Reputation: 41
When I used this function to get features, I found that: If the 'Style' (like image and text) of a 'Feature' is within 100 pixels of the feature's coordinate, I can get the feature by using the pixels within the 'Style'; But If the 'Style' is too far (more than 100 pixels), I cannot get the 'Feature' by using the pixels of the 'Style'.
e.g. adding the 'ol/style/Text' into a Style of a feature.
new Text({
font: '15px Microsoft YaHei',
text: '',
fill: new Fill({
color: '#222'
}),
backgroundStroke: new Stroke({
color: 'rgba(0,0,0,0.5)',
width: 1
}),
backgroundFill: new Fill({
color: 'rgba(0,250,154,0.3)'
}),
textAlign: 'middle',
textBaseline: 'middle',
offsetX: 200,
offsetY: 200
})
Upvotes: 2
Views: 298
Reputation: 41
I have found solution in github:
By default, OpenLayers only considers an area of 100 pixels around a feature for hit detection. When you use an offset of 200 pixels. you are outside of that region. To fix it, configure your layer with a renderBuffer
with an appropriate size.
Upvotes: 2