Mapserver的中文标注问题
搞了一两天了,记下吧,唉
关键是下面的map配置
首先是LabelItem,对应属性的字段
FONT simhei//这个font必须在 FONTSET http://www.cnblogs.com/gmap/etc/fonts.txt列表中存在,并且有字体文件
还要加上个 Encoding gb2312
如果是shp文件,保证dbf文件是utf8编码(我用的是utf8)
如果是postgis数据库,保证数据库是utf8编码,shp文件导入数据库是gb2312编码
在数据库迁移时,用备份回存会发生问题,即使你的数据库是utf8编码
最好是先做成sql文件,重新执行导入数据
LabelItem "Name"
CLASSITEM "CLASS"
CLASS
EXPRESSION "AH"
TEMPLATE "ttt_query.html"
NAME "Cities"
LABEL
COLOR 255 0 0
FONT simhei
TYPE truetype
SIZE 8
POSITION AUTO
PARTIALS FALSE
OUTLINECOLOR 255 255 255
Encoding gb2312
END
完整的mapfile配置文件
# Map file generated by QGIS version 0.8.0
# Edit this file to customize for your interface
# Not all sections are complete. See comments for details.
NAME bj
STATUS ON
FONTSET http://www.cnblogs.com/gmap/etc/fonts.txt
SYMBOLSET http://www.cnblogs.com/gmap/etc/symbols.sym
# Map image size. Change size as desired
SIZE 600 600
SHAPEPATH "../data"
#
# Start of web interface definition. Only the TEMPLATE parameter
# must be specified to display a map. See Mapserver documentation
#
WEB
METADATA
"wms_title" "Demo"
"wms_onlineresource" "http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/ka-map-1.0.b1/data/china.map&"
"wms_srs" "EPSG:4326"
END
# HEADER
# TEMPLATE
# FOOTER
#MINSCALE
#MAXSCALE
# Set IMAGEPATH to the path where mapserver should
# write its output
IMAGEPATH '/tmp/'
# Set IMAGEURL to the url that points to IMAGEPATH
#IMAGEURL '/map_output/'
END
# Extent based on full extent of QGIS view
EXTENT 116.354 39.8709 116.435 39.9285
UNITS dd
IMAGECOLOR 255 255 255
IMAGETYPE gif
# Projection definition
# Projections are not currenlty supported. If desired, add your own
# projection information based on Mapserver documentation.
#
PROJECTION
"init=epsg:4326"
END
LAYER
NAME popplace
GROUP p
METADATA
"wms_title" "Demo"
"wms_onlineresource" "http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/ka-map-1.0.b1/data/china.map&"
"wms_srs" "EPSG:4326"
END
PROJECTION
"init=epsg:4326"
END
TYPE POINT
STATUS ON
CONNECTION "user=postgres password=postgres dbname=postgis host=localhost port=5432"
CONNECTIONTYPE postgis
DATA "the_geom from china_xianch_point"
LabelItem "Name"
CLASSITEM "CLASS"
CLASS
EXPRESSION "AH"
TEMPLATE "ttt_query.html"
NAME "Cities"
LABEL
COLOR 255 0 0
FONT simhei
TYPE truetype
SIZE 8
POSITION AUTO
PARTIALS FALSE
OUTLINECOLOR 255 255 255
Encoding gb2312
END
STYLE
SYMBOL 2
SIZE 8
COLOR 0 0 0
END
END
TOLERANCE 5
END # Layer
END # Map File