简体   繁体   English

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

[英]OpenLayers Vector Layer z-ordering on feature labels

EDIT: I have filed a bug ticket for this on GitHub: https://github.com/openlayers/ol2/issues/1167 编辑:我已经在GitHub上提交了一张错误票: https//github.com/openlayers/ol2/issues/1167

I'm working on a project with OpenLayers and have found the experience quite painful due to the lack of good documentation. 我正在与OpenLayers合作开展一个项目,并且由于缺乏良好的文档而发现这种体验非常痛苦。 I've followed the example here http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/ordering.html to create icons on the map with z-ordering. 我按照这里的示例http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/ordering.html使用z-ordering在地图上创建图标。 However, I am also using a variation of the technique here http://openlayers.org/dev/examples/vector-features-with-text.html to create labels for the vectors. 但是,我也在http://openlayers.org/dev/examples/vector-features-with-text.html使用该技术的变体来为矢量创建标签。 Unfortunaely, it seems like OpenLayers does not respect z-ordering properties when it draws labels. 遗憾的是,OpenLayers在绘制标签时似乎不尊重z排序属性。

OpenLayers不正确的z排序

Notice how the green icon is on top of the grey icon (correct), but the green label is below the grey label (incorrect.) Is there a workaround for this? 注意绿色图标如何位于灰色图标的顶部(正确),但绿色标签位于灰色标签下方(不正确。)是否有解决方法?

Here's my code for the layer: 这是我的图层代码:

    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}
    });

Here's my code for the icons: 这是我的图标代码:

    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]);

A few things you can try if you haven't already: 如果你还没有,你可以尝试一些事情:

I noticed you enabled rendererOptions on your first vector but not your second. 我注意到你在第一个矢量上启用了rendererOptions而不是你的第二个矢量。 You could try adding that to your second layer too. 您也可以尝试将其添加到第二层。

Also try removing the quotes from "${zIndex}" to simply ${zIndex} since it probably expects an integer. 同时尝试将"${zIndex}"的引号删除为${zIndex}因为它可能需要一个整数。

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

layer.renderer.textRoot = layer.renderer.vectorRoot;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM