OpenLayers矢量图层在特征标签上的z排序

问题描述 投票:3回答:2

编辑:我已经在GitHub上提交了一张错误票:https://github.com/openlayers/ol2/issues/1167

我正在与OpenLayers合作开展一个项目,并且由于缺乏良好的文档而发现这种体验非常痛苦。我在这里按照http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/ordering.html的例子在地图上用z-ordering创建图标。但是,我也在这里使用http://openlayers.org/dev/examples/vector-features-with-text.html技术的变体来为矢量创建标签。遗憾的是,OpenLayers在绘制标签时似乎不尊重z排序属性。

注意绿色图标如何位于灰色图标的顶部(正确),但绿色标签位于灰色标签下方(不正确。)是否有解决方法?

这是我的图层代码:

    this.vehicleLayer = new OpenLayers.Layer.Vector("vehicles", {
        // The zIndex is taken from the zIndex attribute of the features
        styleMap: new OpenLayers.StyleMap({ 'default': {
            graphicZIndex: "${zIndex}"
        }}),
        // enable the indexer by setting zIndexing to true
        rendererOptions: {zIndexing: true}
    });

这是我的图标代码:

    iconPrefix = mapView.iconProvider.prefixMapping(vehicle.get('icon'));
    imgUrl = mapView.iconProvider.getIconURL(iconPrefix, trackingStatus, position.get('track'));

    //Vehicle icon
    this.marker = new OpenLayers.Feature.Vector(point, null, {
        'graphicZIndex': this.zIndexState[trackingStatus],
        'externalGraphic': imgUrl,
        'pointRadius': 8,
        'cursor': 'pointer',
        'clickable': true,
        'title': label_text
    });

    this.marker.attributes = {
        'vehicleMapView': this
    };

    //tail label
    if (App.Settings.get('labels')) {
        this.marker.style = _.extend(this.marker.style, {
            pointerEvents: "visiblePainted",
            label: label_text,
            fontColor: trackingStatus !== 'inactive' ? "#222222" : "white",
            fontSize: "12px",
            fontFamily: "Courier New, monospace",
            fontWeight: "bold",
            labelAlign: "lm",
            labelXOffset:12,
            labelOutlineColor: this.statusToColor[trackingStatus],
            labelOutlineWidth: 2.5
        });
        this.marker.attributes = _.extend(this.marker.attributes, {label: label_text});

    }
    layer.addFeatures([this.marker]);
javascript gis openlayers
2个回答
0
投票

如果你还没有,你可以尝试一些事情:

我注意到你在你的第一个矢量上启用了rendererOptions而不是你的第二个矢量。您也可以尝试将其添加到第二层。

同时尝试将引号从"${zIndex}"删除到简单的${zIndex},因为它可能需要一个整数。


0
投票

可能的解决方法是将文本容器更改为图形容器,它将遵循渲染文本的z-index:

layer.renderer.textRoot = layer.renderer.vectorRoot;
© www.soinside.com 2019 - 2024. All rights reserved.