.. Author: Bu Kun .. Title: Interactive map and Browse mode Interactive Map and Browse Model ================================ View examples ------------- .. raw:: html The map above is in ``map`` Generated in mode. It is a static map (nothing changes when you click). But open the map below and you can use mouse clicks to interoperate. http://webgis.pub / cgi-bin/mapserv?map=/owg/mdc1.map&layer=states_line&layer=topo&mode=browse Submit CGI variables using Post form ------------------------------------ Previously, you put all the parameters needed by MapServer in URL, which is the way to use parameters explicitly, but it can cause the URL to become very long. Instruction ~~~~~~~~~~~ Another way is to use a form to submit parameters. Here is a form: .. raw:: html
POST form ~~~~~~~~~ This part of the code is as follows ::
With POST submission, the parameters need to be placed in the form. .. raw:: html Mapfile and template file description ------------------------------------- Mapfile description ~~~~~~~~~~~~~~~~~~~ Now, take a look at Mapfile: .. literalinclude:: ./mfc1.map :lineno-start: 1 Compared to static maps, only the following line is actually added to Mapfile: :: TEMPLATE 'example1-9.html' This tells MapServer to use the page ``example1-9.html`` as the template file. MapServer will process this file and replace the tags it encounters before sending it to the web browser. This is the mechanism by which MapServer implements dynamic pages. The above code snippet defines the parameters of the Web object, starting with the keyword ``WEB`` and ending with the keyword ``END``. The ``WEB`` object tells the map server the name of the HTML template file (in this case, only one, named ``example1-9.html`` ), the paths to the images to create, and the URLs to point to those images. As before, IMAGEPATH specifies the path to images created by MapServer. In this case you use absolute paths, but you can also use relative paths from the location of the mapfile. Note that you cannot remove the leading or final slash ``/`` from the IMAGEURL. The string defined by IMAGEURL is appended to the base URL (ie, http://localhost ) to generate the URL for the image rendered on the page. Note that if you’re not sure about the importance of ``/``, or what Apache’s ``DocumentRoot`` is, you can look it up at http://httpd.apache.org/docs/mod/core.html#documentroot. HTML file ~~~~~~~~~ In the template file, in addition to the HTML text content, the key is the form code block within this page (right-click on your browser page and select “View Source” or something similar): Now, let’s build an interactive interface for our application. The following shows the use of a form for submission, with various parameters passed through the input control. ::
Each time the user clicks the map, this block executes the MapServer CGI program ( ``/cgi-bin/mapserv`` ). The program here can be defined using the following: :: The following two variables are user-defined variables. If it finds the correct tag within square brackets ``[]``, MapServer will pass its value to the HTML template. ``map`` And ``layer`` Variables are MapServer internal variables. They are required for MapServer mapping applications. ::