The main purpose of this cfc is to make mapscript easier to access for Coldfusion developers. This CFC has been written with CF7 but should work equally well with any version from 6 up. It has not been tested using the BlueDragon server.
The mapscript component can be downloaded from Sibern Solutions you should be able to get it directly from here
To use mapserver/mapscript you will need to the following
Depending on the OS and which version of Coldfusion you are running, the installation will be different. You can email me at "simon [at] sibern.com.au" if you are stuck.
Have a read through the cfc and you will see that the different functions are using hints to descibe the functions and parameters.
To get you up and running fast you can use the following as an example of some cfscript.
msapi = createObject("component","mapscript");
msapi.init(savePath="/your/directory/to/save/to/", mapPath="/where/the/mapfiles/are/",
mapFile="mapfilename.map", shapePath="/the/location/to/the/shapefiles/");
mapinfo = msapi.createMap(legend="false", width="450", height="450");
There is a basic working demo called test.cfm which produces a world map with australian states.
Make mapscript easier to access
methods: addEndSlash, createJavaObjects, createLayerLegend, createMap, createSimpleLegend, evaluateString, findStructArrayValue, getConnectionObject, getExtents, getFileType, getFontFile, getLayerData, getLayerFilter, getLayerList, getLayerStatus, getMapFile, getMapObj, getMapPath, getPositionEnums, getSavePath, getShapePath, getUnitType, init, initConnectionTypes, initJavaObjects, isRelative, setExtents, setFileType, setFontFile, setLayerData, setLayerFilter, setLayerListStatus, setLayerStatus, setLegendStr, setMapFile, setMapPath, setSavePath, setScaleBar, setShapePath, setURLPath, throw, validPoints, versionGreaterOrEqual, zoom * - private methodaddEndSlash |
---|
package
addEndSlash
(
str="",
type="os"
)
Add a closing slash if required Output: suppressed Parameters: str: any, optional, str - A full or relative path type: any, optional, type - Is this a operating system or URL path |
createJavaObjects |
package
createJavaObjects
(
)
Create the required java objects Output: suppressed |
createLayerLegend |
public
string
createLayerLegend
(
required
numeric
layerId="0",
string
fileExt="gif",
numeric
iconHeight="15",
numeric
iconWidth="23",
boolean
reverseOrder="true",
string
legendStr="",
boolean
ignoreInvisible="true",
Any
layerObj=""
)
Create a legend for layer if the layer is visible Output: suppressed Parameters: layerId: numeric, required, layerId - The layer number fileExt: string, optional, fileExt - gif, png, jpg iconHeight: numeric, optional, iconHeight - Height of each legend icon iconWidth: numeric, optional, iconWidth - Width of each legend icon reverseOrder: boolean, optional, reverseOrder - Do you want the order of the legend to be reversed. Default: true legendStr: string, optional, legendStr - The legend item html to parse. This does not change the default legend for this instance of mapscript. Use setLegendStr to set default ignoreInvisible: boolean, optional, ignoreInvisible - Produce only the html for visible layers. Defaults to true layerObj: Any, optional, layerObj - If the layer object is already created then pass it here |
createMap |
public
struct
createMap
(
string
imageName="",
string
outputFormat="",
boolean
legend="false",
numeric
width="0",
numeric
height="0",
string
mapStr=""
)
Create an image from the current mapscript definitions Output: suppressed Parameters: imageName: string, optional, imageName - The filename of the saved image outputFormat: string, optional, outputFormat - The format and extension of the output image. If empty then it will use png. Currrently supports Built-in formats are PNG, PNG24, JPEG, GIF and GTIFF. legend: boolean, optional, legend - Do you want a legend image created as well. Default is false. width: numeric, optional, width - The width of the output image. height: numeric, optional, height - The height of the output image. mapStr: string, optional, mapStr - The map image html |
createSimpleLegend |
public
struct
createSimpleLegend
(
string
imageName="",
string
outputFormat="",
numeric
width="0",
numeric
height="0"
)
Create a legend for the map returning the legend image details Output: suppressed Parameters: imageName: string, optional, imageName - The filename of the saved image outputFormat: string, optional, outputFormat - The format and extension of the output image. If empty then it will use png. Currrently supports Built-in formats are PNG, PNG24, JPEG, GIF and GTIFF. width: numeric, optional, width - The width of the output image. height: numeric, optional, height - The height of the output image. |
evaluateString |
public
evaluateString
(
str="",
collection
)
Evaluate a string looking for any variable names then process and return completed string Output: suppressed Parameters: str: any, optional, str - The string with the CF code to be evaluated collection: any, optional, collection - Structure of collected variables |
findStructArrayValue |
package
findStructArrayValue
(
str="",
collection
)
If given a string that is a pointer to a structure with an array in it then find the associated value Output: suppressed Parameters: str: any, optional, str - The structure item name collection: any, optional, collection - Structure of collected variables |
getConnectionObject |
package
Any
getConnectionObject
(
required
string
connection
)
Return the connection object used by the layer object to define the data's source Output: enabled Parameters: connection: string, required, connection - The type of connection. |
getExtents |
public
struct
getExtents
(
)
Get the new extents for the current map. Output: suppressed |
getFileType |
public
string
getFileType
(
)
Get the path for map files Output: suppressed |
getFontFile |
public
string
getFontFile
(
)
Get the path for map files Output: suppressed |
getLayerData |
public
struct
getLayerData
(
layerName="",
layerId=""
)
Get the name of a data file. Output: suppressed Parameters: layerName: any, optional, layerName - The name of the layer layerId: any, optional, layerId - The ID of the layer |
getLayerFilter |
public
string
getLayerFilter
(
layerName="",
layerId=""
)
Get the current filter string for a layer. Output: suppressed Parameters: layerName: any, optional, layerName - The name of the layer layerId: any, optional, layerId - The ID of the layer |
getLayerList |
public
query
getLayerList
(
generateHtml="true",
numeric
iconHeight="15",
numeric
iconWidth="23",
boolean
reverseOrder="true",
string
legendStr=""
)
Get the layer names, ids and status Output: suppressed Parameters: generateHtml: any, optional, generateHtml - Shall the html be generated for the layer legend iconHeight: numeric, optional, iconHeight - Height of each legend icon iconWidth: numeric, optional, iconWidth - Width of each legend icon reverseOrder: boolean, optional, reverseOrder - Do you want the order of the legend to be reversed. Default: true legendStr: string, optional, legendStr - The legend item html |
getLayerStatus |
public
boolean
getLayerStatus
(
required
layerName,
layerId=""
)
Get the display status of a layer Output: suppressed Parameters: layerName: any, required, layerName - The name of the layer layerId: any, optional, layerId - The ID of the layer |
getMapFile |
public
string
getMapFile
(
)
Get the path for map files Output: suppressed |
getMapObj |
public
any
getMapObj
(
)
Get the path for map files Output: suppressed |
getMapPath |
public
string
getMapPath
(
)
Get the path for map files Output: suppressed |
getPositionEnums |
package
Any
getPositionEnums
(
required
string
position
)
Get the scalebar positions Output: suppressed Parameters: position: string, required, position - The location of the overlayed object |
getSavePath |
public
string
getSavePath
(
)
Get the save path for images Output: suppressed |
getShapePath |
public
string
getShapePath
(
)
Get the path for map files Output: suppressed |
getUnitType |
package
Any
getUnitType
(
required
string
unit
)
Get the scalebar measurement unit Output: suppressed Parameters: unit: string, required, unit - The type of connection. |
init |
public
any
init
(
string
savePath="",
string
mapPath="",
string
mapFile="",
string
shapePath=""
)
Initiator Output: suppressed Parameters: savePath: string, optional, savePath - The physical path to saved images mapPath: string, optional, mapPath - The physical path to map files mapFile: string, optional, mapFile - The name if the initial map file shapePath: string, optional, shapePath - The base path to any shapefiles |
initConnectionTypes |
package
void
initConnectionTypes
(
)
Initialise the connection types used by mapserver Output: suppressed |
initJavaObjects |
package
initJavaObjects
(
string
file=""
)
Init the java objects as required Output: suppressed Parameters: file: string, optional, file - The name of the map file which may include the whole path |
isRelative |
package
boolean
isRelative
(
str="",
type="os"
)
Return true or false if this path is relative or absolute Output: suppressed Parameters: str: any, optional, str - A full or relative path type: any, optional, type - Is this a operating system or URL path |
setExtents |
public
void
setExtents
(
required
struct
extents
)
Set the new extents for the current map. These extents will be clobbered if a new map is created Output: suppressed Parameters: extents: struct, required, extents - The minX, minY, maxX, maxY extents of the map |
setFileType |
public
void
setFileType
(
string
imageType=""
)
Set or reset the name of the map file Output: suppressed Parameters: imageType: string, optional, imageType - The name of the map file which may include the whole path |
setFontFile |
public
setFontFile
(
string
fontFile=""
)
Set or reset the path and file for fonts Output: suppressed Parameters: fontFile: string, optional, fontFile - The physical path and filename for the fonts file |
setLayerData |
public
boolean
setLayerData
(
layerName="",
layerId="",
shapeFile="",
data="",
connection="",
connType=""
)
Set the name of a data file. Returns true on success or false if fails Output: suppressed Parameters: layerName: any, optional, layerName - The name of the layer if you want a file check performed layerId: any, optional, layerId - The ID of the layer shapeFile: any, optional, shapeFile - The name of the data file. This will perform a file system check data: any, optional, data - The data string. This would be the name of the file or the 'column from table' syntax connection: any, optional, connection - The database connection string. connType: any, optional, connType - The type of connection being used. This is any of the swig interface defined connection types. Defaults to MS_POSTGIS or MS_SHAPEFILE depending on arguments provided. See 'Connection Types' for more information |
setLayerFilter |
public
boolean
setLayerFilter
(
layerName="",
layerId="",
required
filter
)
Set the current filter string for a layer. Output: enabled Parameters: layerName: any, optional, layerName - The name of the layer layerId: any, optional, layerId - The ID of the layer filter: any, required, filter - The filter sitring. |
setLayerListStatus |
public
void
setLayerListStatus
(
string
layerIdList=""
)
Given a list of Ids, turn layers on or off Output: suppressed Parameters: layerIdList: string, optional, layerIdList - The Id list of the layers |
setLayerStatus |
public
boolean
setLayerStatus
(
string
layerName="",
numeric
layerId="-1",
boolean
on="true"
)
Allow a layer to be switched on or off Output: suppressed Parameters: layerName: string, optional, layerName - The name of the layer layerId: numeric, optional, layerId - The Id of the layer on: boolean, optional, on |
setLegendStr |
public
void
setLegendStr
(
required
string
str
)
Set the legend string to be parsed by createLayerLegend Output: suppressed Parameters: str: string, required, str - The new lexical string to be used to create the legend |
setMapFile |
public
setMapFile
(
string
file=""
)
Set or reset the name of the map file Output: suppressed Parameters: file: string, optional, file - The name of the map file which may include the whole path |
setMapPath |
public
setMapPath
(
string
path=""
)
Set or reset the path for map files Output: suppressed Parameters: path: string, optional, path - The physical path to the map files |
setSavePath |
public
setSavePath
(
string
path=""
)
Set or reset the save path for images Output: suppressed Parameters: path: string, optional, path - The physical path to saved images |
setScaleBar |
public
setScaleBar
(
numeric
width="0",
numeric
height="0",
string
status="",
numeric
intervals="5",
string
units="KILOMETERS",
string
position="LC"
)
set some options for the map scale bar Output: suppressed Parameters: width: numeric, optional, width - width of the scale bar height: numeric, optional, height - height of the scale bar status: string, optional, status - status of the scale bar (on/off/embed) intervals: numeric, optional, intervals - number of intervals along the scale bar units: string, optional, units - unit of measurement for the scale bar (miles/kms etc) position: string, optional, position - position of the scale bar on the map |
setShapePath |
public
setShapePath
(
string
path=""
)
Set or reset the path for map files Output: suppressed Parameters: path: string, optional, path - The physical path to the map files |
setURLPath |
public
void
setURLPath
(
string
path=""
)
Set or reset the name of the map file Output: suppressed Parameters: path: string, optional, path - The absolute or relative URL to image location |
throw |
package
throw
(
required
string
errorCode,
required
string
message
)
Output: enabled Parameters: errorCode: string, required, errorCode - A custom error code to throw message: string, required, message - The associated error text |
validPoints |
package
boolean
validPoints
(
struct
extents,
struct
imgExtents,
struct
points,
struct
boundary
)
Check to see if the supplied geometry extents or points are valid Output: suppressed Parameters: extents: struct, optional, extents - The minX, minY, maxX, maxY extents of the map imgExtents: struct, optional, imgExtents - The minX, minY, maxX, maxY extents the image points: struct, optional, points - The img x and y points boundary: struct, optional, boundary - The minX, minY, maxX, maxY extremeties of the displayable map. This value could be significantly larger than the maximum extents and is a way to provide some reasonable boundary checking only. If nothing is supplied then the default of -360 to 360 and -90 to 90 is used. |
versionGreaterOrEqual |
package
boolean
versionGreaterOrEqual
(
required
version
)
Return true if the current mapserver version is greater than or equal to the number to check Output: suppressed Parameters: version: any, required, version - The major and minor version number. Minor minor numbers are ignored |
zoom |
public
zoom
(
struct
newExtents,
struct
newPoints,
required
struct
maxExtents,
required
struct
extremities,
numeric
width="0",
numeric
height="0",
numeric
zoomFactor="2"
)
Set the new extents for the new area providing some sanity checking Output: suppressed Parameters: newExtents: struct, optional, newExtents - The minX, minY, maxX, maxY extents of the map newPoints: struct, optional, newPoints - The img x and y points maxExtents: struct, required, maxExtents - The minX, minY, maxX, maxY extents of the map extremities: struct, required, extremities - The minX, minY, maxX, maxY extremeties of the displayable map. See validPoints for more info. width: numeric, optional, width - The width of the output image. height: numeric, optional, height - The height of the output image. zoomFactor: numeric, optional, zoomFactor |