.. _php: ***************************************************************************** PHP MapScript ***************************************************************************** :Author: Daniel Morissette :Contact: dmorissette at mapgears.com :Author: Yewondwossen Assefa :Contact: yassefa at dmsolutions.ca :Revision: $Revision$ :Date: $Date$ .. toctree:: :maxdepth: 2 class-intro by_example .. contents:: :depth: 2 :backlinks: top .. index:: pair: MapScript; php This is a PHP module to make MapServer's MapScript functionalities available in a PHP Dynamically Loadable Library. PHP MapScript was originally developed for PHP-3.0.14 but after MapServer 3.5 support for PHP3 has been dropped and as of the last update of this document, PHP 4.1.2 or more recent was required. The module has been tested and used on Linux, Solaris, \*BSD, and WinNT. There are documentation and examples for PHP MapScript available via the MapServer :ref:`documentation ` See also the MapServer Wiki for links to more information on this module: http://trac.osgeo.org/mapserver/wiki/PHPMapScript Very important notes --------------------- - Constant names and class member variable names are case-sensitive in PHP. - Several MapScript functions (all those that access files in the back end such as ms_newMapObj(), drawMap(), etc) will affect the value of the current working directory (CWD) in the PHP environment. This will be fixed eventually but in the meantime you should be careful about these side-effects. .. index:: single: php; constants Constants ---------- The following MapServer constants are available: Boolean values MS_TRUE, MS_FALSE, MS_ON, MS_OFF, MS_YES, MS_NO Map units MS_INCHES, MS_FEET, MS_MILES, MS_METERS, MS_KILOMETERS, MS_DD, MS_PIXELS Layer types MS_LAYER_POINT, MS_LAYER_LINE, MS_LAYER_POLYGON, MS_LAYER_RASTER, MS_LAYER_ANNOTATION, MS_LAYER_QUERY, MS_LAYER_CIRCLE, MS_LAYER_TILEINDEX, MS_LAYER_CHART Layer/Legend/Scalebar/Class Status MS_ON, MS_OFF, MS_DEFAULT, MS_EMBED, MS_DELETE Layer alpha transparency allows alpha transparent pixmaps to be used with RGB map images MS_GD_ALPHA Font types MS_TRUETYPE, MS_BITMAP Label positions MS_UL, MS_LR, MS_UR, MS_LL, MS_CR, MS_CL, MS_UC, MS_LC, MS_CC, MS_AUTO, MS_XY, MS_FOLLOW Bitmap font styles MS_TINY , MS_SMALL, MS_MEDIUM, MS_LARGE, MS_GIANT Shape types MS_SHAPE_POINT, MS_SHAPE_LINE, MS_SHAPE_POLYGON, MS_SHAPE_NULL Shapefile types MS_SHP_POINT, MS_SHP_ARC, MS_SHP_POLYGON, MS_SHP_MULTIPOINT Query/join types MS_SINGLE, MS_MULTIPLE Querymap styles MS_NORMAL, MS_HILITE, MS_SELECTED Connection Types MS_INLINE, MS_SHAPEFILE, MS_TILED_SHAPEFILE, MS_SDE, MS_OGR, MS_TILED_OGR, MS_POSTGIS, MS_WMS, MS_ORACLESPATIAL, MS_WFS, MS_GRATICULE, MS_MYGIS, MS_RASTER, MS_PLUGIN Error codes MS_NOERR, MS_IOERR, MS_MEMERR, MS_TYPEERR, MS_SYMERR, MS_REGEXERR, MS_TTFERR, MS_DBFERR, MS_GDERR, MS_IDENTERR, MS_EOFERR, MS_PROJERR, MS_MISCERR, MS_CGIERR, MS_WEBERR, MS_IMGERR, MS_HASHERR, MS_JOINERR, MS_NOTFOUND, MS_SHPERR, MS_PARSEERR, MS_SDEERR, MS_OGRERR, MS_QUERYERR, MS_WMSERR, MS_WMSCONNERR, MS_ORACLESPATIALERR, MS_WFSERR, MS_WFSCONNERR, MS_MAPCONTEXTERR, MS_HTTPERR, MS_WCSERR Symbol types MS_SYMBOL_SIMPLE, MS_SYMBOL_VECTOR, MS_SYMBOL_ELLIPSE, MS_SYMBOL_PIXMAP, MS_SYMBOL_TRUETYPE, MS_SYMBOL_CARTOLINE Image Mode types (:ref:`outputFormatObj `) MS_IMAGEMODE_PC256, MS_IMAGEMODE_RGB, MS_IMAGEMODE_RGBA, MS_IMAGEMODE_INT16, MS_IMAGEMODE_FLOAT32, MS_IMAGEMODE_BYTE, MS_IMAGEMODE_NULL Style/Attribue binding MS_STYLE_BINDING_SIZE, MS_STYLE_BINDING_ANGLE, MS_STYLE_BINDING_COLOR, MS_STYLE_BINDING_OUTLINECOLOR, MS_STYLE_BINDING_SYMBOL Label/Attribute binding MS_LABEL_BINDING_SIZE, MS_LABEL_BINDING_ANGLE, MS_LABEL_BINDING_COLOR, MS_LABEL_BINDING_OUTLINECOLOR, MS_LABEL_BINDING_FONT, MS_LABEL_BINDING_PRIORITY Alignment MS_ALIGN_LEFT, MS_ALIGN_CENTER, MS_ALIGN_RIGHT OwsRequest MS_GET_REQUEST, MS_POST_REQUEST Functions ---------- string ms_GetVersion() Returns the MapServer version and options in a string. This string can be parsed to find out which modules were compiled in, etc. int ms_GetVersionInt() Returns the MapServer version number (x.y.z) as an integer (x*10000 + y*100 + z). (New in v5.0) e.g. V5.4.3 would return 50403. array ms_TokenizeMap(string map_file_name) Preparses a mapfile through the MapServer parser and return an array with one item for each token from the mapfile. Strings, logical expressions, regex expressions and comments are returned as individual tokens. void ms_ioinstallstdouttobuffer() Installs a mapserver IO handler directing future stdout output to a memory buffer. void ms_ioinstallstdinfrombuffer() Installs a mapserver IO handler directing future stdin reading (ie. post request capture) to come from a buffer. void ms_iogetstdoutbufferstring() Fetch the current stdout buffer contents as a string. This method does not clear the buffer. int ms_iogetStdoutBufferBytes() Writes the current buffer to stdout. The PHP header() function should be used to set the documents's content-type prior to calling the function. Returns the number of bytes written if output is sent to stdout. See :ref:`mapscript_ows` for more info. void ms_ioresethandlers() Resets the default stdin and stdout handlers in place of "buffer" based handlers. void ms_iostripstdoutbuffercontenttype() Strip the Content-type header off the stdout buffer if it has one, and if a content type is found it is return. Otherwise return false. MapObj Class ------------- Constructor ............................................................................... mapObj ms_newMapObj(string map_file_name [, string new_map_path]) Returns a new object to deal with a MapServer map file. mapObj ms_newMapObjFromString(string map_file_string [, string new_map_path]) Construct a new mapObj from a mapfile string. Returns a new object to deal with a MapServer map file. .. note:: By default, the SYMBOLSET, FONTSET, and other paths in the mapfile are relative to the mapfile location. If new_map_path is provided then this directory will be used as the base path for all the relative paths inside the mapfile. Members ............................................................................... =============== =============================================================== Type Name =============== =============================================================== int numlayers (read-only) string name int status int debug int width (see setSize()) int height (see setSize()) int maxsize outputformatObj outputformat double resolution (pixels per inch, defaults to 72) rectObj extent; double cellsize int units (map units type) double scaledenom (read-only, set by drawMap()) double scale (Deprecated in v5.0. Use scaledenom instead) string shapepath int keysizex int keysizey int keyspacingx int keyspacingy webObj web referenceMapObj reference colorObj imagecolor scalebarObj scalebar legendObj legend string symbolsetfilename (read-only, set by setSymbolSet()) string fontsetfilename (read-only, set by setFontSet()) labelcacheObj labelcache (no members. Used only to be able to free the the label cache (ex : map->labelcache->free()) projectionObj projection int transparent (deprecated, use outputFormatObj) int interlace (deprecated, use outputFormatObj) int imagetype (deprecated, use outputFormatObj) int imagequality (deprecated, use outputFormatObj) =============== =============================================================== Methods ............................................................................... mapObj clone() Returns a handle to a new mapObj which is a clone of the current mapObj. All parameters in the current mapObj are copied to the new mapObj. Returns NULL (0) on error. int set(string property_name, new_value) Set map object property to new value. Returns -1 on error. int getsymbolbyname(string symbol_name) Returns the symbol index using the name. symbol getsymbolobjectbyid(int symbolid) Returns the symbol object using a symbol id. Refer to the symbol object reference section for more details. void preparequery() Calculate the scale of the map and set map->scaledenom. imageObj prepareImage() Return handle on blank image object. imageObj draw() Render map and return handle on image object. imageObj drawQuery() Render a query map and return handle on image object. imageObj drawLegend() Render legend and return handle on image object. imageObj drawReferenceMap() Render reference map and return handle on image object. imageObj drawScaleBar() Render scale bar and return handle on image object. int embedlegend(imageObj image) embeds a legend. Actually the legend is just added to the label cache so you must invoke drawLabelCache() to actually do the rendering (unless postlabelcache is set in which case it is drawn right away). int embedScalebar(imageObj image) embeds a scalebar. Actually the scalebar is just added to the label cache so you must invoke drawLabelCache() to actually do the rendering (unless postlabelcache is set in which case it is drawn right away). int drawLabelCache(imageObj image) Renders the labels for a map. Returns -1 on error. layerObj getLayer(int index) Returns a layerObj from the map given an index value (0=first layer) layerObj getLayerByName(string layer_name) Returns a layerObj from the map given a layer name. Returns FALSE if layer doesn't exist. colorObj getcolorbyindex(int iCloIndex) Returns a colorObj corresponding to the color index in the palette void setExtent(double minx, double miny, double maxx, double maxy) Set the map extents using the georef extents passed in argument. int setRotation(double rotation_angle) Set map rotation angle. The map view rectangle (specified in EXTENTS) will be rotated by the indicated angle in the counter- clockwise direction. Note that this implies the rendered map will be rotated by the angle in the clockwise direction. Returns MS_SUCCESS or MS_FAILURE. int setSize(int width, int height) Set the map width and height. This method updates the internal geotransform and other data structures required for map rotation so it should be used instead of setting the width and height members directly. Returns MS_SUCCESS or MS_FAILURE. void zoompoint(int nZoomFactor, pointObj oPixelPos, int nImageWidth, int nImageHeight, rectObj oGeorefExt) Zoom to a given XY postion. Parameters are : - Zoom factor : positive values do zoom in, negative values zoom out. Factor of 1 will recenter. - Pixel position (pointObj) : x, y coordinates of the click, with (0,0) at the top-left - Width : width in pixel of the current image. - Height : Height in pixel of the current image. - Georef extent (rectObj) : current georef extents. - MaxGeoref extent (rectObj) : (optional) maximum georef extents. If provided then it will be impossible to zoom/pan outside of those extents. void zoomrectangle(rectObj oPixelExt, int nImageWidth, int nImageHeight, rectObj oGeorefExt) Set the map extents to a given extents. Parameters are : - oPixelExt (rect object) : Pixel Extents, with (0,0) at the top-left The rectangle contains the coordinates of the LL and UR coordinates in pixel. (the maxy in the rect object should be < miny value) :: ------- UR (values in the rect object : maxx, maxy) | | | | | | ------ LL (values in the rectobject minx, miny) - Width : width in pixel of the current image. - Height : Height in pixel of the current image. - Georef extent (rectObj) : current georef extents. void zoomscale(double nScaleDenom, pointObj oPixelPos, int nImageWidth, int nImageHeight, rectObj oGeorefExt [, rectObj oMaxGeorefExt]) Zoom in or out to a given XY position so that the map is displayed at specified scale. Parameters are : - ScaleDenom : Scale denominator of the scale at which the map should be displayed. - Pixel position (pointObj) : x, y coordinates of the click, with (0,0) at the top-left - Width : width in pixel of the current image. - Height : Height in pixel of the current image. - Georef extent (rectObj) : current georef extents. - MaxGeoref extent (rectObj) : (optional) maximum georef extents. If provided then it will be impossible to zoom/pan outside of those extents. int queryByPoint(pointObj point, int mode, double buffer) Query all selected layers in map at point location specified in georeferenced map coordinates (i.e. not pixels). The query is performed on all the shapes that are part of a :ref:`CLASS` that contains a :ref:`TEMPLATE` value or that match any class in a layer that contains a :ref:`LAYER` :ref:`TEMPLATE