Thread Tools Display Modes
05/02/21, 12:03 AM   #1
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
GetZoom() example ?

Hi there,
I can't get MapDisplayControl:GetZoom() to work, can somebody provide an short code that doesn't return nil?
Thanks
  Reply With Quote
05/02/21, 08:15 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,959
You need to provide more information please:
1st: Why that function? What do you like to achieve, and when?
2nd: When do you call your code?
3rd: Your code example (complete addon or at least code that runs like an addon to be able to find your bug/problem)

btw: I think MapDisplayControl is not an existing variable ingame but just an "example name of an object/control used in the ESOUIDocumentation_Pxx.txt file, or the Wiki's control section". Did you try to inspect ZO_WorldMap with an addon like merTorchbug Updated or zgoo?
You can check the table shown if it contains the GetZoom function or maybe the __index metatables of it will have them.
Maybe this is the object which holds the functions for the zoom, and which should be used here.

Or try to use this function:
https://github.com/esoui/esoui/blob/...dmap.lua#L4505
ZO_WorldMap_GetPanAndZoom()
It will return the pointer to the local variable g_mapPanAndZoom
And this variable is of the type ZO_MapPanAndZoom
https://github.com/esoui/esoui/blob/...dmap.lua#L3181

So you got access to all the map's zoom functions via this function's return value.
You can find all the functions here:
https://github.com/esoui/esoui/blob/...dmap.lua#L2446
e.g. ZO_MapPanAndZoom:CanMapZoom etc.

Or via using merTorchbug ingame like this (open the map first):
Code:
/tb ZO_WorldMap_GetPanAndZoom()
It will open the torchbug inspecto returning you the table with all the data that ZO_MapPanAndZoom currently shows:

But it also provides the attribute like maxZoom, minZoom and currentNormalizedZoom which might be the value you search for.
If you change the zoom slider at the map and then reuse the /tb ZO_WorldMap_GetPanAndZoom() (or press the refresh button o at the headline of the torchbug inspector window) it will update the table and show you the new value of currentNormalizedZoom.
e.g. medium zoom at slider middle will be currentNormalizedZoom = 0.5




Not sure what your usecase it. This object does not seem to provide any GetZoom function. But there exist other ZO_WorldMap_Get* functions which might return objects you want to inspect and check if they provide that info needed.

Last edited by Baertram : 05/02/21 at 09:14 AM.
  Reply With Quote
05/02/21, 02:31 PM   #3
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
Thanks a lot, I will study all that!

indeed I want to display anchors only when zoomout is maxed
I think I saw a boolean for that somewhere...
  Reply With Quote
05/02/21, 03:19 PM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,959
Hacked this quickly together, maybe it helps
Lua Code:
  1. function MyAddon.GetMapZoom()
  2.     if not ZO_WorldMap_IsWorldMapShowing() then return end
  3.     local worldMapZoomData = ZO_WorldMap_GetPanAndZoom()
  4.     if worldMapZoomData then
  5.         return worldMapZoomData:GetCurrentNormalizedZoom()
  6.     end
  7.     return 0
  8. end

returns nil if map is closed
returns 0 if ZO_WorldMap_GetPanAndZoom is returning nil
returns the current normalized zoom level (e.g. 0.5 at half zoom) if map is shown

If you check for the returned value to be ~= nil and > 0 and == 1 hen you'll know it is at maximum value (as 1 should be the max zoom).

Or you simply check for ZO_WorldMap_GetPanAndZoom():CanZoomInFurther() == false -> no further zoom in means you are at max already

Last edited by Baertram : 05/02/21 at 03:27 PM.
  Reply With Quote
05/02/21, 11:26 PM   #5
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
Originally Posted by Baertram View Post
Hacked this quickly together, maybe it helps
Lua Code:
  1. function MyAddon.GetMapZoom()
  2.     if not ZO_WorldMap_IsWorldMapShowing() then return end
  3.     local worldMapZoomData = ZO_WorldMap_GetPanAndZoom()
  4.     if worldMapZoomData then
  5.         return worldMapZoomData:GetCurrentNormalizedZoom()
  6.     end
  7.     return 0
  8. end

returns nil if map is closed
returns 0 if ZO_WorldMap_GetPanAndZoom is returning nil
returns the current normalized zoom level (e.g. 0.5 at half zoom) if map is shown

If you check for the returned value to be ~= nil and > 0 and == 1 hen you'll know it is at maximum value (as 1 should be the max zoom).

Or you simply check for ZO_WorldMap_GetPanAndZoom():CanZoomInFurther() == false -> no further zoom in means you are at max already
Yep I did the later, indeed the problem was my LUA skills, but i'm learning fast
it doesn't work with parenthesis though, here is the working code snippet I use in my addon:
Lua Code:
  1. local g_mapPanAndZoom = ZO_WorldMap_GetPanAndZoom()
  2.       zoomMaxed = false
  3.     if g_mapPanAndZoom.canZoomOutFurther == false then
  4.       zoomMaxed = true
  5.     end
Thanks a lot for helping me
  Reply With Quote
05/03/21, 03:44 AM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,959
Maybe it's personal preference but you should use the Get Set functions of the ZO_WorldMap_GetPanAndZoom() object, in your case
g_mapPanAndZoom:CanZoomInFurther()
instead of directly using their attribute g_mapPanAndZoom.canZoomOutFurther
  Reply With Quote
05/03/21, 11:28 AM   #7
Marazota
AddOn Author - Click to view addons
Join Date: Sep 2015
Posts: 257
also try to look at TweakIt addon code, there was custom map zoom options i remember
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » GetZoom() example ?

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