Thread Tools Display Modes
05/18/14, 06:19 PM   #1
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
How to create map pins

At first you will need to create custom pin type (group of pins) using this function:
Lua Code:
  1. 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:
  1. "YourAddon/Icons/Icon.dds"
or
Lua Code:
  1. function = GetTexture(pin)
  2.    local texture1 = "YourAddon/Icons/Icon1.dds"
  3.    local texture2 = "YourAddon/Icons/Icon2.dds"
  4.    local pinTypeId, pinTag = pin:GetPinTypeAndTag()
  5.    if pinTag == "some value" then
  6.       return texture1
  7.    else
  8.       return texture2
  9.    end
  10. 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:
  1. 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:
  1. ZO_WorldMap_RefreshCustomPinsOfType(_G[pinType])


Sample code:
Lua Code:
  1. local pinType = "My unique name for pin type"
  2.  
  3. --sample data
  4. local pinData = {
  5.    ["auridon"] = {      --Auridon, Khenarthi's Roost
  6.       ["skywatch_base"] = {
  7.          { x = 0.5, y = 0.6 },
  8.       },      
  9.    },
  10.    ["main"] = {         --Main quest maps
  11.       ["hallsoftorment1_base"] = {
  12.          { x = 0.256, y = 0.361 },
  13.       },
  14.    },
  15. }
  16.  
  17. --sample layout
  18. local pinLayoutData  = {
  19.    level = 50,
  20.    texture = "EsoUI/Art/MapPins/hostile_pin.dds",
  21.    size = 24,
  22. }
  23.  
  24. --tooltip creator
  25. local pinTooltipCreator = {
  26.    creator = function(pin)
  27.       local locX, locY = pin:GetNormalizedPosition()
  28.       InformationTooltip:AddLine(zo_strformat("Position of my pin is: <<1>>,<<2>>", locX*1000, locY*1000))
  29.    end,
  30.    tooltip = InformationTooltip,
  31. }
  32.  
  33. --add callback function
  34. local function pinTypeAddCallback(pinManager)
  35.    --do not create pins if your pinType is not enabled
  36.    if not ZO_WorldMap_IsCustomPinEnabled(_G[pinType]) then return end
  37.    --do not create pins on world, alliance and cosmic maps
  38.    if (GetMapType() > MAPTYPE_ZONE) then return end
  39.  
  40.    local textureName = GetMapTileTexture()
  41.    textureName = string.lower(textureName)
  42.    local _,_,_,zone,subzone = string.find(textureName, "(maps/)([%w%-]+)/([%w%-]+_%w+)")
  43.    local pins
  44.  
  45.    if pinData[zone] and pinData[zone][subzone] then
  46.       pins = pinData[zone][subzone]
  47.    else
  48.       return         --return if no data for current map
  49.    end
  50.  
  51.    for _, pinInfo in ipairs(pins) do
  52.       --ZO_WorldMapPins:CreatePin(pinTypeId, pinTag, locX, locY, areaRadius)
  53.       --pinTag can be anything, but I recommend using table or string with additional info about pin, you can use it later in code
  54.       pinManager:CreatePin(_G[pinType], pinInfo, pinInfo.x, pinInfo.y)
  55.    end
  56. end
  57.  
  58. --resize callback function (usualy just nil)
  59. local function pinTypeOnResizeCallback(pinManager, mapWidth, mapHeight)
  60.    local visibleWidth, visibleHeight = ZO_WorldMapScroll:GetDimensions()
  61.    local currentZoom = mapWidth / visibleWidth
  62.    
  63.    if currentZoom < 1.5 then
  64.       ZO_WorldMap_SetCustomPinEnabled(_G[pinType], false)
  65.    else
  66.       ZO_WorldMap_SetCustomPinEnabled(_G[pinType], true)
  67.    end
  68.  
  69.    ZO_WorldMap_RefreshCustomPinsOfType(_G[pinType])
  70. end
  71.  
  72. local function OnLoad(eventCode, name)
  73.    if name ~= "MyAddon" then return end
  74.  
  75.    --initialize map pins
  76.    ZO_WorldMap_AddCustomPin(pinType, pinTypeAddCallback, pinTypeOnResizeCallback, pinLayoutData, pinTooltipCreator)
  77.    --custom pins are disabled by default, you have to enable them
  78.    ZO_WorldMap_SetCustomPinEnabled(_G[pinType], true)
  79.    --force refresh pins to call pinTypeAddCalback for the current map
  80.    ZO_WorldMap_RefreshCustomPinsOfType(_G[pinType])
  81.  
  82.    EVENT_MANAGER:UnregisterForEvent("MyAddon_OnLoad", EVENT_ADD_ON_LOADED)
  83. end
  84.  
  85. EVENT_MANAGER:RegisterForEvent("MyAddon_OnLoad", EVENT_ADD_ON_LOADED, OnLoad)

Last edited by Garkin : 05/31/14 at 02:31 PM. Reason: Added more about pinTooltipCreator
  Reply With Quote
05/18/14, 06:24 PM   #2
Kentarii
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 42
Awesome, thanks for the write-up!
  Reply With Quote
05/19/14, 02:35 PM   #3
dwot
 
dwot's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 3
Thumbs up

Once again, Garkin FTW!
  Reply With Quote
05/20/14, 03:37 PM   #4
skyraker
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 154
May want to incorporate this into the wiki also.
  Reply With Quote
05/21/14, 02:50 AM   #5
Kentarii
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 42
Found a typo, textue:
Lua Code:
  1. ..edit..

Shouldn't this:
Lua Code:
  1. ..edit..
Be like this, with _G?
Lua Code:
  1. ..edit..

Thanks again, I'm almost done adding mappins to my Quest Journal

Last edited by Kentarii : 05/21/14 at 04:59 AM. Reason: Removed code to not confuse future readers
  Reply With Quote
05/21/14, 04:49 AM   #6
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Kentarii View Post
Found a typo, textue:
...
You are right, both errors fixed in my post. I have never tried to actually use that code...
  Reply With Quote

ESOUI » Developer Discussions » Tutorials & Other Helpful Info » How to create map pins

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off