I'm working with an Open Street Map that includes vectors (lines) displaying on the roads. Currently, I can only retrieve information about a vector by clicking directly on its pixels. Is there a way to make it so that I can click near the vector (a few pixels off) and still get the relevant information, in order to be less precise?
Code:
Here is the code snippet I am using to get features when I click on a vector:
var displayFeatureInfo = function (pixel, coordinate) {
var features = [];
map.forEachFeatureAtPixel(pixel, function (feature, layer) {
features.push(feature); // Storing each feature found in an array
});
if (features.length > 0) { // If there are one or more features
$("#popup").html('<object data=' + "http://URLToLoadDataFrom '/>'); // Loading data via jQuery
popup.setPositioning('top-left');
popup.setPosition(coordinate);
container.style.display = 'block';
} else {
container.style.display = 'none';
}
};
map.on('click', function (evt) {
var coordinate = evt.coordinate;
displayFeatureInfo(evt.pixel, coordinate);
});
Thanks for any help in advance.