mapObj
final class mapObj (View source)
Properties
float | $cellsize | ||
int | $debug | ||
float | $defresolution | pixels per inch, defaults to 72 |
|
rectObj | $extent | ; | |
string | $fontsetfilename | read-only, set by setFontSet() |
|
int | $height | see setSize() |
|
colorObj | $imagecolor | ||
int | $keysizex | ||
int | $keysizey | ||
int | $keyspacingx | ||
int | $keyspacingy | ||
labelcacheObj | $labelcache | no members. Used only to free the label cache (map->labelcache->free() |
|
legendObj | $legend | ||
string | $mappath | ||
int | $maxsize | ||
hashTableObj | $metadata | ||
string | $name | ||
int | $numlayers | read-only | |
outputformatObj | $outputformat | ||
int | $numoutputformats | read-only | |
projectionObj | $projection | ||
querymapObj | $querymap | ||
referenceMapObj | $reference | ||
float | $resolution | pixels per inch, defaults to 72 |
|
scalebarObj | $scalebar | ||
float | $scaledenom | read-only, set by drawMap() |
|
string | $shapepath | ||
int | $status | ||
string | $symbolsetfilename | read-only, set by setSymbolSet() |
|
int | $units | map units type |
|
webObj | $web | ||
int | $width | see setSize() |
Methods
Returns a new object to deal with a MapServer map file.
Old style constructor
Applies the config options set in the map file. For example setting the PROJ_LIB using the setconfigoption only modifies the value in the map object. applyconfigoptions will actually change the PROJ_LIB value that will be used when dealing with projection.
Apply the :ref:SLD
document to the map file. The matching between the
sld document and the map file will be done using the layer's name.
Apply the SLD document pointed by the URL to the map file. The matching between the sld document and the map file will be done using the layer's name.
Saves the object to a string.
Renders the labels for a map. Returns MS_SUCCESS or MS_FAILURE on error.
Render legend and return an image object.
Render reference map and return an image object.
Render scale bar and return an image object.
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). Returns MS_SUCCESS or MS_FAILURE on error.
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).
Free the object properties and break the internal references.
Returns an SLD XML string based on all the classes found in all
the layers that have STATUS
on
.
Return an array containing all the group names used in the layers. If there are no groups, it returns an empty array.
Return an array containing all the layer names.
Returns a colorObj corresponding to the color index in the palette.
Returns the config value associated with the key.
Returns a labelcacheMemberObj from the map given an index value (0=first label). Labelcache has to be enabled.
Returns a layerObj from the map given a layer name.
Return an array containing layer's index in the order which they are drawn. If there are no layers, it returns an empty array.
Return an array containing all the layer's indexes given a group name. If there are no layers, it returns an empty array.
Fetch metadata entry by name (stored in the :ref:WEB
object in
the map file). Returns "" if no entry matches the name.
Return the number of symbols in map.
Returns a string representation of the projection.
Returns the symbol index using the name.
Returns the symbol object using a symbol id. Refer to the symbol object reference section for more details.
Available only if WMS support is enabled. Load a :ref:WMS Map Context <map_context>
XML file into the current mapObj. If the
map already contains some layers then the layers defined in the
WMS Map context document are added to the current map. The 2nd
argument unique_layer_name is optional and if set to MS_TRUE
layers created will have a unique name (unique prefix added to the
name). If set to MS_FALSE the layer name will be the the same name
as in the context. The default value is MS_FALSE. Returns
MS_SUCCESS/MS_FAILURE.
Load OWS request parameters (BBOX, LAYERS, &c.) into map. Returns MS_SUCCESS or MS_FAILURE. 2nd argument version is not mandatory.
Move layer down in the hierarchy of drawing.
Move layer up in the hierarchy of drawing.
Offset the map extent based on the given distances in map coordinates.
Processes and executes the passed OpenGIS Web Services request on
the map. Returns MS_DONE (2) if there is no valid OWS request in
the req object, MS_SUCCESS (0) if an OWS request was successfully
processed and MS_FAILURE (1) if an OWS request was not
successfully processed. OWS requests include :ref:WMS <wms_server>
,
:ref:WFS <wfs_server>
, :ref:WCS <wcs_server>
and :ref:SOS <sos_server>
requests supported by MapServer.
Return a blank image object.
Calculate the scale of the map and set map->scaledenom.
Process legend template files and return the result in a buffer.
Process query template files and return the result in a buffer.
Process the template file specified in the web object and return the result in a buffer. The processing consists of opening the template file and replace all the tags found in it. Only tags that have an equivalent element in the map object are replaced (ex [scaledenom]).
Perform a query based on a previous set of results from a layer. At present the results MUST be based on a polygon layer.
Add a specific shape on a given layer to the query result.
Query all selected layers in map at point location specified in georeferenced map coordinates (i.e. not pixels).
Query all selected layers in map using a rectangle 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 <template>
value. Returns MS_SUCCESS if shapes were found or MS_FAILURE if
nothing was found or if some other error happened (note that the
error message in case nothing was found can be avoided in PHP
using the '@' control operator).
Query all selected layers in map based on a single shape, the shape has to be a polygon at this point.
Remove a layer from the mapObj. The argument is the index of the layer to be removed. Returns the removed layerObj on success, else null.
Remove a metadata entry for the map (stored in the WEB object in the map file). Returns MS_SUCCESS/MS_FAILURE.
Save current map object state to a file. Returns -1 on error.
Available only if WMS support is enabled. Save current map object
state in :ref:WMS Map Context <map_context>
format. Only WMS
layers are saved in the WMS Map Context XML file. Returns
MS_SUCCESS/MS_FAILURE.
Save the current query in a file. Results determines the save format - MS_TRUE (or 1/true) saves the query results (tile index and shape index), MS_FALSE (or 0/false) the query parameters (and the query will be re-run in loadquery). Returns MS_SUCCESS or MS_FAILURE. Either save format can be used with loadquery. See RFC 65 and ticket #3647 for details of different save formats.
Scale the map extent using the zoomfactor and ensure the extent within the minscaledenom and maxscaledenom domain. If minscaledenom and/or maxscaledenom is 0 then the parameter is not taken into account. Returns MS_SUCCESS or MS_FAILURE.
Selects the output format to be used in the map.
Appends outputformat object in the map object.
Remove outputformat from the map.
Returns the outputformat at index position.
Set map object property to new value.
Sets a config parameter using the key and the value passed
Set the map extents using the georef extents passed in argument.
Load and set a new :ref:fontset
.
Set a metadata entry for the map (stored in the WEB object in the map file). Returns MS_SUCCESS/MS_FAILURE.
Set map projection and coordinate system. Returns MS_SUCCESS or MS_FAILURE on error.
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.
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.
Load and set a symbol file dynamically.
Same as setProjection(), but takes an OGC WKT projection definition string as input. Returns MS_SUCCESS or MS_FAILURE on error.
Set the map extents to a given extents. Returns MS_SUCCESS or MS_FAILURE on error.
Details
final
__construct(string $map_file_name, string $new_map_path)
Returns a new object to deal with a MapServer map file.
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 rewlative paths inside the mapfile.
final mapObj
ms_newMapObjFromString(string $map_file_string, string $new_map_path)
Old style constructor
final int
applyconfigoptions()
Applies the config options set in the map file. For example setting the PROJ_LIB using the setconfigoption only modifies the value in the map object. applyconfigoptions will actually change the PROJ_LIB value that will be used when dealing with projection.
final int
applySLD(string $sldxml)
Apply the :ref:SLD
document to the map file. The matching between the
sld document and the map file will be done using the layer's name.
See :ref:SLD HowTo <sld>
for more information on the SLD support.
final int
applySLDURL(string $sldurl)
Apply the SLD document pointed by the URL to the map file. The matching between the sld document and the map file will be done using the layer's name.
See :ref:SLD HowTo <sld>
for more information on the SLD support.
final string
convertToString()
Saves the object to a string.
.. note:: The inverse method updateFromString does not exist for the mapObj .. versionadded:: 6.4
final imageObj|null
draw()
Render map and return an image object or NULL on error.
final int
drawLabelCache(imageObj $image)
Renders the labels for a map. Returns MS_SUCCESS or MS_FAILURE on error.
final imageObj
drawLegend()
Render legend and return an image object.
final imageObj|null
drawQuery()
Render a query map and return an image object or NULL on error.
final imageObj
drawReferenceMap()
Render reference map and return an image object.
final imageObj
drawScaleBar()
Render scale bar and return an image object.
final 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). Returns MS_SUCCESS or MS_FAILURE on error.
final 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).
Returns MS_SUCCESS or MS_FAILURE on error.
final void
free()
Free the object properties and break the internal references.
Note that you have to unset the php variable to free totally the resources. void freeQuery(layerindex) Frees the query result on a specified layer. If the layerindex is -1, all queries on layers will be freed.
final string
generateSLD()
Returns an SLD XML string based on all the classes found in all
the layers that have STATUS
on
.
final array
getAllGroupNames()
Return an array containing all the group names used in the layers. If there are no groups, it returns an empty array.
final array
getAllLayerNames()
Return an array containing all the layer names.
If there are no layers, it returns an empty array.
final colorObj
getColorbyIndex(int $iCloIndex)
Returns a colorObj corresponding to the color index in the palette.
final string
getConfigOption(string $key)
Returns the config value associated with the key.
Returns an empty sting if key not found.
final labelcacheMemberObj
getLabel(int $index)
Returns a labelcacheMemberObj from the map given an index value (0=first label). Labelcache has to be enabled.
.. code-block:: php while ($oLabelCacheMember = $oMap->getLabel($i)) { do something with the labelcachemember ++$i; }
final layerObj
getLayer(int $index)
Returns a layerObj from the map given an index value (0=first layer)
final layerObj
getLayerByName(string $layer_name)
Returns a layerObj from the map given a layer name.
Returns NULL if layer doesn't exist.
final array
getLayersDrawingOrder()
Return an array containing layer's index in the order which they are drawn. If there are no layers, it returns an empty array.
final array
getLayersIndexByGroup(string $groupname)
Return an array containing all the layer's indexes given a group name. If there are no layers, it returns an empty array.
final int
getMetaData(string $name)
Fetch metadata entry by name (stored in the :ref:WEB
object in
the map file). Returns "" if no entry matches the name.
.. note:: getMetaData's query is case sensitive.
final int
getNumSymbols()
Return the number of symbols in map.
final string
getProjection()
Returns a string representation of the projection.
Returns NULL on error or if no projection is set.
final int
getSymbolByName(string $symbol_name)
Returns the symbol index using the name.
final symbolObj
getSymbolObjectById(int $symbolid)
Returns the symbol object using a symbol id. Refer to the symbol object reference section for more details.
int insertLayer( layerObj layer [, int nIndex=-1 ] ) Insert a copy of layer into the Map at index nIndex. The default value of nIndex is -1, which means the last possible index. Returns the index of the new Layer, or -1 in the case of a failure.
final int
loadMapContext(string $filename, bool $unique_layer_name)
Available only if WMS support is enabled. Load a :ref:WMS Map Context <map_context>
XML file into the current mapObj. If the
map already contains some layers then the layers defined in the
WMS Map context document are added to the current map. The 2nd
argument unique_layer_name is optional and if set to MS_TRUE
layers created will have a unique name (unique prefix added to the
name). If set to MS_FALSE the layer name will be the the same name
as in the context. The default value is MS_FALSE. Returns
MS_SUCCESS/MS_FAILURE.
final int
loadOWSParameters(OwsrequestObj $request, string $version)
Load OWS request parameters (BBOX, LAYERS, &c.) into map. Returns MS_SUCCESS or MS_FAILURE. 2nd argument version is not mandatory.
If not given, the version will be set to 1.1.1 int loadQuery(filename) Loads a query from a file. Returns MS_SUCCESS or MS_FAILURE. To be used with savequery.
final int
moveLayerDown(int $layerindex)
Move layer down in the hierarchy of drawing.
Returns MS_SUCCESS or MS_FAILURE on error.
final int
moveLayerUp(int $layerindex)
Move layer up in the hierarchy of drawing.
Returns MS_SUCCESS or MS_FAILURE on error.
final int
offsetExtent(float $x, float $y)
Offset the map extent based on the given distances in map coordinates.
Returns MS_SUCCESS or MS_FAILURE.
final int
owsDispatch(OwsrequestObj $request)
Processes and executes the passed OpenGIS Web Services request on
the map. Returns MS_DONE (2) if there is no valid OWS request in
the req object, MS_SUCCESS (0) if an OWS request was successfully
processed and MS_FAILURE (1) if an OWS request was not
successfully processed. OWS requests include :ref:WMS <wms_server>
,
:ref:WFS <wfs_server>
, :ref:WCS <wcs_server>
and :ref:SOS <sos_server>
requests supported by MapServer.
Results of a dispatched request are written to stdout and can be captured using the msIO services (ie. ms_ioinstallstdouttobuffer() and ms_iogetstdoutbufferstring())
final imageObj
prepareImage()
Return a blank image object.
final void
prepareQuery()
Calculate the scale of the map and set map->scaledenom.
final string
processLegendTemplate(array $params)
Process legend template files and return the result in a buffer.
.. seealso::
:ref:processtemplate <processtemplate>
final string
processQueryTemplate(array $params, bool $generateimages)
Process query template files and return the result in a buffer.
Second argument generateimages is not mandatory. If not given
it will be set to TRUE.
.. seealso::
:ref:processtemplate <processtemplate>
.. _processtemplate:
final string
processTemplate(array $params, bool $generateimages)
Process the template file specified in the web object and return the result in a buffer. The processing consists of opening the template file and replace all the tags found in it. Only tags that have an equivalent element in the map object are replaced (ex [scaledenom]).
The are two exceptions to the previous statement :
- [img], [scalebar], [ref], [legend] would be replaced with the appropriate url if the parameter generateimages is set to MS_TRUE. (Note : the images corresponding to the different objects are generated if the object is set to MS_ON in the map file)
- the user can use the params parameter to specify tags and their values. For example if the user have a specific tag call [my_tag] and would like it to be replaced by "value_of_my_tag" he would do .. code-block:: php $tmparray["my_tag"] = "value_of_my_tag"; $map->processtemplate($tmparray, MS_FALSE);
final int
queryByFeatures(int $slayer)
Perform a query based on a previous set of results from a layer. At present the results MUST be based on a polygon layer.
Returns MS_SUCCESS if shapes were found or MS_FAILURE if nothing was found or if some other error happened (note that the error message in case nothing was found can be avoided in PHP using the '@' control operator).
final int
queryByIndex($layerindex, $tileindex, $shapeindex, $addtoquery)
Add a specific shape on a given layer to the query result.
If addtoquery (which is a non mandatory argument) is set to MS_TRUE, the shape will be added to the existing query list. Default behavior is to free the existing query list and add only the new shape.
final int
queryByPoint(pointObj $point, int $mode, float $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 <template>
value.
Mode is MS_SINGLE or MS_MULTIPLE depending on number of results
you want.
Passing buffer -1 defaults to tolerances set in the map file
(in pixels) but you can use a constant buffer (specified in
ground units) instead.
Returns MS_SUCCESS if shapes were found or MS_FAILURE if nothing
was found or if some other error happened (note that the error
message in case nothing was found can be avoided in PHP using
the '@' control operator).
final int
queryByRect(rectObj $rect)
Query all selected layers in map using a rectangle 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 <template>
value. Returns MS_SUCCESS if shapes were found or MS_FAILURE if
nothing was found or if some other error happened (note that the
error message in case nothing was found can be avoided in PHP
using the '@' control operator).
final int
queryByShape(shapeObj $shape)
Query all selected layers in map based on a single shape, the shape has to be a polygon at this point.
Returns MS_SUCCESS if shapes were found or MS_FAILURE if nothing was found or if some other error happened (note that the error message in case nothing was found can be avoided in PHP using the '@' control operator).
final layerObj
removeLayer(int $nIndex)
Remove a layer from the mapObj. The argument is the index of the layer to be removed. Returns the removed layerObj on success, else null.
final int
removeMetaData(string $name)
Remove a metadata entry for the map (stored in the WEB object in the map file). Returns MS_SUCCESS/MS_FAILURE.
final int
save(string $filename)
Save current map object state to a file. Returns -1 on error.
Use absolute path. If a relative path is used, then it will be relative to the mapfile location.
final int
saveMapContext(string $filename)
Available only if WMS support is enabled. Save current map object
state in :ref:WMS Map Context <map_context>
format. Only WMS
layers are saved in the WMS Map Context XML file. Returns
MS_SUCCESS/MS_FAILURE.
final int
saveQuery(string $filename, int $results)
Save the current query in a file. Results determines the save format - MS_TRUE (or 1/true) saves the query results (tile index and shape index), MS_FALSE (or 0/false) the query parameters (and the query will be re-run in loadquery). Returns MS_SUCCESS or MS_FAILURE. Either save format can be used with loadquery. See RFC 65 and ticket #3647 for details of different save formats.
final int
scaleExtent(float $zoomfactor, float $minscaledenom, float $maxscaledenom)
Scale the map extent using the zoomfactor and ensure the extent within the minscaledenom and maxscaledenom domain. If minscaledenom and/or maxscaledenom is 0 then the parameter is not taken into account. Returns MS_SUCCESS or MS_FAILURE.
final int
selectOutputFormat(string $type)
Selects the output format to be used in the map.
Returns MS_SUCCESS/MS_FAILURE. .. note:: the type used should correspond to one of the output formats declared in the map file. The type argument passed is compared with the mimetype parameter in the output format structure and then to the name parameter in the structure.
final int
appendOutputFormat(outputFormatObj $outputFormat)
Appends outputformat object in the map object.
Returns the new numoutputformats value.
final int
removeOutputFormat(string $name)
Remove outputformat from the map.
Returns MS_SUCCESS/MS_FAILURE.
final outputFormatObj
getOutputFormat(int $index)
Returns the outputformat at index position.
final int
set(string $property_name, $new_value)
Set map object property to new value.
final int
setCenter(pointObj $center)
Set the map center to the given map point.
Returns MS_SUCCESS or MS_FAILURE.
final int
setConfigOption(string $key, string $value)
Sets a config parameter using the key and the value passed
final void
setExtent(float $minx, float $miny, float $maxx, float $maxy)
Set the map extents using the georef extents passed in argument.
Returns MS_SUCCESS or MS_FAILURE on error.
final int
setFontSet(string $fileName)
Load and set a new :ref:fontset
.
boolean setLayersDrawingOrder(array layeryindex) Set the layer's order array. The argument passed must be a valid array with all the layer's index. Returns MS_SUCCESS or MS_FAILURE on error.
final int
setMetaData(string $name, string $value)
Set a metadata entry for the map (stored in the WEB object in the map file). Returns MS_SUCCESS/MS_FAILURE.
final int
setProjection(string $proj_params, bool $bSetUnitsAndExtents)
Set map projection and coordinate system. Returns MS_SUCCESS or MS_FAILURE on error.
Parameters are given as a single string of comma-delimited PROJ.4 parameters. The argument : bSetUnitsAndExtents is used to automatically update the map units and extents based on the new projection. Possible values are MS_TRUE and MS_FALSE. By default it is set at MS_FALSE.
final int
setRotation(float $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.
final 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.
final int
setSymbolSet(string $fileName)
Load and set a symbol file dynamically.
final int
setWKTProjection(string $proj_params, bool $bSetUnitsAndExtents)
Same as setProjection(), but takes an OGC WKT projection definition string as input. Returns MS_SUCCESS or MS_FAILURE on error.
.. note:: setWKTProjection requires GDAL support
final int
zoomPoint(int $nZoomFactor, pointObj $oPixelPos, int $nImageWidth, int $nImageHeight, rectObj $oGeorefExt)
Zoom to a given XY position. Returns MS_SUCCESS or MS_FAILURE on error.
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.
final int
zoomRectangle(rectObj $oPixelExt, int $nImageWidth, int $nImageHeight, rectObj $oGeorefExt)
Set the map extents to a given extents. Returns MS_SUCCESS or MS_FAILURE on error.
Parameters are :
- oPixelExt (rect object) : Pixel Extents
- Width : width in pixel of the current image.
- Height : Height in pixel of the current image.
- Georef extent (rectObj) : current georef extents.
final int
zoomScale(float $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. Returns MS_SUCCESS or MS_FAILURE on error.
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.