-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathby_example.html
More file actions
779 lines (711 loc) · 54 KB
/
by_example.html
File metadata and controls
779 lines (711 loc) · 54 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
<!DOCTYPE html>
<html lang="pl" 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>By Example — 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=5bd745c1"></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=2827c288"></script>
<link rel="icon" href="../../_static/mapserver.ico"/>
<link rel="author" title="O tych dokumentach" href="../../about.html" />
<link rel="index" title="Indeks" href="../../genindex.html" />
<link rel="search" title="Szukaj" href="../../search.html" />
<link rel="copyright" title="Copyright" href="../../copyright.html" />
<link rel="next" title="Python MapScript Appendix" href="../python.html" />
<link rel="prev" title="PHP MapScript Migration Guide" href="migration_guide.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="../../../mapscript/php/by_example.html"><img src="../../_static/flagicons/en.png" alt="en" title="en" border="0" /></a>
<a href="../../../ar/mapscript/php/by_example.html"><img src="../../_static/flagicons/ar.png" alt="ar" title="ar" border="0" /></a>
<a href="../../../de/mapscript/php/by_example.html"><img src="../../_static/flagicons/de.png" alt="de" title="de" border="0" /></a>
<a href="../../../el/mapscript/php/by_example.html"><img src="../../_static/flagicons/el.png" alt="el" title="el" border="0" /></a>
<a href="../../../es/mapscript/php/by_example.html"><img src="../../_static/flagicons/es.png" alt="es" title="es" border="0" /></a>
<a href="../../../fr/mapscript/php/by_example.html"><img src="../../_static/flagicons/fr.png" alt="fr" title="fr" border="0" /></a>
<a href="../../../id/mapscript/php/by_example.html"><img src="../../_static/flagicons/id.png" alt="id" title="id" border="0" /></a>
<a href="../../../it/mapscript/php/by_example.html"><img src="../../_static/flagicons/it.png" alt="it" title="it" border="0" /></a>
<a href="../../../ja/mapscript/php/by_example.html"><img src="../../_static/flagicons/ja.png" alt="ja" title="ja" border="0" /></a>
<a href="../../../nl_NL/mapscript/php/by_example.html"><img src="../../_static/flagicons/nl_NL.png" alt="nl_NL" title="nl_NL" border="0" /></a>
<img src="../../_static/flagicons/pl.png" alt="pl" title="pl" border="0" width="18px" height="13px"/>
<a href="../../../ru/mapscript/php/by_example.html"><img src="../../_static/flagicons/ru.png" alt="ru" title="ru" border="0" /></a>
<a href="../../../sq/mapscript/php/by_example.html"><img src="../../_static/flagicons/sq.png" alt="sq" title="sq" border="0" /></a>
<a href="../../../tr/mapscript/php/by_example.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>Nawigacja</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="Indeks ogólny"
accesskey="I">indeks</a></li>
<li class="right" >
<a href="../python.html" title="Python MapScript Appendix"
accesskey="N">dalej</a> |</li>
<li class="right" >
<a href="migration_guide.html" title="PHP MapScript Migration Guide"
accesskey="P">wstecz</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" >MapScript</a> »</li>
<li class="nav-item nav-item-3"><a href="index.html" accesskey="U">PHP MapScript</a> »</li>
<li class="nav-item nav-item-this"><a href="">By Example</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="by-example">
<span id="php-example"></span><h1><a class="toc-backref" href="#tresc" role="doc-backlink">By Example</a><a class="headerlink" href="#by-example" title="Link to this heading">¶</a></h1>
<dl class="field-list simple">
<dt class="field-odd">Author<span class="colon">:</span></dt>
<dd class="field-odd"><p>Vinko Vrsalovic</p>
</dd>
<dt class="field-even">Contact<span class="colon">:</span></dt>
<dd class="field-even"><p>el at vinko.cl</p>
</dd>
<dt class="field-odd">Last Updated<span class="colon">:</span></dt>
<dd class="field-odd"><p>2005-12-12</p>
</dd>
</dl>
<nav class="contents" id="tresc">
<p class="topic-title">Treść</p>
<ul class="simple">
<li><p><a class="reference internal" href="#by-example" id="id1">By Example</a></p>
<ul>
<li><p><a class="reference internal" href="#introduction" id="id2">Introduction</a></p></li>
<li><p><a class="reference internal" href="#mapscript-overview" id="id3">MapScript overview</a></p></li>
<li><p><a class="reference internal" href="#our-first-application" id="id4">Our first application</a></p></li>
<li><p><a class="reference internal" href="#conclusions" id="id5">Conclusions</a></p></li>
</ul>
</li>
</ul>
</nav>
<div class="admonition warning">
<p class="admonition-title">Ostrzeżenie</p>
<p>As of the MapServer 8.0.0 release PHP support is only available through
MapServer’s <a class="reference internal" href="../mapscript-api/index.html#swig"><span class="std std-ref">SWIG API</span></a>. The unmaintained <cite>native</cite> PHP MapScript
support was removed.</p>
</div>
<div class="admonition note">
<p class="admonition-title">Informacja</p>
<p>As of the 7.4.0 release PHP 7 is available through
MapServer’s <a class="reference internal" href="../mapscript-api/index.html#swig"><span class="std std-ref">SWIG API</span></a>. MapServer users are encouraged to
use the SWIG API to connect to PHP 7 through MapScript. This document only covers
the legacy MapScript support; for recent examples of PHP 7 mapscript,
see the <a class="reference external" href="https://ms4w.com/trac/">MS4W wiki</a> as users have been
contributing PHP 7 mapscript scripts there.</p>
</div>
<section id="introduction">
<h2><a class="toc-backref" href="#tresc" role="doc-backlink">Introduction</a><a class="headerlink" href="#introduction" title="Link to this heading">¶</a></h2>
<p>The purpose of this document is to be a step by step explanation of
the <a class="reference internal" href="phpmapscript.html#phpmapscriptapi"><span class="std std-ref">PHP MapScript API</span></a> with practical examples for each of them. It
is assumed a basic knowledge of <a class="reference internal" href="../../mapfile/map.html#map"><span class="std std-ref">MAP</span></a> and MapServer, and
familiarity with the <a class="reference external" href="http://www.php.net">PHP (scripting)</a> and <a class="reference external" href="http://www.w3.org/MarkUp/">HTML (markup)</a> languages
. This document was originally created for MapServer v4.0, but the
examples still apply to more recent versions.</p>
<p><strong>Let’s Begin…</strong></p>
<p>Hello, kind reader. I am Tut, thank you for downloading me. I am
sorry, but I am just a technical manual so I cannot answer any
questions. The maintainer, a handsome, very nice and lazy guy
according to what I saw from the other side of the screen, maybe will
be able to answer your question(s). I am currently here to tell you
about MapScript in its PHP incarnation. At my current age, I will be
more useful to beginners than advanced users, even though I hope that
some day I will be sufficiently old to be useful to advanced MapScript
programmers.</p>
<p>Let’s hope I live long enough… sigh.</p>
<p>But enough with my personal problems, let myself begin. My duty is to
familiarize you with MapScript, and in particular with PHP
MapScript. When I end, you are expected to understand what MapScript
is, and to be able to write applications to display and navigate that
is, zooming and panning over shapefiles via a web browser.</p>
<p>What follows are the questions you must answer affirmatively before
accompanying me through the rest of this journey (I apologize for my
maintainer’s lack of literary taste).</p>
<section id="do-you-have-running-somewhere">
<h3>Do you have running somewhere…<a class="headerlink" href="#do-you-have-running-somewhere" title="Link to this heading">¶</a></h3>
<ul class="simple">
<li><p>a web server capable of running PHP as a CGI (Apache will do)?</p></li>
<li><p>the PHP language configured as a CGI, version 4.1.2 or higher? I
recommend 4.3 onwards.</p></li>
<li><p>PHP MapScript, version 4.0 or later? <a class="reference internal" href="../../installation/php.html#php-install"><span class="std std-ref">PHP MapScript Installation</span></a></p></li>
</ul>
</section>
<section id="can-you">
<h3>Can you…<a class="headerlink" href="#can-you" title="Link to this heading">¶</a></h3>
<ul class="simple">
<li><p>code PHP or are willing to <a class="reference external" href="http://php.net/tut.php">learn how to</a>?</p></li>
<li><p>write and understand <a class="reference external" href="http://www.w3.org/MarkUp/">HTML</a> documents? (Note that Javascript is a
plus)</p></li>
<li><p>tell somebody what on earth is a <a class="reference external" href="http://shapelib.maptools.org/">shapefile</a> [or a <a class="reference external" href="http://postgis.net/">PostGIS</a>
table]?</p></li>
</ul>
</section>
<section id="outline-of-this-document">
<h3>Outline of this Document<a class="headerlink" href="#outline-of-this-document" title="Link to this heading">¶</a></h3>
<ul class="simple">
<li><p>A general overview of MapScript, in a language independent way</p></li>
<li><p>A trivial example</p></li>
<li><p>A simple example</p></li>
<li><p>Conclusion</p></li>
</ul>
<p>You can also go to each part directly through my table of contents
located at the top, if you wish to skip some sections.</p>
</section>
</section>
<section id="mapscript-overview">
<h2><a class="toc-backref" href="#tresc" role="doc-backlink">MapScript overview</a><a class="headerlink" href="#mapscript-overview" title="Link to this heading">¶</a></h2>
<p>Ok, now I’m at last arriving at a point I will enjoy. This overview
intends to clear some common misconceptions beginners encounter when
first facing MapScript and to give a general overview about
MapScript’s internals. For now, just look at the following diagram (I
apologize again for the maintainer’s lack of graphic design taste).</p>
<img alt="../../_images/phpmapscript-byexample-map.png" src="../../_images/phpmapscript-byexample-map.png" />
<p>It all starts as everything on the Web. A browser requests a certain
URL through HTTP. The request arrives at the web server, which, in
turn, delivers a file or executes a program and then delivers its
output back to the browser. Yes, I know you knew that, but I have been
told to be as complete as possible, and I will try to.</p>
<p>In MapScript’s case, the server executes a certain script, which
contains standard language functionality, that is, the same
functionality you would have in that language without MapScript, plus
access to almost all of the MapServer C API, the level of completeness
of MapServer API support varies a bit with the language you choose,
but I think it is my duty to tell you almost every available flavor of
MapScript is usable. This API, exposed now in your scripting language
through the MapScript module, allows you to do many GIS-like
operations on spatial data, including read-write access to shapefiles,
reprojection of data, and many others. For more information on the
API, click over the link above. For other flavors, you can check their
own documentation, you will see there is not much difference.</p>
<p>The CGI version of MapServer is not required to run MapScript
applications, just as you don’t need a particular MapScript module to
run the CGI. The CGI version has many features out-of-the-box,
MapScript is just an API, so with MapScript you must start from
scratch or with some of the examples available. Think of the CGI as of
a MapScript application written directly in C, with direct access to
the MapServer C API. Sometimes the out-of-the-box functionality has
some limits which can be surpassed by MapScript, but not embedded
within the CGI. In other words, the CGI is not scriptable, but you can
program all the CGI and more with MapScript. This may seem a strange
thing to clarify, but is a common misconception, just check the <a class="reference external" href="https://lists.osgeo.org/pipermail/mapserver-users/">list
archives</a> if you are not inclined to believe me.</p>
<p>As with MapServer itself, MapScript can be configured using only map
files, but, unlike the CGI, also includes the possibility of
dynamically create maps or modify existing ones and to (and here is
the key to the flexibility that MapScript has) mix this information
with other sources of non GIS data, such as user input, non spatial
and spatial databases, text files, etc. and that you can use every
single module your language provides. The power of this approach is
tremendous, and the most restrictive limit is your imagination. As
always, flexibility comes with a price, performance. It’s generally
slower to use a scripting language instead of C, but nowadays this
shouldn’t be a big worry. And you can still program directly in C
(there are not much documents about how to do it, though you might
want to check the <a class="reference external" href="https://lists.osgeo.org/mailman/listinfo/mapserver-dev/">mapserver-dev list</a>) if you would like to.</p>
<p>The input and output formats MapScript can handle are exactly the same
as the ones configured when you build MapServer/MapScript. But one of
the most important things to remember is that, basically, you feed
geographic data and relevant user input (for instance clicks over the
map image) to MapScript and as a result get one or more file(s),
typically standard image files such as a PNG or JPEG. So you can apply
anything you’ve seen in any server side scripted web application,
DHTML, Java applets, CSS, HTML templates, sessions, you name it.</p>
</section>
<section id="our-first-application">
<h2><a class="toc-backref" href="#tresc" role="doc-backlink">Our first application</a><a class="headerlink" href="#our-first-application" title="Link to this heading">¶</a></h2>
<p>In this first example, I will tell you how to display a shapefile on a
web page using a map file.</p>
<section id="the-map-file">
<h3>The Map File<a class="headerlink" href="#the-map-file" title="Link to this heading">¶</a></h3>
<p>Here’s the map file:</p>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="linenos"> 1</span> <span class="k">NAME</span> <span class="s">"Europe in purple"</span>
<span class="linenos"> 2</span> <span class="k">SIZE</span> <span class="mi">400</span> <span class="mi">400</span>
<span class="linenos"> 3</span> <span class="k">STATUS</span> <span class="nb">ON</span>
<span class="linenos"> 4</span> <span class="k">SYMBOLSET</span> <span class="s">"/var/www/html/maps/symbols/symbols.sym"</span>
<span class="linenos"> 5</span> <span class="k">EXTENT</span> <span class="p">-</span><span class="mi">5696501</span> <span class="mi">1923039</span> <span class="mi">5696501</span> <span class="mi">11022882</span>
<span class="linenos"> 6</span> <span class="k">UNITS</span> <span class="nb">METERS</span>
<span class="linenos"> 7</span> <span class="k">SHAPEPATH</span> <span class="s">"/var/www/html/maps/data"</span>
<span class="linenos"> 8</span>
<span class="linenos"> 9</span> <span class="k">WEB</span>
<span class="linenos">10</span> <span class="k">IMAGEPATH</span> <span class="s">"/var/www/html/maps/tmp/"</span>
<span class="linenos">11</span> <span class="k">IMAGEURL</span> <span class="s">"/tmp/"</span>
<span class="linenos">12</span> <span class="k">END</span>
<span class="linenos">13</span>
<span class="linenos">14</span> <span class="k">LAYER</span>
<span class="linenos">15</span> <span class="k">NAME</span> <span class="s">"Europe"</span>
<span class="linenos">16</span> <span class="k">TYPE</span> <span class="nb">POLYGON</span>
<span class="linenos">17</span> <span class="k">STATUS</span> <span class="nb">ON</span>
<span class="linenos">18</span> <span class="k">DATA</span> <span class="s">"europe.shp"</span>
<span class="linenos">19</span> <span class="k">CLASS</span>
<span class="linenos">20</span> <span class="k">STYLE</span>
<span class="linenos">21</span> <span class="k">COLOR</span> <span class="mi">110</span> <span class="mi">50</span> <span class="mi">100</span>
<span class="linenos">22</span> <span class="k">OUTLINECOLOR</span> <span class="mi">200</span> <span class="mi">200</span> <span class="mi">200</span>
<span class="linenos">23</span> <span class="k">SYMBOL</span> <span class="mi">0</span>
<span class="linenos">24</span> <span class="k">END</span>
<span class="linenos">25</span> <span class="k">END</span>
<span class="linenos">26</span> <span class="k">END</span>
<span class="linenos">27</span>
<span class="linenos">28</span> <span class="k">END</span>
</pre></div>
</div>
<p>Here I have shown a map with a single layer, where the europe.shp,
europe.shx and europe.dbf files must be located in the subdirectory
called data. The symbols are located in the symbols subdirectory. All
this locations are relative from the place the map file is, but better
safe than sorry, I guess. The web section is used to define where will
the images be saved and in what URL will they be available.</p>
</section>
<section id="displaying-the-map-with-mapscript">
<h3>Displaying the map with MapScript<a class="headerlink" href="#displaying-the-map-with-mapscript" title="Link to this heading">¶</a></h3>
<p>To display a map the following MapScript objects and methods will be
used:</p>
<ul class="simple">
<li><p>MapObj object</p></li>
<li><p>imageObj object</p></li>
</ul>
<p>MapObj methods:</p>
<ul class="simple">
<li><p>The constructor method: MapObj ms_newMapObj(string map_file_name[,string new_map_path])</p></li>
<li><p>The draw method: imageObj draw()</p></li>
</ul>
<p>imageObj methods:</p>
<ul class="simple">
<li><p>The saveWebImage method: string saveWebImage()</p></li>
</ul>
<p>The code looks like this:</p>
<div class="highlight-php notranslate"><div class="highlight"><pre><span></span><span class="linenos"> 1</span><span class="x"> </span><span class="cp"><?php</span>
<span class="linenos"> 2</span>
<span class="linenos"> 3</span> <span class="nb">dl</span><span class="p">(</span><span class="s1">'php_mapscript.so'</span><span class="p">);</span>
<span class="linenos"> 4</span>
<span class="linenos"> 5</span> <span class="nv">$map_path</span><span class="o">=</span><span class="s2">"/var/www/html/ms/map_files/"</span><span class="p">;</span>
<span class="linenos"> 6</span>
<span class="linenos"> 7</span> <span class="nv">$map</span> <span class="o">=</span> <span class="nx">ms_newMapObj</span><span class="p">(</span><span class="nv">$map_path</span><span class="o">.</span><span class="s2">"europe.map"</span><span class="p">);</span>
<span class="linenos"> 8</span> <span class="nv">$image</span><span class="o">=</span><span class="nv">$map</span><span class="o">-></span><span class="na">draw</span><span class="p">();</span>
<span class="linenos"> 9</span> <span class="nv">$image_url</span><span class="o">=</span><span class="nv">$image</span><span class="o">-></span><span class="na">saveWebImage</span><span class="p">();</span>
<span class="linenos">10</span>
<span class="linenos">11</span> <span class="cp">?></span>
<span class="linenos">12</span>
<span class="linenos">13</span><span class="x"> <HTML></span>
<span class="linenos">14</span><span class="x"> <HEAD></span>
<span class="linenos">15</span><span class="x"> <TITLE>Example 1: Displaying a map</TITLE></span>
<span class="linenos">16</span><span class="x"> </HEAD></span>
<span class="linenos">17</span><span class="x"> <BODY></span>
<span class="linenos">18</span><span class="x"> <IMG SRC=</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$image_url</span><span class="p">;</span> <span class="cp">?></span><span class="x"> ></span>
<span class="linenos">19</span><span class="x"> </BODY></span>
<span class="linenos">20</span><span class="x"> </HTML></span>
</pre></div>
</div>
<p>The code I will present through the rest of this document will follow
the following rule:</p>
<ul class="simple">
<li><p>Every non empty line is numbered</p></li>
</ul>
<p>This code will render an image corresponding to the shapefile europe and display
it on a HTML page.</p>
</section>
<section id="code-explanation">
<h3>Code Explanation<a class="headerlink" href="#code-explanation" title="Link to this heading">¶</a></h3>
<ul class="simple">
<li><p>In line 2 it is loaded the MapScript extension (you may not need it if your
php.ini file is configured to automatically load it).</p></li>
<li><p>Line 3 declares a variable that holds the absolute path for the mapfile.</p></li>
<li><p>Line 4 creates an instance of the MapObj object using the constructor. As you
can see, the constructor receives the location of the map file as its only
required parameter, and the map file received the europe.map name.</p></li>
<li><p>Afterwards the draw method of the map object is called to render the image
defined by the map file (line 5). The result (an imageObj) is saved in the
$image variable.</p></li>
<li><p>Line 6 calls the saveWebImage method to generate the image file, it returns a
string which represents the URL as defined in the mapfile (in this case,
/tmp/filename.png).</p></li>
<li><p>The rest of the lines are pure HTML, except line 13, that defines the source
URL of the image will be the value stored in $image_url.</p></li>
</ul>
<p>You should test the application on your system, to check that it really works
and to solve the problems that may arise on your particular configuration before
moving on to the more complex examples.</p>
</section>
<section id="output">
<h3>Output<a class="headerlink" href="#output" title="Link to this heading">¶</a></h3>
<p>The output (using the europe shapefile) should look like this:</p>
<img alt="../../_images/phpmapscript-byexample-map.png" src="../../_images/phpmapscript-byexample-map.png" />
</section>
<section id="zooming-and-panning">
<h3>Zooming and Panning<a class="headerlink" href="#zooming-and-panning" title="Link to this heading">¶</a></h3>
<p>Now I will tell you how to add zoom and pan capabilities to the code.</p>
<p>Here goes the list of new methods and objects called.</p>
<p>New Objects:</p>
<ul class="simple">
<li><p>pointObj</p></li>
<li><p>rectObj</p></li>
</ul>
<p>New Methods and Members called:</p>
<ul class="simple">
<li><p>The zoompoint method of the map object: void zoompoint(int nZoomFactor,
pointObj oPixelPos, int nImageWidth, int nImageHeight, rectObj oGeorefExt).</p></li>
<li><p>The setextent method of the map object: $map->setextent(double minx,
double miny, double maxx, double maxy);.</p></li>
<li><p>The extent, width and height members of the map object.</p></li>
<li><p>The constructors of RectObj and PointObj: $point = ms_newPointObj();
$rect = ms_newRectObj();</p></li>
<li><p>The setXY method of the point object: $point->setXY(double x_coord,
double y_coord);</p></li>
<li><p>The setextent method of the rectangle object: $rect->setextent(double minx,
double miny, double maxx, double maxy);</p></li>
</ul>
<p>The .map file remains the same as the one presented in the previous example.</p>
</section>
<section id="php-mapscript-code">
<h3>PHP/MapScript Code<a class="headerlink" href="#php-mapscript-code" title="Link to this heading">¶</a></h3>
<p>Here I present the new code.</p>
<div class="highlight-php notranslate"><div class="highlight"><pre><span></span><span class="linenos"> 1</span><span class="x"> </span><span class="cp"><?php</span>
<span class="linenos"> 2</span>
<span class="linenos"> 3</span> <span class="nb">dl</span><span class="p">(</span><span class="s1">'php_mapscript.so'</span><span class="p">);</span>
<span class="linenos"> 4</span>
<span class="linenos"> 5</span> <span class="c1">// Default values and configuration</span>
<span class="linenos"> 6</span>
<span class="linenos"> 7</span> <span class="nv">$val_zsize</span><span class="o">=</span><span class="mi">3</span><span class="p">;</span>
<span class="linenos"> 8</span> <span class="nv">$check_pan</span><span class="o">=</span><span class="s2">"CHECKED"</span><span class="p">;</span>
<span class="linenos"> 9</span> <span class="nv">$map_path</span><span class="o">=</span><span class="s2">"/var/www/html/ms/map_files/"</span><span class="p">;</span>
<span class="linenos"> 10</span> <span class="nv">$map_file</span><span class="o">=</span><span class="s2">"europe.map"</span><span class="p">;</span>
<span class="linenos"> 11</span>
<span class="linenos"> 12</span> <span class="nv">$map</span> <span class="o">=</span> <span class="nx">ms_newMapObj</span><span class="p">(</span><span class="nv">$map_path</span><span class="o">.</span><span class="nv">$map_file</span><span class="p">);</span>
<span class="linenos"> 13</span>
<span class="linenos"> 14</span>
<span class="linenos"> 15</span> <span class="k">if</span> <span class="p">(</span> <span class="nb">isset</span><span class="p">(</span><span class="nv">$_POST</span><span class="p">[</span><span class="s2">"mapa_x"</span><span class="p">])</span> <span class="o">&&</span> <span class="nb">isset</span><span class="p">(</span><span class="nv">$_POST</span><span class="p">[</span><span class="s2">"mapa_y"</span><span class="p">])</span>
<span class="linenos"> 16</span> <span class="o">&&</span> <span class="o">!</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$_POST</span><span class="p">[</span><span class="s2">"full"</span><span class="p">])</span> <span class="p">)</span> <span class="p">{</span>
<span class="linenos"> 17</span>
<span class="linenos"> 18</span> <span class="nv">$extent_to_set</span> <span class="o">=</span> <span class="nb">explode</span><span class="p">(</span><span class="s2">" "</span><span class="p">,</span><span class="nv">$_POST</span><span class="p">[</span><span class="s2">"extent"</span><span class="p">]);</span>
<span class="linenos"> 19</span>
<span class="linenos"> 20</span> <span class="nv">$map</span><span class="o">-></span><span class="na">setextent</span><span class="p">(</span><span class="nv">$extent_to_set</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="nv">$extent_to_set</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
<span class="linenos"> 21</span> <span class="nv">$extent_to_set</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="nv">$extent_to_set</span><span class="p">[</span><span class="mi">3</span><span class="p">]);</span>
<span class="linenos"> 22</span>
<span class="linenos"> 23</span> <span class="nv">$my_point</span> <span class="o">=</span> <span class="nx">ms_newpointObj</span><span class="p">();</span>
<span class="linenos"> 24</span> <span class="nv">$my_point</span><span class="o">-></span><span class="na">setXY</span><span class="p">(</span><span class="nv">$_POST</span><span class="p">[</span><span class="s2">"mapa_x"</span><span class="p">],</span><span class="nv">$_POST</span><span class="p">[</span><span class="s2">"mapa_y"</span><span class="p">]);</span>
<span class="linenos"> 25</span>
<span class="linenos"> 26</span> <span class="nv">$my_extent</span> <span class="o">=</span> <span class="nx">ms_newrectObj</span><span class="p">();</span>
<span class="linenos"> 27</span>
<span class="linenos"> 28</span> <span class="nv">$my_extent</span><span class="o">-></span><span class="na">setextent</span><span class="p">(</span><span class="nv">$extent_to_set</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="nv">$extent_to_set</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
<span class="linenos"> 29</span> <span class="nv">$extent_to_set</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="nv">$extent_to_set</span><span class="p">[</span><span class="mi">3</span><span class="p">]);</span>
<span class="linenos"> 30</span>
<span class="linenos"> 31</span> <span class="nv">$zoom_factor</span> <span class="o">=</span> <span class="nv">$_POST</span><span class="p">[</span><span class="s2">"zoom"</span><span class="p">]</span><span class="o">*</span><span class="nv">$_POST</span><span class="p">[</span><span class="s2">"zsize"</span><span class="p">];</span>
<span class="linenos"> 32</span> <span class="k">if</span> <span class="p">(</span><span class="nv">$zoom_factor</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="linenos"> 33</span> <span class="nv">$zoom_factor</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="linenos"> 34</span> <span class="nv">$check_pan</span> <span class="o">=</span> <span class="s2">"CHECKED"</span><span class="p">;</span>
<span class="linenos"> 35</span> <span class="nv">$check_zout</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
<span class="linenos"> 36</span> <span class="nv">$check_zin</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
<span class="linenos"> 37</span> <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nv">$zoom_factor</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="linenos"> 38</span> <span class="nv">$check_pan</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
<span class="linenos"> 39</span> <span class="nv">$check_zout</span> <span class="o">=</span> <span class="s2">"CHECKED"</span><span class="p">;</span>
<span class="linenos"> 40</span> <span class="nv">$check_zin</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
<span class="linenos"> 41</span> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="linenos"> 42</span> <span class="nv">$check_pan</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
<span class="linenos"> 43</span> <span class="nv">$check_zout</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
<span class="linenos"> 44</span> <span class="nv">$check_zin</span> <span class="o">=</span> <span class="s2">"CHECKED"</span><span class="p">;</span>
<span class="linenos"> 45</span> <span class="p">}</span>
<span class="linenos"> 46</span>
<span class="linenos"> 47</span> <span class="nv">$val_zsize</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="nv">$zoom_factor</span><span class="p">);</span>
<span class="linenos"> 48</span>
<span class="linenos"> 49</span> <span class="nv">$map</span><span class="o">-></span><span class="na">zoompoint</span><span class="p">(</span><span class="nv">$zoom_factor</span><span class="p">,</span><span class="nv">$my_point</span><span class="p">,</span><span class="nv">$map</span><span class="o">-></span><span class="na">width</span><span class="p">,</span><span class="nv">$map</span><span class="o">-></span><span class="na">height</span><span class="p">,</span>
<span class="linenos"> 50</span> <span class="nv">$my_extent</span><span class="p">);</span>
<span class="linenos"> 51</span>
<span class="linenos"> 52</span> <span class="p">}</span>
<span class="linenos"> 53</span>
<span class="linenos"> 54</span>
<span class="linenos"> 55</span> <span class="nv">$image</span><span class="o">=</span><span class="nv">$map</span><span class="o">-></span><span class="na">draw</span><span class="p">();</span>
<span class="linenos"> 56</span> <span class="nv">$image_url</span><span class="o">=</span><span class="nv">$image</span><span class="o">-></span><span class="na">saveWebImage</span><span class="p">();</span>
<span class="linenos"> 57</span>
<span class="linenos"> 58</span> <span class="nv">$extent_to_html</span> <span class="o">=</span> <span class="nv">$map</span><span class="o">-></span><span class="na">extent</span><span class="o">-></span><span class="na">minx</span><span class="o">.</span><span class="s2">" "</span><span class="o">.</span><span class="nv">$map</span><span class="o">-></span><span class="na">extent</span><span class="o">-></span><span class="na">miny</span><span class="o">.</span><span class="s2">" "</span>
<span class="linenos"> 59</span> <span class="o">.</span><span class="nv">$map</span><span class="o">-></span><span class="na">extent</span><span class="o">-></span><span class="na">maxx</span><span class="o">.</span><span class="s2">" "</span><span class="o">.</span><span class="nv">$map</span><span class="o">-></span><span class="na">extent</span><span class="o">-></span><span class="na">maxy</span><span class="p">;</span>
<span class="linenos"> 60</span>
<span class="linenos"> 61</span> <span class="cp">?></span>
<span class="linenos"> 62</span><span class="x"> <HTML></span>
<span class="linenos"> 63</span><span class="x"> <HEAD></span>
<span class="linenos"> 64</span><span class="x"> <TITLE>Map 2</TITLE></span>
<span class="linenos"> 65</span><span class="x"> </HEAD></span>
<span class="linenos"> 66</span><span class="x"> <BODY></span>
<span class="linenos"> 67</span><span class="x"> <CENTER></span>
<span class="linenos"> 68</span><span class="x"> <FORM METHOD=POST ACTION=</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$HTTP_SERVER_VARS</span><span class="p">[</span><span class="s1">'PHP_SELF'</span><span class="p">]</span><span class="cp">?></span><span class="x">></span>
<span class="linenos"> 69</span><span class="x"> <TABLE></span>
<span class="linenos"> 70</span><span class="x"> <TR></span>
<span class="linenos"> 71</span><span class="x"> <TD></span>
<span class="linenos"> 72</span><span class="x"> <INPUT TYPE=IMAGE NAME="mapa" SRC="</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$image_url</span><span class="cp">?></span><span class="x">"></span>
<span class="linenos"> 73</span><span class="x"> </TD></span>
<span class="linenos"> 74</span><span class="x"> </TR></span>
<span class="linenos"> 75</span><span class="x"> <TR></span>
<span class="linenos"> 76</span><span class="x"> <TD></span>
<span class="linenos"> 77</span><span class="x"> Pan</span>
<span class="linenos"> 78</span><span class="x"> </TD></span>
<span class="linenos"> 79</span><span class="x"> <TD></span>
<span class="linenos"> 80</span><span class="x"> <INPUT TYPE=RADIO NAME="zoom" VALUE=0 </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$check_pan</span><span class="cp">?></span><span class="x">></span>
<span class="linenos"> 81</span><span class="x"> </TD></span>
<span class="linenos"> 82</span><span class="x"> </TR></span>
<span class="linenos"> 83</span><span class="x"> <TR></span>
<span class="linenos"> 84</span><span class="x"> <TD></span>
<span class="linenos"> 85</span><span class="x"> Zoom In</span>
<span class="linenos"> 86</span><span class="x"> </TD></span>
<span class="linenos"> 87</span><span class="x"> <TD></span>
<span class="linenos"> 88</span><span class="x"> <INPUT TYPE=RADIO NAME="zoom" VALUE=1 </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$check_zin</span><span class="cp">?></span><span class="x">></span>
<span class="linenos"> 89</span><span class="x"> </TD></span>
<span class="linenos"> 90</span><span class="x"> </TR></span>
<span class="linenos"> 91</span><span class="x"> <TR></span>
<span class="linenos"> 92</span><span class="x"> <TD></span>
<span class="linenos"> 93</span><span class="x"> Zoom Out</span>
<span class="linenos"> 94</span><span class="x"> </TD></span>
<span class="linenos"> 95</span><span class="x"> <TD></span>
<span class="linenos"> 96</span><span class="x"> <INPUT TYPE=RADIO NAME="zoom" VALUE=-1 </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$check_zout</span><span class="cp">?></span><span class="x">></span>
<span class="linenos"> 97</span><span class="x"> </TD></span>
<span class="linenos"> 98</span><span class="x"> </TR></span>
<span class="linenos"> 99</span><span class="x"> <TR></span>
<span class="linenos">100</span><span class="x"> <TD></span>
<span class="linenos">101</span><span class="x"> Zoom Size</span>
<span class="linenos">102</span><span class="x"> </TD></span>
<span class="linenos">103</span><span class="x"> <TD></span>
<span class="linenos">104</span><span class="x"> <INPUT TYPE=TEXT NAME="zsize" VALUE="</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$val_zsize</span><span class="cp">?></span><span class="x">"</span>
<span class="linenos">105</span><span class="x"> SIZE=2></span>
<span class="linenos">106</span><span class="x"> </TD></span>
<span class="linenos">107</span><span class="x"> </TR></span>
<span class="linenos">108</span><span class="x"> <TR></span>
<span class="linenos">109</span><span class="x"> <TD></span>
<span class="linenos">110</span><span class="x"> Full Extent</span>
<span class="linenos">111</span><span class="x"> </TD></span>
<span class="linenos">112</span><span class="x"> <TD></span>
<span class="linenos">113</span><span class="x"> <INPUT TYPE=SUBMIT NAME="full" VALUE="Go"</span>
<span class="linenos">114</span><span class="x"> SIZE=2></span>
<span class="linenos">115</span><span class="x"> </TD></span>
<span class="linenos">116</span><span class="x"> </TABLE></span>
<span class="linenos">117</span><span class="x"> <INPUT TYPE=HIDDEN NAME="extent" VALUE="</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$extent_to_html</span><span class="cp">?></span><span class="x">"></span>
<span class="linenos">118</span><span class="x"> </FORM></span>
<span class="linenos">119</span><span class="x"> </CENTER></span>
<span class="linenos">120</span><span class="x"> </BODY></span>
<span class="linenos">121</span><span class="x"> </HMTL></span>
</pre></div>
</div>
<p>This code will zoom out, zoom in, pan, and restore to full extent the
image displayed in the previous example.</p>
<p>It looks much more complicated than it really is, much of the lines
are the HTML code, and much of the remaining PHP code is just to deal
with the forms and such.</p>
<p>You should try it and look at how it works first. Try it in your own
server by copying and pasting the code.</p>
<p>Now it’s time for you to play with it a little and look at the source
in your browser to check how it changes.</p>
<p>Done?, now let’s start the explanation with the HTML part.</p>
</section>
<section id="code-explanation-html">
<h3>Code Explanation - HTML<a class="headerlink" href="#code-explanation-html" title="Link to this heading">¶</a></h3>
<p>Line 49 declares a form, and line 53 declares the image generated by
MapScript to be part of that form, so when you click on it, the X and
Y coordinates of the click (in pixels) will be sent along with the
other data for the PHP code to process.</p>
<p>If you are familiar with HTML and PHP, the rest of the HTML code
should be straightforward for you to understand with the exception of
line 98, that will be explained in due time.</p>
</section>
<section id="code-explanation-php">
<h3>Code Explanation - PHP<a class="headerlink" href="#code-explanation-php" title="Link to this heading">¶</a></h3>
<p>Now look at the PHP code, it’s almost the same code used in example 1,
with the addition of lines 9 to 37. What do these lines do?</p>
<p>Line 9 checks the relevant variables from the form have been
set. «mapa_x» and «mapa_y» represent the X and Y coordinates of the
click over the image, and «full» represents the click on the «Full
Extent» button.</p>
<p>The first time the page is displayed the code between the if statement
doesn’t get executed, but the rest of the code does. Lines 40 and 41
set the «$extent_to_html» variable with the values of the extent
defined in the map file separated by spaces; that value will be put in
the HTML variable «extent» in line 98.</p>
<p>Now look at line 11 and 12. We are inside the if statement, that means
the form has been submitted at least once. We grab the extent stored
in the previous execution (the «extent» HTML variable) of the code and
set the extent of the map to be that last extent. This allows to zoom
or pan with respect of the previous extent, not the extent that is set
in the map file.</p>
<p>From that last paragraph you can deduce that all the default values
are set in the map file, and anything that you change through
MapScript and would like to remain in your code, must be stored
somehow. In this case it is done through hidden variables in a
form. For more advanced applications you could use session variables
or a database.</p>
<p>Now you should be able to see why the «Full Extent» button works. If
you check line 10, it says that if you haven’t pressed the button,
skip the code in the if statement, so the extent is reset to the value
that the map file has. You should also see that it isn’t necessarily a
full extent (in case the extent in the map file is not full extent).</p>
<p>Lines 14 and 15 declare a new point object and initialize it with the
values the user clicked on. You should not forget that those values
are in pixels, not in georeferenced coordinates.</p>
<p>Lines 16 through 18 create a new rectangle object and set it with the
extent of the previous image, just like it is done on line 12. In fact
this would work too: $my_extent = $map->extent;.</p>
<p>To do all the zooming and panning, the zoompoint function in called on
line 35, but first the arguments it receives must be prepared. You can
determine the point the user clicked on, and the extent of the image
($my_point and $my_extent, respectively), but now you have to
determine the zoom factor. That’s what lines 19 to 33 do. If you
wondered why the values of the radio buttons where 0, -1, and 1 for
pan, zoom in and zoom out, now you will know the reason.</p>
<p>A zoom factor of 1 tells zoompoint that the operation is pan, a
negative value indicates zoom out and a positive value indicates zoom
in. So, by means of multiplying the value received for the radio
buttons (HTML variable «zoom») by the size of the zoom the user
entered the zoom factor is calculated. If that value is 0, that means
the user selected the pan operation, so «$zoom_factor» is set to 1,
otherwise the result of the multiplication is the zoom factor
zoompoint needs to receive. The other lines are to preserve the button
the user clicked on the next time. Line 34 tries to preserve the value
of the zoom size the user entered (It doesn’t do that all the time,
when and why that line fails? That’s for you to find out).</p>
<p>And finally, line 34 calls the zoompoint method with the zoom factor
obtained, the point built from the pixel coordinates (I insist on that
issue because zoompoint is almost the only method that receives the
coordinates in pixels, for the other methods you must convert pixels
to georeferenced coordinates on your own), the height and width of the
image, and the extent.</p>
<p>After calling zoompoint, the extent of the image is changed
accordingly to the operation performed (or, better put, the zoom
factor). So then the image is drawn and the current extent saved
(after the zooming) for use in the next iteration.</p>
</section>
</section>
<section id="conclusions">
<h2><a class="toc-backref" href="#tresc" role="doc-backlink">Conclusions</a><a class="headerlink" href="#conclusions" title="Link to this heading">¶</a></h2>
<p>Well, it’s time for me to go recharge my batteries. So I will use this
last energy to share some final words. The examples I have managed to
present here are very basic but you should now be able to devise ways
to improve them and suit things to your needs. Keep in mind that you
can preprocess, store, read, write data from any source you can
usually read through PHP, plus all the sources MapServer can handle
for GIS data. You can even process some GIS data with PHP only if the
need would arise (SQL sources are a good example of this). You can
also do hybrid approaches where some script prepares data which is
then shown through the CGI interface to MapServer, or create data on
the fly based on input from a GPS, etc, etc. The possibilities are
just too many to enumerate completely. As I already said your
imagination is the limit. The next version of this document will
include examples that include more than one layer, with different
datasources (not just shapefiles) and creation of dynamic layers and
classes. If you have a better idea or would like to see some other
thing here first, please drop a note to my maintainer.</p>
<p>In the meantime, if you need bigger examples you can refer to the
original „GMap demo” (you can download the source <a class="reference external" href="http://dl.maptools.org/dl/">here</a>), or the
<a class="reference external" href="http://www.maptools.org/">MapTools site</a> (for the older MapLab, Chameleon applications, which were
built on PHPMapScript). Goodbye, and thanks for reading this far.</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">Szybkie wyszukiwanie</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="Szukaj" />
</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="#">By Example</a><ul>
<li><a class="reference internal" href="#introduction">Introduction</a><ul>
<li><a class="reference internal" href="#do-you-have-running-somewhere">Do you have running somewhere…</a></li>
<li><a class="reference internal" href="#can-you">Can you…</a></li>
<li><a class="reference internal" href="#outline-of-this-document">Outline of this Document</a></li>
</ul>
</li>
<li><a class="reference internal" href="#mapscript-overview">MapScript overview</a></li>
<li><a class="reference internal" href="#our-first-application">Our first application</a><ul>
<li><a class="reference internal" href="#the-map-file">The Map File</a></li>
<li><a class="reference internal" href="#displaying-the-map-with-mapscript">Displaying the map with MapScript</a></li>
<li><a class="reference internal" href="#code-explanation">Code Explanation</a></li>
<li><a class="reference internal" href="#output">Output</a></li>
<li><a class="reference internal" href="#zooming-and-panning">Zooming and Panning</a></li>
<li><a class="reference internal" href="#php-mapscript-code">PHP/MapScript Code</a></li>
<li><a class="reference internal" href="#code-explanation-html">Code Explanation - HTML</a></li>
<li><a class="reference internal" href="#code-explanation-php">Code Explanation - PHP</a></li>
</ul>
</li>
<li><a class="reference internal" href="#conclusions">Conclusions</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Nawigacja</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="Indeks ogólny"
>indeks</a></li>
<li class="right" >
<a href="../python.html" title="Python MapScript Appendix"
>dalej</a> |</li>
<li class="right" >
<a href="migration_guide.html" title="PHP MapScript Migration Guide"
>wstecz</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" >MapScript</a> »</li>
<li class="nav-item nav-item-3"><a href="index.html" >PHP MapScript</a> »</li>
<li class="nav-item nav-item-this"><a href="">By Example</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© <a href="../../copyright.html">Copyright</a> 2026, Open Source Geospatial Foundation.
Ostatnia modyfikacja 2026-04-20.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 9.1.0.
</div>
</body>
</html>