# Find index of Linestring element at feature, when hovering - openlayers/GeoJson

I have a Geo-JSON Linestring, this is drawn by 800 elements in OpenLayers 4.6.5.

I'am trying to use the map.forEachFeatureAtPixel, and print a pop-up when hovering for individual elements on the linestring. However, i have trouble identifying which element in the Linestring i'm CURRENTLY hovering over.

I can extract the whole array of 800 elements from my Linestring;

map.on('pointermove', function (evt2) {
var linefeature = map.forEachFeatureAtPixel(evt2.pixel, function
(kfeature, layer) {
console.log(kfeature.N.geometry.A);
return kfeature;
}


I have tried to experiment with forEachSegment, without any promising result:https://openlayers.org/en/latest/apidoc/module-ol_geom_LineString-LineString.html

Same for the findIndex(), i don't get any results.

How do I identify the elements in my Linestring? Or suggestions for other ways to solve this?

You would probably have get the point on the linestring corresponding to the pixel clicked, then convert each segment into a linestring to see it contains that point (using a for loop because forEachSegment doesn't pass an index):
var geometry = linefeature.getGeometry();