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 = "global.map"; // Create a mapObj, initialized with the mapfile above $mapobject = ms_newMapObj($mapfile); // Create an imgObj that has an image of the map $mapimage = $mapobject->draw( ); // Save the mapimage to a file $mapimage->saveImage("worldmap.png"); ?> Example 14-8. Java MapScript basic example import edu.umn.gis.mapscript.*; public class map1 { public static void main(String[] args) { System.loadLibrary("mapscript"); mapObj mapobject; imageObj mapimage; String mapfile; // Set the map file to use mapfile = "global.map"; // Create a mapObj, initilized with the mapfile above mapobject = new 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",mapobject); } } Example 14-9. Ruby MapScript basic example # map1.rb # Ruby MapScript Example 1 require "mapscript" include Mapscript # Set the map file to use mapfile = "global.map" # Create a mapObj, initialized with the mapfile above mapobject = MapObj.new(mapfile) # Create an imgObj that has an image of the map mapimage = mapobject.draw # Save the mapimage to a file mapimage.save("worldmap.png") |