Hi,
for the Command Engine I had exactly the same problem, i.e. I want map markers to be clickable. For this I created the function "getClickedMarker.sqf",
_markerID = [ clickPos, maxDist, [ markersToCheck ] call loadFile "getClickedMarker.sqf"
into which you pass the click position, the max distance (clickPos <-> marker) for a viable click and an array of markers to be checked for. It then returns the index of the clicked marker (or -1, if no marker was clicked):
comment
{
selectedMarkerID_integer = getClickedMarker (position_array, threshold_float, markers_array)
returns ID of clicked marker (= closest marker to position and within threshold) within array markers
if no viable marker is found, it returns -1
};
private ["_x", "_y", "_theshold", "_markers", "_ID", "_minDist", "_N", "_i", "_markerPos", "_dist"];
_x = (_this select 0) select 0;
_y = (_this select 0) select 1;
_threshold = _this select 1;
_threshold = _threshold^2;
_markers = _this select 2;
_ID = -1;
_minDist = _threshold;
_N = count _markers;
_i = 0;
while {_i < _N}
do
{
_markerPos = getMarkerPos (_markers select _i);
_dist = (_x - (_markerPos select 0))^2 + (_y - (_markerPos select 1))^2;
if (_dist < _threshold)
then
{
if (_dist < _minDist) then {_minDist = _dist; _ID = _i}
};
_i = _i + 1
};
_ID
The algorithm is quite simply. I simply loop through all markers and calculate the distance between the click and each marker. If distance > maxDistance, the marker is discarded, if not, the distance is compared with the (yet) minimal distance click<->marker. If the new distance is smaller it is taken as the new minDist.
That way one can determine the marker with smallest (<maxDist) distance to clickPos.
Hope this helps,
Spinor