【问题标题】:Mapserver: trying to make a map with an annotation/labelMapserver:尝试制作带有注释/标签的地图
【发布时间】:2023-03-04 03:20:01
【问题描述】:

我正在尝试使用 MapServer 制作一张图像,它只显示一个带有标签的图层。我写了以下地图文件:

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

我正在使用 PHP 和 ms_newMapObjFromString() 生成图像。但是,我得到的只是一张没有任何文字的透明图像。我错过了什么?

编辑: PHP代码:

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 是上面贴出的字符串。

【问题讨论】:

    标签: php mapserver


    【解决方案1】:

    您的地图范围与您使用的投影不匹配。您可能指的是投影 EPSG:4326,因为 -180 -90 180 90 是此投影的最大扩展。

    另一个问题是您的点 (POINTS 100 100) 超出了您请求的边界框 (EXTENT -180 -90 180 90) 尝试将点放在图像的中心

    POINTS 0 0
    

    PS:如果它不起作用,请同时发布您的 php 代码

    【讨论】:

    • 很遗憾,您的解决方案不起作用。我添加了我的 PHP 代码。
    【解决方案2】:

    执行此操作的一种方法(可能还有其他方法)是在您的 LAYER 配置中,您需要添加一个 LABELITEM 来标识数据中的属性以获取标签文本。

    所以比如下面的例子,原油标签就是输入数据的Gen_Type属性中的数据,而“原油”值的类包含了LABEL指令。

    所以在地图文件中我们有:

    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
    

    在“样式”文件中我们有:

        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
    

    【讨论】:

      猜你喜欢
      • 2021-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-12
      • 2011-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多