<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://war.app/index.php?action=history&amp;feed=atom&amp;title=Mod_API_Reference%3AClient_MapLayers</id>
	<title>Mod API Reference:Client MapLayers - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://war.app/index.php?action=history&amp;feed=atom&amp;title=Mod_API_Reference%3AClient_MapLayers"/>
	<link rel="alternate" type="text/html" href="https://war.app/wiki/index.php?title=Mod_API_Reference:Client_MapLayers&amp;action=history"/>
	<updated>2026-11-04T15:04:56Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://war.app/wiki/index.php?title=Mod_API_Reference:Client_MapLayers&amp;diff=8047&amp;oldid=prev</id>
		<title>Fizzer: Created page with &quot; Put the function in a file named &lt;code&gt;Client_MapLayers.lua&lt;/code&gt;:  &lt;pre&gt; function Client_MapLayers(game, layers)     local layer = layers.Create(&#039;Territory IDs&#039;, true);     for terrID, _ in pairs(game.Map.Territories) do         layer.AddLabel(terrID, tostring(terrID));     end end &lt;/pre&gt;  Client_Visual draws a visual for one order. This hook instead draws &#039;&#039;&#039;map layers&#039;&#039;&#039;: labels and shapes that stay on the map for as long as the g...&quot;</title>
		<link rel="alternate" type="text/html" href="https://war.app/wiki/index.php?title=Mod_API_Reference:Client_MapLayers&amp;diff=8047&amp;oldid=prev"/>
		<updated>2026-11-02T10:54:34Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; Put the function in a file named &amp;lt;code&amp;gt;Client_MapLayers.lua&amp;lt;/code&amp;gt;:  &amp;lt;pre&amp;gt; function Client_MapLayers(game, layers)     local layer = layers.Create(&amp;#039;Territory IDs&amp;#039;, true);     for terrID, _ in pairs(game.Map.Territories) do         layer.AddLabel(terrID, tostring(terrID));     end end &amp;lt;/pre&amp;gt;  &lt;a href=&quot;/wiki/Mod_API_Reference:Client_Visual&quot; title=&quot;Mod API Reference:Client Visual&quot;&gt;Client_Visual&lt;/a&gt; draws a visual for one order. This hook instead draws &amp;#039;&amp;#039;&amp;#039;map layers&amp;#039;&amp;#039;&amp;#039;: labels and shapes that stay on the map for as long as the g...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
Put the function in a file named &amp;lt;code&amp;gt;Client_MapLayers.lua&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function Client_MapLayers(game, layers)&lt;br /&gt;
    local layer = layers.Create(&amp;#039;Territory IDs&amp;#039;, true);&lt;br /&gt;
    for terrID, _ in pairs(game.Map.Territories) do&lt;br /&gt;
        layer.AddLabel(terrID, tostring(terrID));&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Mod API Reference:Client Visual|Client_Visual]] draws a visual for one order. This hook instead draws &amp;#039;&amp;#039;&amp;#039;map layers&amp;#039;&amp;#039;&amp;#039;: labels and shapes that stay on the map for as long as the game is open. Examples are territory IDs, zones of control, or a mod&amp;#039;s own borders.&lt;br /&gt;
&lt;br /&gt;
Players turn each layer on or off with checkboxes in a &amp;quot;Map layers&amp;quot; dialog, which opens from a button in the game&amp;#039;s menu. That button only appears in games where a mod created at least one layer. The device remembers each player&amp;#039;s choice for each mod and layer name.&lt;br /&gt;
&lt;br /&gt;
The client calls the hook when the game loads and every time it refreshes, and redraws the layers each time. Turning a layer on or off doesn&amp;#039;t run the hook again.&lt;br /&gt;
&lt;br /&gt;
Layers are drawn above territories and bonus links, and below army numbers.&lt;br /&gt;
&lt;br /&gt;
Like Client_Visual, layers are shown in the app and on the website in 3D mode, but not on the website in 2D mode. In 2D mode, the &amp;quot;Map layers&amp;quot; dialog says that layers aren&amp;#039;t supported.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Argument !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;game&amp;lt;/code&amp;gt; || [[Mod API Reference:ClientGame|ClientGame]] || Information about the game.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;layers&amp;lt;/code&amp;gt; || table || The object you create layers with. See below.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== layers.Create ===&lt;br /&gt;
&amp;lt;code&amp;gt;layers.Create(name, defaultVisible)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Creates a layer and returns it.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;name&amp;#039;&amp;#039;&amp;#039;: the name shown next to the layer&amp;#039;s checkbox, under your mod&amp;#039;s name. Names are cut to 50 characters. Creating a layer with a name you&amp;#039;ve already used in this call returns that same layer, so you can add to it from several places.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;defaultVisible&amp;#039;&amp;#039;&amp;#039;: whether the layer is shown before the player has changed its checkbox. Optional; defaults to true.&lt;br /&gt;
&lt;br /&gt;
A mod can create up to 10 layers.&lt;br /&gt;
&lt;br /&gt;
=== layer.AddLabel ===&lt;br /&gt;
&amp;lt;code&amp;gt;layer.AddLabel(territoryID, text, options)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adds a text label at a territory&amp;#039;s middle point. It returns the layer, so calls can be chained.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;territoryID&amp;#039;&amp;#039;&amp;#039;: the territory to put the label on.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;text&amp;#039;&amp;#039;&amp;#039;: the text to show. Text is cut to 100 characters.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;options&amp;#039;&amp;#039;&amp;#039;: optional. A table with any of these fields:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field !! Default !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FontSize&amp;lt;/code&amp;gt; || 10 || The size of the text, from 4 to 40.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FillColor&amp;lt;/code&amp;gt; || 0 (black) || The color of the text, as a number in the form &amp;lt;code&amp;gt;0xRRGGBB&amp;lt;/code&amp;gt;, such as &amp;lt;code&amp;gt;0xFF0000&amp;lt;/code&amp;gt; for red.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;OffsetX&amp;lt;/code&amp;gt; || 0 || How far right of the territory&amp;#039;s middle to put the label, in map units.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;OffsetY&amp;lt;/code&amp;gt; || -18 || How far below the territory&amp;#039;s middle to put the label, in map units. The default puts it just above the army number.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
A layer can have up to 1000 labels.&lt;br /&gt;
&lt;br /&gt;
=== layer.AddShape ===&lt;br /&gt;
&amp;lt;code&amp;gt;layer.AddShape()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adds a shape and returns an object with the same functions as the &amp;lt;code&amp;gt;visual&amp;lt;/code&amp;gt; object in [[Mod API Reference:Client Visual|Client_Visual]]:&lt;br /&gt;
* SetVertices, SetTriangles and SetColors&lt;br /&gt;
* SetFrames, SetRestTime and SetDepthTest&lt;br /&gt;
* SetAnchorTerritory and SetAnchorPoint&lt;br /&gt;
&lt;br /&gt;
Shapes don&amp;#039;t animate. A shape is drawn at its rest pose: the pose at the time given to SetRestTime, which defaults to 1 (the last frame). For a shape that doesn&amp;#039;t change, SetVertices is simplest.&lt;br /&gt;
&lt;br /&gt;
A layer can have up to 200 shapes. Problems with a shape are written to the mod log, the same as for Client_Visual. A shape that can&amp;#039;t be drawn, such as one with a triangle index past the last vertex, is skipped.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- a green square on each of the player&amp;#039;s territories, hidden until the player turns it on&lt;br /&gt;
if (game.Us ~= nil) then&lt;br /&gt;
    local mine = layers.Create(&amp;#039;My territories&amp;#039;, false);&lt;br /&gt;
    for terrID, standing in pairs(game.LatestStanding.Territories) do&lt;br /&gt;
        if (standing.OwnerPlayerID == game.Us.ID) then&lt;br /&gt;
            mine.AddShape()&lt;br /&gt;
                .SetAnchorTerritory(terrID)&lt;br /&gt;
                .SetVertices({ {-8, -8}, {8, -8}, {8, 8}, {-8, 8} })&lt;br /&gt;
                .SetTriangles({ 1, 2, 3, 1, 3, 4 })&lt;br /&gt;
                .SetColors(&amp;#039;#8000FF00&amp;#039;);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fizzer</name></author>
	</entry>
</feed>