【问题标题】:Openlayers - Draw String on MapOpenlayers - 在地图上绘制字符串
【发布时间】:2013-07-13 06:31:50
【问题描述】:

我试图在 Openlayers 中的图层上绘制字符串/字符(例如,显示路线 --> 在路线附近绘制描述或楼层号)。 问题:可以将标签添加到 Openlayers.Vector,但我的应用程序有一个包含多个几何图形的向量,每个应该使用不同的字符串呈现。 也许存在一些像这样的几何:layer.addFeature(new Openlayers.StringGeometry("text", x,y) 左右。我找不到任何东西。

谁能给我一个提示?

【问题讨论】:

    标签: javascript map openlayers gis openstreetmap


    【解决方案1】:

    要为向量层的特征添加自定义文本标签,我建议如下:

    1) 将StyleMap 添加到您的矢量图层中:

    var vectorLayer = new OpenLayers.Layer.Vector("Vector", 
    {
        styleMap: new OpenLayers.StyleMap(            
        {
            label : "${labelText}",                    
            fontColor: "blue",
            fontSize: "12px",
            fontFamily: "Courier New, monospace",
            fontWeight: "bold",
            labelAlign: "lc",
            labelXOffset: "14",
            labelYOffset: "0",
            labelOutlineColor: "white",
            labelOutlineWidth: 3
        })
    });
    

    请注意,此样式图中的labelText 表示此标签的文本将取自相应的特征属性。

    2) 对于您添加到图层的每个功能,请指定定义了labelText 的属性:

    var features = [];
    var pt = new OpenLayers.Geometry.Point(0, 0);
    features.push(new OpenLayers.Feature.Vector(pt, {labelText: "This is my label"}));
    vectorLayer.addFeatures(features);
    

    此解决方案的唯一限制是您必须为每个点添加功能并且无法使用OpenLayers.Geometry.MultiPoint

    【讨论】:

    • 不客气。如果这解决了您的问题,请考虑将其标记为答案:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    相关资源
    最近更新 更多