-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsection2.html
More file actions
299 lines (231 loc) · 16 KB
/
section2.html
File metadata and controls
299 lines (231 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<!DOCTYPE html>
<html lang="el" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Section 2: CGI variables and the User Interface — MapServer 8.6.2 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="../_static/sphinx.css?v=48f05237" />
<link rel="stylesheet" type="text/css" href="../_static/copybutton.css?v=76b2166b" />
<link rel="stylesheet" type="text/css" href="../_static/sphinx_collapse.css?v=226d88b4" />
<link rel="stylesheet" type="text/css" href="../_static/custom.css?v=dd298242" />
<link rel="stylesheet" type="text/css" href="../_static/ribbon.css?v=ea091bf4" />
<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=84745c96"></script>
<script src="../_static/doctools.js?v=fd6eb6e6"></script>
<script src="../_static/sphinx_highlight.js?v=6ffebe34"></script>
<script src="../_static/clipboard.min.js?v=a7894cd8"></script>
<script src="../_static/copybutton.js?v=f281be69"></script>
<script src="../_static/translations.js?v=e109e2be"></script>
<link rel="icon" href="../_static/mapserver.ico"/>
<link rel="author" title="Σχετικά με αυτά τα κείμενα" href="../about.html" />
<link rel="index" title="Ευρετήριο" href="../genindex.html" />
<link rel="search" title="Αναζήτηση" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="Section 3: Query and more about HTML Templates" href="section3.html" />
<link rel="prev" title="Section 1: Static Maps and the MapFile" href="section1.html" />
</head><body>
<!-- for main branch only, do not backport this -->
<table width="100%" style="width: 100%; background-color: white;">
<tr>
<td rowspan="2" style="padding: 10px 0px 10px 10px;">
<a href="../index.html" title="Home"><img src="../_static/banner.png" alt="MapServer banner" border="0" /></a>
</td>
<td style="padding: 10px 10px 0px 0px; text-align: right; vertical-align: top;">
<a href="../index.html" title="Home">Home</a> |
<a href="../products.html" title="Products (MapServer core, MapCache, TinyOWS">Products</a> |
<a href="https://github.com/mapserver/mapserver/issues/" title="Issue Tracker (MapServer core)">Issue Tracker</a> |
<a href="../community/service_providers.html" title="Professional Service Providers">Service Providers</a> |
<a href="../faq.html" title="Frequently Asked Questions">FAQ</a> |
<a href="https://fosstodon.org/@mapserver" title="Mastodon" target="_blank">Mastodon</a> |
<a href="../download.html" title="Download Source or Binaries">Download </a> |
<a class="badge" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KRJ2X44N3HA6U&source=url" target="_blank">
<img src="https://img.shields.io/badge/donate-%E2%9D%A4%C2%A0-ff69b4.svg?style=flat" alt="Donate to MapServer">
</a>
</td>
</tr>
<tr>
<td style="padding: 0px 10px 0px 0px; text-align: right; vertical-align: bottom;">
<a href="../../tutorial/section2.html"><img src="../_static/flagicons/en.png" alt="en" title="en" border="0" /></a>
<a href="../../ar/tutorial/section2.html"><img src="../_static/flagicons/ar.png" alt="ar" title="ar" border="0" /></a>
<a href="../../de/tutorial/section2.html"><img src="../_static/flagicons/de.png" alt="de" title="de" border="0" /></a>
<img src="../_static/flagicons/el.png" alt="el" title="el" border="0" width="18px" height="13px"/>
<a href="../../es/tutorial/section2.html"><img src="../_static/flagicons/es.png" alt="es" title="es" border="0" /></a>
<a href="../../fr/tutorial/section2.html"><img src="../_static/flagicons/fr.png" alt="fr" title="fr" border="0" /></a>
<a href="../../id/tutorial/section2.html"><img src="../_static/flagicons/id.png" alt="id" title="id" border="0" /></a>
<a href="../../it/tutorial/section2.html"><img src="../_static/flagicons/it.png" alt="it" title="it" border="0" /></a>
<a href="../../ja/tutorial/section2.html"><img src="../_static/flagicons/ja.png" alt="ja" title="ja" border="0" /></a>
<a href="../../nl_NL/tutorial/section2.html"><img src="../_static/flagicons/nl_NL.png" alt="nl_NL" title="nl_NL" border="0" /></a>
<a href="../../pl/tutorial/section2.html"><img src="../_static/flagicons/pl.png" alt="pl" title="pl" border="0" /></a>
<a href="../../ru/tutorial/section2.html"><img src="../_static/flagicons/ru.png" alt="ru" title="ru" border="0" /></a>
<a href="../../sq/tutorial/section2.html"><img src="../_static/flagicons/sq.png" alt="sq" title="sq" border="0" /></a>
<a href="../../tr/tutorial/section2.html"><img src="../_static/flagicons/tr.png" alt="tr" title="tr" border="0" /></a>
</td>
</tr>
</table>
<div class="related" role="navigation" aria-label="Related">
<h3>Πλοήγηση</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="Κεντρικό Ευρετήριοο"
accesskey="I">ευρετήριο</a></li>
<li class="right" >
<a href="section3.html" title="Section 3: Query and more about HTML Templates"
accesskey="N">επόμενο</a> |</li>
<li class="right" >
<a href="section1.html" title="Section 1: Static Maps and the MapFile"
accesskey="P">προηγούμενο</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Home</a> »</li>
<li class="nav-item nav-item-1"><a href="../documentation.html" >MapServer 8.6.2 Documentation</a> »</li>
<li class="nav-item nav-item-2"><a href="index.html" accesskey="U">MapServer Tutorial</a> »</li>
<li class="nav-item nav-item-this"><a href="">Section 2: CGI variables and the User Interface</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="section-2-cgi-variables-and-the-user-interface">
<span id="tutorial-section2"></span><h1>Section 2: CGI variables and the User Interface<a class="headerlink" href="#section-2-cgi-variables-and-the-user-interface" title="Link to this heading">¶</a></h1>
<p>So far we have only looked at the mapfile when creating maps. In
creating web mapping applications, it is usually our intention to make
maps that can be changed by the user (of the application)
interactively. That is, a user should be able to change the content of
(or the information in) the map. To accomplish this interactivity, we
use the MapServer HTML templates.</p>
<section id="html-templates">
<h2>HTML Templates<a class="headerlink" href="#html-templates" title="Link to this heading">¶</a></h2>
<p>A MapServer HTML template is essentially an HTML file with a few
MapServer specific tags. These tags are the MapServer CGI variables
and are enclosed in square brackets «[]». When the MapServer CGI
program processes an application, it first parses the query string and
the mapfile, and produces the necessary output. Some of this output
will need to be written to the HTML template file which you would have
to also specify in the mapfile using the web template keyword (or in a
separate HTML initialization file). The CGI program will replace all
the variables in the HTML template with the proper value before
sending it back to the web browser. If you are to directly view an
HTML template in a web browser, there won’t be any maps rendered and
you will instead get blank images and other junk.</p>
<section id="variables">
<h3>Variables<a class="headerlink" href="#variables" title="Link to this heading">¶</a></h3>
<p>MapServer provides several variables for web mapping: the «img»
variable which you’ve seen in Example 1.9 is but one example. There
area few core CGI variables originally designed as part of the mapping
interface but practically all the mapfile parameters can be defined as
variables. The definitive reference to the MapServer CGI variables can
be found <a class="reference internal" href="../cgi/index.html#cgi"><span class="std std-ref">here</span></a>.</p>
<p>We can also define our own variables, which MapServer will pass along
to our application. For example, we can create a variable called
«root» to represent the root directory of this tutorial, the value for
«root» will then be «/tutorial». When the MapServer CGI program
processes our HTML template, it will replace every instance of he
«[root]» tag with «/tutorial». You will see this in action for each of
the following examples.</p>
</section>
<section id="run-time-substitution">
<h3>Run-time Substitution<a class="headerlink" href="#run-time-substitution" title="Link to this heading">¶</a></h3>
<p>Since MapServer 8.0.1, this tutorial uses MapServer’s <a class="reference internal" href="../cgi/runsub.html#runsub"><span class="std std-ref">Run-time Substitution</span></a> to pass the
template name through the url, such as <cite>…&template=example2-2.html</cite>. The
associated mapfile’s WEB object contains a <cite>%template%</cite> variable, and a VALIDATION
object with a regular expression to allow the «<cite>template=</cite>» variable’s possible
values through the url.</p>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">WEB</span>
<span class="k">TEMPLATE</span> <span class="s">'%template%'</span>
<span class="p">...</span>
<span class="k">VALIDATION</span>
<span class="s">"template"</span> <span class="s">"example2*"</span>
<span class="k">END</span>
<span class="k">END</span>
</pre></div>
</div>
</section>
</section>
<section id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Link to this heading">¶</a></h2>
<p>So, let’s build an interactive interface for our application…</p>
<ul class="simple">
<li><p>Users of a web mapping application should be able to pan and zoom on the map:
<a class="reference external" href="https://demo.mapserver.org/cgi-bin/mapserv?map=/mapserver/apps/tutorial/htdocs/example2.map&layer=states&zoom=0&mode=browse&root=/tutorial&program=/cgi-bin/mapserv&template=example2-1.html">Example 2.1 - Pan and Zoom Controls</a></p></li>
<li><p>They also should be able to turn on and off layers on a map:
<a class="reference external" href="https://demo.mapserver.org/cgi-bin/mapserv?map=/mapserver/apps/tutorial/htdocs/example2.map&layer=states&zoom=0&mode=browse&root=/tutorial&program=/cgi-bin/mapserv&template=example2-2.html">Example 2.2 - Layer Control</a></p></li>
<li><p>A map should always include a scalebar.
<a class="reference external" href="https://demo.mapserver.org/cgi-bin/mapserv?map=/mapserver/apps/tutorial/htdocs/example2.map&layer=states&zoom=0&mode=browse&root=/tutorial&program=/cgi-bin/mapserv&template=example2-3.html">Example 2.3 - Adding a Scalebar</a></p></li>
<li><p>If users are to navigate through the map, a reference map should be provided:
<a class="reference external" href="https://demo.mapserver.org/cgi-bin/mapserv?map=/mapserver/apps/tutorial/htdocs/example2.map&layer=states&zoom=0&mode=browse&root=/tutorial&program=/cgi-bin/mapserv&template=example2-4.html">Example 2.4 - Adding a Reference Map</a></p></li>
<li><p>The map should include a legend.
<a class="reference external" href="https://demo.mapserver.org/cgi-bin/mapserv?map=/mapserver/apps/tutorial/htdocs/example2.map&layer=states&zoom=0&mode=browse&root=/tutorial&program=/cgi-bin/mapserv&template=example2-5.html">Example 2.5- Adding a Legend</a></p></li>
</ul>
<hr class="docutils" />
<p><a class="reference internal" href="section1.html#tutorial-section1"><span class="std std-ref">Back to Section 1 index</span></a> | <a class="reference internal" href="section3.html#tutorial-section3"><span class="std std-ref">Proceed to Section 3</span></a></p>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<search id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Σύντομη αναζήτηση</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Πάμε" />
</form>
</div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script><h3>Navigation</h3>
<p>
<a href="../about.html" title="About">About</a><br>
<a href="../products.html" title="Products">Products</a><br>
<a href="../community/index.html" title="Community">Community</a><br>
<a href="../development/index.html" title="Development">Development</a><br>
<a href="../download.html" title="Downloads">Downloads</a><br>
<a href="../documentation.html" title="Documentation">Documentation</a><br>
<a href="../faq.html" title="FAQ">FAQ</a><br>
<a href="../psc.html" title="PSC">PSC</a><br>
<a href="https://fosstodon.org/@mapserver" title="Mastodon">Mastodon</a>
</p>
<h3>Current Table Of Contents</h3>
<ul>
<li><a class="reference internal" href="#">Section 2: CGI variables and the User Interface</a><ul>
<li><a class="reference internal" href="#html-templates">HTML Templates</a><ul>
<li><a class="reference internal" href="#variables">Variables</a></li>
<li><a class="reference internal" href="#run-time-substitution">Run-time Substitution</a></li>
</ul>
</li>
<li><a class="reference internal" href="#examples">Examples</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Πλοήγηση</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="Κεντρικό Ευρετήριοο"
>ευρετήριο</a></li>
<li class="right" >
<a href="section3.html" title="Section 3: Query and more about HTML Templates"
>επόμενο</a> |</li>
<li class="right" >
<a href="section1.html" title="Section 1: Static Maps and the MapFile"
>προηγούμενο</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Home</a> »</li>
<li class="nav-item nav-item-1"><a href="../documentation.html" >MapServer 8.6.2 Documentation</a> »</li>
<li class="nav-item nav-item-2"><a href="index.html" >MapServer Tutorial</a> »</li>
<li class="nav-item nav-item-this"><a href="">Section 2: CGI variables and the User Interface</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© <a href="../copyright.html">Copyright</a> 2026, Open Source Geospatial Foundation.
Τελευταία ενημέρωση στις 2026-04-20.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 9.1.0.
</div>
</body>
</html>