fn_findUserMarker.sqf 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. Name: cTab_fnc_findUserMarker
  3. Author(s):
  4. Gundy, Riouken
  5. Description:
  6. Find user placed marker at provided position
  7. Parameters:
  8. 0: OBJECT - Map control we took the position from
  9. 1: ARRAY - Position to look for marker
  10. Returns:
  11. INTEGER - Index of user marker, if not found -1
  12. Example:
  13. _markerIndex = [_ctrlScreen,[0,0]] call cTab_fnc_findUserMarker;
  14. */
  15. private["_return","_searchPos","_targetRadius","_maxDistance","_distance"];
  16. _return = -1;
  17. _searchPos = _this select 1;
  18. // figure out radius around cursor box based on map zoom and scale
  19. _targetRadius = cTabIconSize * 2 * (ctrlMapScale (_this select 0)) * cTabMapScaleFactor;
  20. _maxDistance = _searchPos distanceSqr [(_searchPos select 0) + _targetRadius,(_searchPos select 1) + _targetRadius];
  21. // find closest user marker within _maxDistance
  22. {
  23. _distance = _searchPos distanceSqr (_x select 1 select 0);
  24. if (_distance <= _maxDistance) then {
  25. _maxDistance = _distance;
  26. _return = _x select 0;
  27. };
  28. } count cTabUserMarkerList;
  29. _return