If you are trying to build an overlay over the entire map frame (its borders, UI elements, etc.), then something like this might help:
Lua Code:
local function myFunction()
local isMaximized = WorldMapFrame:IsMaximized()
-- do something
end
hooksecurefunc(WorldMapFrame.BorderFrame.MaximizeMinimizeFrame, "Maximize", myFunction)
hooksecurefunc(WorldMapFrame.BorderFrame.MaximizeMinimizeFrame, "Minimize", myFunction)
If you are trying to build something on the map canvas itself which appears at an x/y coordinate and can be dragged to another x/y coordinate, then you should take a look at
MapCanvas_DataProviderBase.lua.
Lua Code:
MyAddonSavedVariables = { }
MyPinMixin = CreateFromMixins(MapCanvasPinMixin)
MyPinMixin:OnAcquired(id, x, y)
self:SetPosition(x,y)
self.id = id
end
MyPinMixin:OnLoad()
-- placeholder appearance for testing
self:SetSize(20, 20)
self.texture = self:CreateTexture(nil, "ARTWORK")
self.texture:SetTexture("Interface\\RaidFrame\\UI-RaidFrame-Threat")
self.texture:SetAllPoints()
-- draggable to a new map coordinate
self:RegisterForDrag("RightButton")
self:HookScript("OnDragEnd", function()
local x, y = self:GetMap():GetNormalizedCursorPosition()
x = x and Clamp(x, 0.05, 0.95) or 0.5 -- stay a little inside the box
y = y and Clamp(y, 0.05, 0.95) or 0.5
MyAddonSavedVariables[self.id]["x"] = x
MyAddonSavedVariables[self.id]["y"] = y
self:SetPosition(x,y)
end)
end
MyDataProvider = CreateFromMixins(MapCanvasDataProviderMixin)
MyDataProvider:RefreshAllData()
self:RemoveAllData()
for id, coords in ipairs(MyAddonSavedVariables) do
self:GetMap():AcquirePin("MyPinTemplate", id, coords.x, coords.y)
end
end
WorldMapFrame:AddDataProvider(MyDataProvider)
-- placeholder just to create a single pin for testing
local listener = CreateFrame("Frame")
listener:RegisterEvent("PLAYER_LOGIN")
listener:SetScript("OnEvent", function()
if #MyAddonSavedVariables == 0 then
tinsert(MyAddonSavedVariables, {0.5, 0.5})
end
end)
XML Code:
<Ui>
<Frame name="MyPinTemplate" mixin="MyPinMixin" virtual="true"></Frame>
</Ui>
toc Code:
## SavedVariables: MyAddonSavedVariables
Disclaimer: I just quickly wrote this together by taking snippets of a much longer file. I'm probably missing something to make it work.