Nik*_*lff 12 javascript openlayers
我有一个OpenLayers地图,它有一个光栅基础层,一个矢量图层和一个标记图层.它们以正确的顺序显示,矢量顶部的标记非常好.
但是当我添加一个SelectFeature控件并将其指向矢量图层时,它会突然在标记图层上方绘制,尽管所有努力都会提升标记图层或设置Z索引.似乎SelectFeature控件会覆盖所有绘图顺序设置.这是设计,还是我能以某种方式克服这个问题?
图层定义:
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
}
);
Run Code Online (Sandbox Code Playgroud)
控件定义:
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
}
);
Run Code Online (Sandbox Code Playgroud)
激活:(没有这个,图层按正确的顺序绘制)
map.addControl(selectctrl);
selectctrl.activate();
Run Code Online (Sandbox Code Playgroud)
编辑:在OpenLayers.Handler.Feature中找到这个,其中"moveLayerToTop"感觉就像罪魁祸首......会尝试克服它,但如果有人知道这是不可能的,请告诉我!
/**
* 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;
},
Run Code Online (Sandbox Code Playgroud)
答案 - 如果可以调用它,那就在我上面提到的激活功能中.我试图覆盖它并删除了对moveLayerToTop的调用,它就像一个魅力.
编辑:我最终将此代码添加到OL代码库外的js文件中,覆盖处理程序激活功能.这是因为否则我将失去对OpenLayers代码库更新的更改.
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;
};
Run Code Online (Sandbox Code Playgroud)