May have gone a little overboard but this should increase performance significantly.
Edit: Decided to take out the comments after fixing it up; I'm clearly bad at explaining myself.
Lua Code:
local GetBestMapForUnit = C_Map.GetBestMapForUnit
local MapRects = {}
local mapID
local UnitPosition = UnitPosition
local GetWorldPosFromMapPos = C_Map.GetWorldPosFromMapPos
local CreateVector2D = CreateVector2D
local function GetPlayerMapPosition(mapid, token, rects, _, x, y)
if mapid then
rects = MapRects[mapid]
if not rects then
rects = {}
_, topleft = GetWorldPosFromMapPos(mapid, CreateVector2D(0,0))
_, bottomright = GetWorldPosFromMapPos(mapid, CreateVector2D(1,1))
bottomright:Subtract(topleft)
rects = { topleft.x, topleft.y, bottomright.x, bottomright.y }
MapRects[mapid] = rects
end
x, y = UnitPosition(token)
if x then
x, y = x - rects[1], y - rects[2]
return y / rects[4], x / rects[3]
else
return 0, 0
end
end
end
local function OnUpdate(self, elapsed, x, y)
if mapID then
x, y = GetPlayerMapPosition(mapID, 'player')
self.text:SetFormattedText('%.1f, %.1f', x*100, y*100)
end
end
tMinimapCoordsFrame:HookScript('OnUpdate', OnUpdate)
tMinimapCoordsFrame:HookScript('OnEvent', function(self, event, ...)
if event == 'PLAYER_STOPPED_MOVING' then
mapID = nil
elseif event ~= 'PLAYER_ENTERING_WORLD' then
mapID = GetBestMapForUnit('player')
else
mapID = GetBestMapForUnit('player')
OnUpdate(self)
self:UnregisterEvent('PLAYER_ENTERING_WORLD')
end
end)
tMinimapCoordsFrame:RegisterEvent('ZONE_CHANGED')
tMinimapCoordsFrame:RegisterEvent('ZONE_CHANGED_INDOORS')
tMinimapCoordsFrame:RegisterEvent('ZONE_CHANGED_NEW_AREA')
tMinimapCoordsFrame:RegisterEvent('PLAYER_ENTERING_WORLD')
tMinimapCoordsFrame:RegisterEvent('PLAYER_STOPPED_MOVING')
tMinimapCoordsFrame:RegisterEvent('PLAYER_STARTED_MOVING')