I created and maintain the official HTML Legend demo for MapServer, and you can find all of the examples at https://demo.mapserver.org/itasca_legend/ (I had updated it all this morning, when I responded to your question on the mapserver-users list)
I should also mention that the full HTML Legend HowTo document lives at: https://mapserver.org/output/html_legend.html
At the bottom of each example page in the HTML Legend demo (https://demo.mapserver.org/itasca_legend/), you will see the template code, which is the contents of the TEMPLATE file referenced in the LEGEND section of the mapfile.
In your case, mylegend.html
would contain only the following text:
[leg_class_html opt_flag=15]
<img src=[leg_icon]> [leg_class_name]<br>
[/leg_class_html]
And your mylayer.map
would point to that template, within the LEGEND object, such as:
# LEGEND object
LEGEND
STATUS ON
KEYSIZE 18 12
# LABEL object
LABEL
TYPE BITMAP
SIZE MEDIUM
COLOR 0 0 89
END
TEMPLATE "mylegend.html" ### HTML template file
END
(you don't need a file named mylegend.map
)
You can actually test this by using MapServer's legend
commandline utility (or legend.exe
if you are using MS4W/Windows). Call the command to generate your legend image, such as:
setenv.bat (for MS4W users)
legend.exe mylayer.map mylegend.png
The full working mapfile and HTML legend files for this demo will soon be included for all MS4W installations, as well (I'm working on the big MS4W 5.0 release, so this makes sense to include).
Update on 2024-09-30: MS4W 5.0 is now available, containing the "MapServer HTML Legends Demo" that works out-of-the-box for all MS4W installations.