编辑: 我已经在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-ordering属性。
请注意,绿色图标在灰色图标上方(正确),但绿色标签在灰色标签下方(不正确)。是否有解决此问题的方法?
以下是图层的代码:
这是关于图标的代码:
请注意,绿色图标在灰色图标上方(正确),但绿色标签在灰色标签下方(不正确)。是否有解决此问题的方法?
以下是图层的代码:
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]);