As of version 1.07 the WN server does not require the NCSA
C imagemap.c
program to support clickable images. This
functionality is now built into the server. Try clicking on this image
for an example.
Clickable images like this make use of a "map file" telling the server which coordinates in the image correspond to which document. The format of this file (described below) is the same as that used with the NCSA imagemap program (with a few minor enhancements).
There are a number of image creation and editing programs that can be
used. One (which I have not tried) is xpaint. The
image file must be in png
, jpeg
or
xbm
format.
This is a file containing lines specifying regions in the image and the URL to which the client should be directed after clicking in one of these regions. The format of this file is described below in detail, but roughly a line contains the name of a shape (like a rectangle) the URL to go to and the pixel coordinates necessary to specify the rectangle.
There is a commercial program called mapedit and a free tcl/tk program mapmarker (neither of which I have used) that are designed to automate this task.
In the index file for the directory containing the image (let's call it
image.png
) put the lines:
File=image.png
File=image.map
Attributes=imagemap
If your imagemap file redirects the client to other documents on your
server make sure they are also installed. Run wndex
where necessary to
update your index.cache
.
Note: A file namedfoo.map
(i.e. with suffix ".map
") will automatically be considered to have "Attributes=imagemap
" set whenwndex
is run unless a "Content-type=something
" line is supplied for it.
This will also work if the "Attributes=serveall
"
directive is specified for this directory and there is no entry in the index.wn
file for
foo.map
. But it is necessary to run wndex
since the server will
not recognize foo.map
as an imagemap
file if wndex
has not been run on
the directory containing it.
In the HTML file which you want to contain the clickable image must put a link to it which looks like:
<a href="image.map">
<img src="image.png" ismap>
</a>
assuming that "image.map
", "image.png
" and the
file containing this link are all in the same directory.
An imagemap file is a plain text file consisting of lines, each of which tells the server what to do if a user clicks in a certain region. You will need to know the dimensions of your image and you will have to have a way of reading the coordinates of points on your image when you click on it. I use the program xv to determine the coordinates.
A complete functioning example of imagemap use, illustrating all the methods is included with the WN distribution.
An imagemap can contain comments which are lines starting with the
character '#
'. These lines are ignored by the server, as
are lines which are blank.
All other lines must start with one of the imagemap "method" keywords:
default
, rect
, circle
,
poly
,
or point
. Here is a
description of each type of method line.
default
keyword
This line contains only the keyword "default
" followed by
white space and the URL to be referenced if none of the other other
regions is selected. An example is:
default http://webhost/dir/default.html
rect
keyword
This line contains the keyword "rect
" followed by white
space and the URL to be referenced and more white space followed by the
coordinates of the upper left and lower right corners of the rectangle.
When the coordinates of the clicked on point lie within the rectangle
specified by these coordinates the given URL will be referenced. An
example is:
rect http://webhost/dir/rect.html 20,20 70,100
Note the coordinates of the rectangle corners consist of the X coordinate
(two numbers separated by a comma) followed by whitespace followed by the
Y coordinate (two more numbers separated by a comma). This URL will be
returned if the clicked on point lies in the rectangle with opposite
corners (20,20)
and (70,10)
. In screen
coordinates (as opposed to the Cartesian plane) these are the upper left
and lower right corners respectively.
circle
keyword
This line contains the keyword "circle
" followed by white
space and the URL to be referenced and more white space followed by the
coordinates of the center of the circle and the coordinates of a point on
the circle. When the coordinates of the clicked on point lie within the
circle specified by these coordinates the given URL will be referenced.
An example is:
circle http://webhost/dir/circle.html 70,70 70,100
This URL will be returned if the clicked on point lies in the the circle
with center at (70,70)
and radius 30
(i.e. the
circle with center (70,70)
containing the point
(70,100)
).
poly
keyword
This line contains the keyword "poly
" followed by white
space and the URL to be referenced and more white space followed by the a
sequence of coordinates of the vertices of a polygon, in order. The
polygon so determined is the one you would obtain by connecting each of
the vertices in order with a straight line and then connecting the last
vertex to the first. The polygon need not be convex.
Technical note: The curve formed in this way may cross itself -- a point will be considered inside if the winding number of the curve around the point is non-zero.
An example is:
poly http://webhost/dir/triangle.html 10,20 70,100 5,150
This URL will be returned if the clicked on point lies in the triangle
with vertices (10,20)
, (70,100)
and
(5,150)
.
point
keyword
This line contains the keyword "point
" followed by white
space and the URL to be referenced and more white space followed by the a
sequence of coordinates of one or more points in the the image. This
method replaces the default
. The default URL
referenced is the one associated with the point in a "point method" line
which is closest to the clicked location. An example is:
point http://webhost/dir/point1.html 10,20 70,100
point http://webhost/dir/point2.html 100,110 80,5
If no other method has returned a URL then the returned URL will be to
point1.html
or point2.html
depending on whether
the clicked on location is closer to one of the points
(10.20)
or (70,100)
or to one of the points
(100,110)
or (80,5)
.
Note: Allowing multiple points on a single point method line is a WN enhancement and will not be portable to other imagemap programs.
nocoords
keyword
This line contains the keyword "nocoords
" followed by white
space and the URL to be referenced when a user with a non-graphical
browser selects the the substitute text for the image. More precisely,
if any browser makes a request for the document and does not include the
X and Y coordinates of the point clicked on in the image then this URL
will be referenced. An example is:
nocoords http://webhost/dir/message.txt
Note: The nocoords
keyword and functionality is a
WN enhancement and will not be portable to other imagemap
programs.
The URL in the lines listed above can be in one of the following three forms:
http://remote_host/dir/rect.html
/dir/rect.html
rect.html
Here are the differences. The first,
"http://remote_host/dir/rect.html
" is primarily used to link
to a document on a remote host. On seeing this the server sends an HTTP/1.1 redirect to the client
causing the client to automatically access this URL.
The use of "/dir/rect.html
" is equivalent to
"http://local_host/dir/rect.html
". Any URL specified in a
method line which begins with a '/
' is assumed to be on the
local local host and the path is assumed relative to the WN root
directory. An HTTP/1.1
redirect is sent because simply sending the file would confuse the client
(it would think that the document rect.html
is in the same
directory as the imagemap file which might not be true in which case
relative URLs would fail to work).
Warning: The WN root directory is changed by use of
http://host/~user/
type URLs.
The use of "rect.html
" or anything which does not contain
':/
' (i.e. which does not start with http://...
or ftp://...
) and does not start with '/
'
causes the server to assume that the document is relative to the
directory containing the imagemap. In this case the server will
immediately serve that document with no redirection. This is the most
efficient way to set up an imagemap, but it requires that the response
files like "rect.html
" be in the same directory as the
imagemap file. There is one exception to this. If the relative URL
contains a '#
' the server prepends the appropriate path to
the URL and sends an HTTP/1.1
redirect to the client. This is necessary for the client to be able to
handle the "name" anchor indicated by the '#
'.
Note: Allowing relative URLs of this type is a WN enhancement and will not be portable to imagemap programs run on other servers. Also note that using a relative URL like "dir/rect.html
" referring to a document in a subdirectory can confuse a browser about the location of documents referred to in "rect.html
". For this reason it should only be used when the document is not an HTML document or contains a<base>
tag specifying its location.
There is one special URL which may be used in map files, namely
<null>
. It has the effect of not sending a redirect
or a document to the client but instead sending a header with status 204.
This instructs the client to do nothing and in particular not to reload
or alter the document it is displaying. For example, the line:
default <null>
in a map file will have the effect of making clicks in the default area behave as if the click had been somewhere outside the image, i.e. nothing will happen.
Note: the <null>
URL is a WN
enhancement and will not be portable to imagemap programs run on other
servers.