In my openlayers map there is a list of Points, which is processed to a list of icons and then is correctly displayed on the map.
var markers = [icon1, icon2, icon3]
var vectorSource = new ol.source.Vector({
features:markers});
var stationLayer = new ol.layer.Vector({
source:vectorSource});
map.addLayer(stationLayer);
In a next step I want to make these Points at the Map clickable. When the point is clicked a table outside the map should show further information on the chosen point. The different Points are defined through their position in the array.
After reading several examples I tried this:
map.on('click',function(event){
var coord = event.coordinate;
console.log(coord)
var source = stationLayer.getSource();
var feature = source.getClosestFeaturetoCoordinate(coord);
});
The click-event is triggered properly, the right Coordinates are shown on the console. There is also a feature stored, but i can't tell if it's a point and if it's the right one.
Is there any way I can get the index in markers from the clicked point?