what I needed was to get the shortest distance to the one of the vertices like the green segment in the answer of Werkuh so I'll let my code here, it works fine in case someone is looking for it: var wgs84Sphere = new ol.Sphere(6378137); var ...
Take a look at the ol3 API here this will get you the point of the line closest to the given coordinate. Otherwise you have to calculate the perpendicular distance. There's a few ways to accomplish that, see Wikipedia for reference. But with the function I pointed out in the API you are already halfway done. You just have to figure out the second point ...
OpenLayers does check for FIDs internally and will not add a previously added feature. So make sure that you get unique FIDs from GeoServer. If you have an incorrect configuration of your data source, you may end up getting random FIDs, and then OpenLayers cannot avoid the duplication on the client.
Only top voted, non community-wiki answers of a minimum length are eligible