Skip to Content
Web Mapping Illustrated
book

Web Mapping Illustrated

by Tyler Mitchell
June 2005
Beginner to intermediate
372 pages
10h 1m
English
O'Reilly Media, Inc.
Content preview from Web Mapping Illustrated

Parallel MapScript Translations

A simple example is shown in this section using multiple scripting programming languages. Examples 14-5 through 14-9 provide a reference point for programmers who want to see how MapScript can be used in various languages. All these examples do the exact same thing—open a map file, draw the map, and save it to an image file. They are meant to be run in the same folder as the global.map map file, and they all produce an image file called worldmap.png.

Example 14-5. Python MapScript basic example

# map1.py
# Python MapScript Example 1

import mapscript

# Set the map file to use
mapfile = "global.map"

# Create a mapObj, initialized with the mapfile above
mapobject = mapscript.mapObj(mapfile)

# Create an imgObj that has an image of the map
mapimage = mapobject.draw()

# Save the mapimage to a file
mapimage.save("worldmap.png")

Example 14-6. Perl MapScript basic example

# map1.pl
# Perl MapScript Example 1

use mapscript;

# Set the map file to use
$mapfile = "global.map";

# Create a mapObj, initialized with the mapfile above
$mapobject = new mapscript::mapObj($mapfile);

# Create an imgObj that has an image of the map
$mapimage = $mapobject->draw();

# Save the mapimage to a file
$mapimage->save("worldmap.png");

Example 14-7. PHP MapScript basic example

<?PHP // map1.php // PHP MapScript Example 1 // MapScript extension could also be loaded in php.ini if (!extension_loaded("MapScript")) dl('php_mapscript.'.PHP_SHLIB_SUFFIX); // Set the map file to use $mapfile = ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Flask Web Development, 2nd Edition

Flask Web Development, 2nd Edition

Miguel Grinberg

Publisher Resources

ISBN: 0596008651Supplemental ContentErrata Page