At first you will need to create custom pin type (group of pins) using this function:
Lua Code:
ZO_WorldMap_AddCustomPin(pinType, pinTypeAddCallback, pinTypeOnResizeCallback, pinLayoutData, pinTooltipCreator)
pinType = unique string that defines category of your pins eg. "My Addon's Pins"
pinTypeAddCallback = function(pinManager), it is called every time when map is changed and should create pins for given area.
pinTypeOnResizeCallback = function(pinManager, mapWidth, mapHeight), called every time when map is resized (zoomed). Usualy not defined (nil).
pinLayoutData = table with the following keys:
level: required, and must be >2. Pins with higher level will be drawn on the top of pins with lower level.
Example values:
points of interests = 50,
AvA objectives = 50-100
quests = 110
group members = 130
wayshrine = 140
player = 160
texture: required, can be string or function. Function can return just a background texture or background, pulse and glow texture.
Example values:
Lua Code:
"YourAddon/Icons/Icon.dds"
or
Lua Code:
function = GetTexture(pin)
local texture1 = "YourAddon/Icons/Icon1.dds"
local texture2 = "YourAddon/Icons/Icon2.dds"
local pinTypeId, pinTag = pin:GetPinTypeAndTag()
if pinTag == "some value" then
return texture1
else
return texture2
end
end
size: texture will be resized to square size*size. If not specified, default value is 20.
Example values:
point of interest = 40
quest pins = 32
player pin = 16
insetX,
insetY: size of transparent texture border, used to determine if mouse click hits this pin. No need to specify if you do not plan to handle mouse clicks.
minSize: if not specified, default value is 18.
minAreaSize:
showsPinAndArea: true/false
isAnimated: true/false
pinTooltipCreator = table with the following keys:
creator: function(pin) that creates tooltip - or I should say function that will be called when mouse is over the pin, it does not need to create tooltip.
tooltip: (nilable) tooltip control you want to use.
hasTooltip: (optional), function(pin) which returns true/false to enable/disable tooltip.
If used tooltip is ZO_KeepTooltip, ZO_MapLocationTooltip or InformationTooltip, it will be properly initialized before creator is called and after that will be tooltip anchored to the pinControl. If you use any other tooltip, you have to handle initialization and anchoring in creator or hasTooltip functions.
By default are all custom pins disabled, so the next step is to enable your pins:
Lua Code:
ZO_WorldMap_SetCustomPinEnabled(_G[pinType], true)
Beacause map is not changed when you log into the game or after /reloadui, you have to manually refresh pins for the current map:
Lua Code:
ZO_WorldMap_RefreshCustomPinsOfType(_G[pinType])
Sample code:
Lua Code:
local pinType = "My unique name for pin type"
--sample data
local pinData = {
["auridon"] = { --Auridon, Khenarthi's Roost
["skywatch_base"] = {
{ x = 0.5, y = 0.6 },
},
},
["main"] = { --Main quest maps
["hallsoftorment1_base"] = {
{ x = 0.256, y = 0.361 },
},
},
}
--sample layout
local pinLayoutData = {
level = 50,
texture = "EsoUI/Art/MapPins/hostile_pin.dds",
size = 24,
}
--tooltip creator
local pinTooltipCreator = {
creator = function(pin)
local locX, locY = pin:GetNormalizedPosition()
InformationTooltip:AddLine(zo_strformat("Position of my pin is: <<1>>,<<2>>", locX*1000, locY*1000))
end,
tooltip = InformationTooltip,
}
--add callback function
local function pinTypeAddCallback(pinManager)
--do not create pins if your pinType is not enabled
if not ZO_WorldMap_IsCustomPinEnabled(_G[pinType]) then return end
--do not create pins on world, alliance and cosmic maps
if (GetMapType() > MAPTYPE_ZONE) then return end
local textureName = GetMapTileTexture()
textureName = string.lower(textureName)
local _,_,_,zone,subzone = string.find(textureName, "(maps/)([%w%-]+)/([%w%-]+_%w+)")
local pins
if pinData[zone] and pinData[zone][subzone] then
pins = pinData[zone][subzone]
else
return --return if no data for current map
end
for _, pinInfo in ipairs(pins) do
--ZO_WorldMapPins:CreatePin(pinTypeId, pinTag, locX, locY, areaRadius)
--pinTag can be anything, but I recommend using table or string with additional info about pin, you can use it later in code
pinManager:CreatePin(_G[pinType], pinInfo, pinInfo.x, pinInfo.y)
end
end
--resize callback function (usualy just nil)
local function pinTypeOnResizeCallback(pinManager, mapWidth, mapHeight)
local visibleWidth, visibleHeight = ZO_WorldMapScroll:GetDimensions()
local currentZoom = mapWidth / visibleWidth
if currentZoom < 1.5 then
ZO_WorldMap_SetCustomPinEnabled(_G[pinType], false)
else
ZO_WorldMap_SetCustomPinEnabled(_G[pinType], true)
end
ZO_WorldMap_RefreshCustomPinsOfType(_G[pinType])
end
local function OnLoad(eventCode, name)
if name ~= "MyAddon" then return end
--initialize map pins
ZO_WorldMap_AddCustomPin(pinType, pinTypeAddCallback, pinTypeOnResizeCallback, pinLayoutData, pinTooltipCreator)
--custom pins are disabled by default, you have to enable them
ZO_WorldMap_SetCustomPinEnabled(_G[pinType], true)
--force refresh pins to call pinTypeAddCalback for the current map
ZO_WorldMap_RefreshCustomPinsOfType(_G[pinType])
EVENT_MANAGER:UnregisterForEvent("MyAddon_OnLoad", EVENT_ADD_ON_LOADED)
end
EVENT_MANAGER:RegisterForEvent("MyAddon_OnLoad", EVENT_ADD_ON_LOADED, OnLoad)