强制OpenLayers Markers图层在顶部绘制,并在下面有可选择的图层 [英] Forcing an OpenLayers Markers layer to draw on top, and having selectable layers beneath
问题描述
我有一个OpenLayers地图,其中包含光栅基础层,矢量图层和标记图层。它们以正确的顺序显示,矢量顶部的标记很好。
I have an OpenLayers map with a raster base layer, a vector layer and a markers layer in that order. They display fine, in the correct order with the markers on top of the vectors, great.
但是当我添加一个SelectFeature控件并将其指向矢量图层时,它尽管已经努力提高标记层或设置Z指数,但突然在标记层上方绘制。似乎SelectFeature控件会覆盖所有绘图顺序设置。这是设计,还是我能以某种方式克服这个?
But when I add a SelectFeature Control and point it to the vector layer, it is suddenly drawn above the markers layer, despite all efforts to raise the marker layer or setting the Z index. It seems that the SelectFeature control overrides all drawing order settings. Is this by design, or can I overcome this somehow?
图层定义:
var baselayer = new OpenLayers.Layer.WMS('Norden',
'http://{myarcgisserver}/ArcGIS/services/mylayer/MapServer/WMSServer', {
layers :'1,2',
transparent :false,
width :'auto',
height :'auto',
filter :null
}, {
isBaseLayer: true,
singleTile :true,
ratio :1,
alpha :false,
transitionEffect :'resize'
});
var vectorLayer = new OpenLayers.Layer.Vector("Work orders", {
projection: new OpenLayers.Projection("EPSG:2400"),
strategies: [new OpenLayers.Strategy.Fixed(), refresh],
protocol: new OpenLayers.Protocol.HTTP({
url: "/WorkOrder/WorkOrders.ashx?output=geojson",
format: new OpenLayers.Format.GeoJSON()
})
});
var markerlayer = new OpenLayers.Layer.Markers("Markers", {
projection: new OpenLayers.Projection("EPSG:2400"),
displayInLayerSwitcher: false
}
);
控制定义:
var selectctrl = new OpenLayers.Control.SelectFeature(
vectorLayer,
{
clickout: true,
toggle: false,
multiple: false,
hover: false,
toggleKey: "ctrlKey", // ctrl key removes from selection
multipleKey: "shiftKey", // shift key adds to selection
box: false
}
);
激活:(如果没有这个,图层绘制的顺序正确)
Activation: (Without this, the layers draw in correct order)
map.addControl(selectctrl);
selectctrl.activate();
编辑:
在OpenLayers.Handler.Feature中找到这个,其中moveLayerToTop感觉像罪魁祸首......会试图克服它,但如果有人知道这是不可能的,请告诉我!
Found this in OpenLayers.Handler.Feature, where the "moveLayerToTop" feels like the culprit... Will try to overcome it, but if someone knows it to be impossible, please let me know!
/**
* Method: activate
* Turn on the handler. Returns false if the handler was already active.
*
* Returns:
* {Boolean}
*/
activate: function() {
var activated = false;
if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
this.moveLayerToTop();
this.map.events.on({
"removelayer": this.handleMapEvents,
"changelayer": this.handleMapEvents,
scope: this
});
activated = true;
}
return activated;
},
推荐答案
答案 - 如果是好吧把它叫做我上面提到的激活功能。我试图覆盖它并删除了对moveLayerToTop的调用,它就像一个魅力。
The answer - if it's ok to call it that lies in the activate function that I mention above. I tried to override that and removed the call to moveLayerToTop, and it works like a charm.
编辑:
我最终将此代码添加到OL代码库外的js文件中,覆盖处理程序激活功能。这是因为否则我将失去对OpenLayers代码库更新的更改。
EDIT: I ended up adding this code to a js file outside the OL code library, overriding the handlers activate function. This is because I would otherwise lose the change on an update of the OpenLayers code base.
OpenLayers.Handler.Feature.prototype.activate = function() {
var activated = false;
if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
//this.moveLayerToTop();
this.map.events.on({
"removelayer": this.handleMapEvents,
"changelayer": this.handleMapEvents,
scope: this
});
activated = true;
}
return activated;
};
这篇关于强制OpenLayers Markers图层在顶部绘制,并在下面有可选择的图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!