Skip to content

Mapserver module api

Paul Spencer edited this page Nov 19, 2010 · 10 revisions

Module | Error | Map | Layer

Mapserver Module API

Defined Values

Most of the MS_XXXXX values are defined as constants through the mapserver module, for instance:

var mapserver = require('mapserver');
console.log('MS_ON value is ' + mapserver.MS_ON);

outputs

MS_ON value is 1

Module Methods

These methods are invoked directly on the module after it has been required.

getVersion

returns the version information for mapserver as a string value

Example:

require('mapserver').getVersion();

returns

MapServer version 5.6.5 OUTPUT=GIF OUTPUT=PNG OUTPUT=WBMP OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=CAIRO SUPPORTS=FREETYPE SUPPORTS=ICONV SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=GEOS INPUT=EPPL7 INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE

getVersionInt

Returns the version number for mapserver as an integer value.

Example:

require('mapserver').getVersionInt();

returns

 50605

loadMap

Returns a Map object for the map file at the specified path.

Arguments are:

  • mapfile - required string, path to the map file to open, relative to the process working directory
  • path - optional string, path for mapserver with relative paths defined in the map file, assumed to be the process working directory if not set

TODO: path is currently required, make optional

Returns a Map object.

Throws an Error exception if the map could not be loaded. Use getError() to get specific details about the error that happened.

Example:

var mapserver = require('mapserver');
try {
    var map = mapserver.loadMap('test.map');
} catch (e) {
    var err = mapserver.getError();
    console.log('Error ' + err.code + '('+ err.codeStr +') in ' + err.routine + ':' + err.message);
}

getError

Returns the next error in the mapserver error stack or undefined if there are no more errors.

Example: see loadMap() example.