Here's my take on it. I would suggest trying to insert custom pins in the MapCanvas system, but I haven't dug around it ever since it was implemented. There isn't a way to delete UI objects without a logout or UI reload, so you have to create a pool of them by storing them in a table you grab from. There's no reason to loop through and hide the icons OnHide. The "cleanup" is handled with the next OnShow.
Lua Code:
local IconTextures={};-- Table to store our textures
local function MapTest_UpdateIcons()
local numshow=(amount_to_be_decided);
local textureindex=1;-- We increment this when we grab a texture
for index=1,numshow do
if (logic_to_be_decided) then
local icon=IconTextures[textureindex];-- Fetch texture from table
if not icon then-- Texture not created yet (We don't want gaps in the table or it'll mess with the table length operation we use later)
icon=WorldMapDetailFrame:CreateTexture(nil,"OVERLAY");
icon:SetTexture("Interface\\AddOns\\MapTest\\AvailableQuestIcon.blp");
icon:SetSize(16,16);
IconTextures[textureindex]=icon;-- Store in table
end
local width,height=WorldMapDetailFrame:GetSize();
icon:SetPoint("CENTER",WorldMapDetailFrame,"TOPLEFT",(XPos/100)*width,(YPos/100)*height);-- Move to coordinates
icon:Show();-- Show texture
textureindex=textureindex+1;-- Increment index
end
end
for index=textureindex,#IconTextures do-- Iterate through icons we haven't updated yet (textureindex will point to the first unused in the list, doesn't run if there are no unused textures (start > end))
IconTextures[index]:Hide();-- Hide them
end
end
WorldMapFrame:HookScript("OnShow",MapTest_UpdateIcons);-- Map Opened
WorldMapFrame:HookScript("OnSizeChanged",MapTest_UpdateIcons);-- Map Resized