簡體   English   中英

OpenLayers矢量圖層在特征標簽上的z排序

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

編輯:我已經在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排序屬性。

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

如果你還沒有,你可以嘗試一些事情:

我注意到你在第一個矢量上啟用了rendererOptions而不是你的第二個矢量。 您也可以嘗試將其添加到第二層。

同時嘗試將"${zIndex}"的引號刪除為${zIndex}因為它可能需要一個整數。

可能的解決方法是將文本容器更改為圖形容器,它將遵循渲染文本的z-index:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM