ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   GetZoom() example ? (https://www.esoui.com/forums/showthread.php?t=9711)

Masteroshi430 05/02/21 12:03 AM

GetZoom() example ?
 
Hi there,
I can't get MapDisplayControl:GetZoom() to work, can somebody provide an short code that doesn't return nil?
Thanks :)

Baertram 05/02/21 08:15 AM

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.

Masteroshi430 05/02/21 02:31 PM

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...

Baertram 05/02/21 03:19 PM

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

Masteroshi430 05/02/21 11:26 PM

Quote:

Originally Posted by Baertram (Post 43827)
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 :)

Baertram 05/03/21 03:44 AM

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

Marazota 05/03/21 11:28 AM

also try to look at TweakIt addon code, there was custom map zoom options i remember


All times are GMT -6. The time now is 05:37 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI