Hello World
MapClient's first principles are shown in
- window.js is included in the header
- all other code is written inside the <body> tags
- "win" is the fundamental object.
A window is initilized as:
w = new win(left,top,width, height, name). After that, w can be used as
a regular JavaScript variable. It has lots of internal variables and
functions (a.k.a. properties and methods) to set its behavior.
The most important are:
- setServerURL(url): the URL the MapServer CGI is called with
- setVar(name,value): a pair of MapServer directives.
- submit(): sends a request for a map to a MapServer WebServer,
together with all defined CGI variables.
All Mapserver
and
variables can be set this way. In this example, only
the name of the MapFile and the size of the map are set.
After a "submit()", the results
will be put in the windows's display frame.
.
All variables are persistent;
submitting a second time will send the variables again.
Adding or changing one
variable will send it together with the original set.
In the example, The submit() function is actually executed by
a very short user function "submitWin()". This function has been
assigned to the
button. It does one other thing besides submitting: it
sets the CGI variable mapsize (which sets the physical size of the image)
to the actual width and height of the window,
using the win properties contentWidth and contentHeight.
This same "submitWin()" function is automatically called when the window
is resized. We arrange this by the win method "setExecOnResize()"
.
There are many more of these so-called
"callback" functions in MapClient. It is not an easy concept, but it
is fundamental to everything that happens in MapClient..