I'm trying to make an image with MapServer which only displays one layer with a label. I have written the following mapfile:
MAP
NAME "TextLayer"
IMAGETYPE PNG
EXTENT -180 -90 180 90
IMAGECOLOR 0 0 255
PROJECTION
"init=epsg:4269"
END
WEB
METADATA
"ows_title" "WMS service"
"ows_onlineresource" "XXX.XXX.XXX.XXX"
"ows_enable_request" "*"
"ows_crs" "EPSG:4269"
END
END
LAYER
NAME "labellayer"
STATUS ON
TYPE POINT
FEATURE
POINTS 100 100 END
TEXT "The text on the image"
END
CLASS
LABEL
SIZE 8
ANTIALIAS true
COLOR 255 0 0
POSITION cc
END
END
END
END
I am generating the image with PHP with ms_newMapObjFromString(). However, all I get is a transparent image without any text. What am I missing?
EDIT: PHP Code:
public function PrintImage($request, $mapFileString)
{
$mapServer_MapObject = ms_newMapObjFromString($mapFileString);
ms_ioinstallstdouttobuffer();
$mapServer_MapObject->owsdispatch($request);
$contenttype = ms_iostripstdoutbuffercontenttype();
ms_iostripStdoutBufferContentType();
//If content type is 'image/png' the image is succesfully requested -> show the image
if($contenttype == "image/png")
{
header('Content-type: image/png');
echo ms_iogetstdoutbufferbytes();
}
//Else an error occured -> show the error
else
{
header('Content-type: xml');
echo ms_iogetstdoutbufferstring();
}
}
$MapFileString is the string posted above.
Your map extent does not match the projection you are using. You probably mean the projection EPSG:4326, because -180 -90 180 90 is the maximal extension of this projection.
Another problem is that your point (POINTS 100 100) is outside the bounding box you request (EXTENT -180 -90 180 90) Try putting the point on the center of the image with
POINTS 0 0
PS: if it does not work, post your php code as well
One way of doing this (there may be others) is in your LAYER
config you need to add a LABELITEM
to identify the attribute in your data to take the label text.
So for example in the below example, the Crude Oil label is the data in the Gen_Type attribute of the input data, and the class for the "Crude Oil" value includes LABEL instructions.
So in the map file we have:
LAYER
CLASSITEM "Gen_Type"
DATA "geom FROM public.energy_gen2016"
EXTENT 29.62017 -1.31861 34.88271 3.69740
GROUP "ENERGY-GEN"
INCLUDE "generic-layer-config.map"
LABELITEM "Gen_Type"
METADATA
"GML_FEATUREID" "fid"
"OWS_ABSTRACT" "Energy generation sites (2016) classified by energy type. The data was downloaded from Data.Ug, and is acquired from the Ministry of Mining and Mineral Development."
"OWS_DATAURL_HREF" "http://catalog.data.ug/dataset/generation-sites"
"OWS_EXTENT" "29.62017 -1.31861 34.88271 3.69740"
"OWS_KEYWORDLIST" "continent@Africa,subcontinent@Eastern Africa,geographicarea@Uganda,serviceprovider@British Geological Survey,DS_TOPIC@utilitiesCommunications,thematic@Energy,DS_DATE@2016"
"OWS_TITLE" "Energy generation type (2016)"
INCLUDE "commonLayerMD.map"
END
NAME "ENERGY_TYPE_2016"
TEMPLATE "tmpl/UPP_energy_tpl.html"
TYPE POINT
INCLUDE "style/entype.map"
END
and in the 'style' file we have:
CLASS
NAME "Crude Oil"
EXPRESSION {Crude Oil}
STYLE
SYMBOL "circlef"
COLOR "#000000"
OUTLINECOLOR "#232323"
SIZE 6
END
LABEL
FONT scb
TYPE TRUETYPE
SIZE 8
COLOR 0 0 0
ALIGN CENTER
PRIORITY 10
BUFFER 1
PARTIALS TRUE
POSITION lc
END
END