API:MapGetCoordinatesForPoint
From RoR Wiki
UI Lua API · Map functions
Version: WAR 1.4.8
Converts a position inside a map window into map coordinates (the coordinates of the place shown at that point).
x, y = MapGetCoordinatesForPoint(mapDisplayName, pointX, pointY)
Arguments
- mapDisplayName
string– Name of a MapDisplay window set up with CreateMapInstance.- pointX, pointY
number– Position inside the window, relative to its top-left corner, in unscaled interface units.
Returns
- x, y
number– Coordinates of that point on the map shown in the window. Nothing is returned if either coordinate would be 0 or less, for example when the point is outside the map.
Details
- This is the reverse of MapGetPointForCoordinates.
- If the window does not exist or is not a MapDisplay, an error is logged, and the conversion is still attempted with the given name. With an empty name, the window check is skipped.
- If the client's map data is not loaded, the function returns nothing.
- The stock world map divides the mouse offset by
InterfaceCore.GetResolutionScale()before calling it, and shows-when nothing is returned. - The function needs at least three arguments and only reads the last three.
Errors
These are written to the UI log; the call continues.
Error in function call 'MapGetCoordinatesForPoint': Display Window %s does not existError in function call 'MapGetCoordinatesForPoint': Display Window %s is not a MapDisplay
Example
From default/ea_worldmapwindow/source/zoneview.lua:
function EA_Window_WorldMap.UpdateCoordinates()
local mapPositionX, mapPositionY = WindowGetScreenPosition("EA_Window_WorldMapZoneViewMapDisplay")
local resolutionScale = InterfaceCore.GetResolutionScale()
local x, y = MapGetCoordinatesForPoint("EA_Window_WorldMapZoneViewMapDisplay",
(SystemData.MousePosition.x - mapPositionX) / resolutionScale,
(SystemData.MousePosition.y - mapPositionY) / resolutionScale)
if (x == nil) then
x = L"-"
end
...
