MapServer LAYER Object
The LAYER object is where we define what data to show (Tab, SHAPE, Raster, Oracle Spatial, ArcSDE, ODBC database, PostGIS, Text files etc). We also define what TYPE of data (Line, Polygon, Point or Text (annotation)), Zoom levels, visibility, filtering of information etc.
For full details of the MapServer LAYER Object please see the MapServer MAP Documentation.
LAYER NAME "crime_statistics" STATUS OFF TYPE POLYGON INCLUDE "datashare.inc" DATA "wkb_geometry from (select * from crime.vw_crime_statistics) as foo using unique ogc_fid using srid=27700" TOLERANCEUNITS METERS CLASS NAME "" STYLE OUTLINECOLOR 255 0 128 WIDTH 2 END END END
Element | Description | Example |
---|---|---|
NAME | This is the name for a layer that the Map Source will reference. The LAYER NAME must start with a letter, underscore or hyphen and then can contain letters, numbers, underscores, full stops and hyphens (no spaces). Full stops are allowed as some customers use the convention schema.table for the Layer name. Total length must not exceed 32 characters. | HighestRepeatCrimes Sea TopoArea |
TYPE | This is the type of layer. Please refer to the CONNECTION item below as this describes the connections to different types / formats | POINT POLYGON LINE ANNOTATION RASTER QUERY |
INCLUDE | This is a link to a file that has the elements that you would otherwise need to add for every LAYER in your .MAP file such as CONNECTIONTYPE, CONNECTION, and PROCESSING. Instead all you need to do is to add these to a file and then add the file name in this INCLUDE element. This file must reside in the _MapServerConfig folder for your installation e.g. D:\iShareData\CustomeName\_MapServerConfig | INCLUDE "datashare.inc" |
CONNECTION / DATA | This is how the location source data is defined. MapServer can draw natively over 120 formats so the options can be varied. Two examples here are for DATA (ESRI Shape) and CONNECTIONTYPE OGR (MapInfo TAB) At present Studio does not handle the encrypting of credentials. Typically you might want to encrypt portions of the CONNECTION parameter for a database connection. The following CONNECTIONTYPEs are supported for using this encryption method: OGR, Oracle Spatial, PostGIS, SDE. Please refer to the current MapServer documentation to enable this http://mapserver.org/utilities/msencrypt.html. PostgreSQL supports schema and table names wrapped with double quotes. If your schema and table names use double quotes they will have to be escaped in the .map file such as DATA "wkb_geometry from (select * from \"schema\".\"table\") as foo using unique ogc_fid using srid=27700" | SHAPE FILES DATA “UKCounties.shp” MapInfo TAB CONNECTIONTYPE OGR CONNECTION “UKCounties.tab” PostGIS CONNECTIONTYPE POSTGIS |
TOLERANCEUNITS | This must be METERS for any Polygon layer used in My House otherwise it will cause issues with My House returning extra results. If this is not specified then PIXELS is the default. | METERS |
STATUS | Whether a layer is shown or not. The two main ones to look at here are OFF and DEFAULT. DEFAULT means it will always be drawn. OFF means that iShare will control the visibility – although Zoom layering still applies. | OFF ON DEFAULT |
REQUIRES | Use this to only display the layer provided that another layer is NOT being displayed. This is useful for switching between Aerial Photography and either OS MasterMap or Raster layers. The ! denotes NOT. Note: If you use this element the STATUS element must be DEFAULT REQUIRES is also commonly used to display a layer when another layer is shown. For instance you may have a TPO table which contains points and polygons and you wish to display both the points and polygons when a single TPO layer is enabled in iShare. To achieve this you define two layers in the mapfile, one for the polygons and another for the points, and make the point layer dependant on the polygon layer using REQUIRES "[tpo_polygons]" and STATUS DEFAULT on the point layer. Commonly the polygon layer would also include a buffer for each point to allow users to get info on the points as well as the polygons. | "![Aerial]" |
MAXSCALE | Zoom Layering. The maximum scale that the layer will be drawn. This is a scale setting | 35000 |
MAXSCALEDENOM | Maximum scale at which this LAYER is drawn. Scale is given as the denominator of the actual scale fraction, for example for a map at a scale of 1:24,000 use 24000. Implemented in MapServer 5.0, to replace the deprecated MAXSCALE parameter. | 35000 |
MINSCALE | Zoom Layering. The minimum scale that the layer will be drawn. This is a scale setting | 10000 |
MINSCALEDENOM | Minimum scale at which this LAYER is drawn. Scale is given as the denominator of the actual scale fraction, for example for a map at a scale of 1:24,000 use 24000. Implemented in MapServer 5.0, to replace the deprecated MINSCALE parameter. | 10000 |
TRANSPARENCY | ALPHA (so that we use antialiasing which can make the features look nicer) or number so layer appears opaque – very good when using with overlays (i.e. planning applications) in conjunction with Mastermap. | ALPHA
50 – partially transparent |
LABELITEM | Field that will be used as a label item. Requires a LAYER -> CLASS -> LABEL | Total Crimes APP_REF |
FILTERITEM | MapServer allows you to filter the records that are displayed based on attribute values. There are multiple ways of doing this whether single values or expressions: Single values: FILTERITEM + FILTER Expressions: FILTER (fields in []) | FILTERITEM "GROUP" FILTER "Burglary"
FILTER ([Total] > 10) |
CLASSITEM | Allows for Classes (sets of information) to be classified by a field. This is useful where you want to create thematics. This is then use in conjunction with the EXPRESSION item within a CLASS. | CLASSITEM “TotalCrimes” |
CLASS | Allows classifications against datasets. Every Layer object MUST have a CLASS object. | CLASS |
METADATA | This is used for web mapping (WMS, OWS etc.), proxy information. and searching in iShare. | METADATA
END |
VALIDATION | From MapServer V6.0 onwards - A VALIDATION block is used in place of the validation_pattern in a METADATA block for searching in iShare. | VALIDATION
END |
Mixed scale levels being shown in Base Maps
You may sometimes see images from one scale being shown in what should be a zoom level that solely uses another. This has so far only happened when using Tilecache-based Base Maps. To resolve this either set the zoom level to a different scale or alter the scale boundary slightly.
100000,20000,5000
LAYER ... MINSCALEDENOM 20001 ... END LAYER ... MAXSCALEDENOM 20001 ... END