我有一个在矢量图层中绘制特征的OpenLayers 地图。这些功能是可选的,并且在选择时会弹出一个弹出窗口。不幸的是,在很多情况下,功能重叠,因此不可能选择某些功能。我认为解决此问题需要做的是更改我的选择控件,以便它使用单击处理程序并此时在地图上搜索功能。我需要编写什么样的函数?以前有没有这样的例子?
这是绘制特征的方式:
var vector_Layer = new OpenLayers.Layer.Vector();
function GetFeaturesFromKMLString (strKML) {
var format = new OpenLayers.Format.KML({
'internalProjection': new OpenLayers.Projection("EPSG:900913"),
'extranalProjection': new OpenLayers.Projection("EPSG:4326")
});
return format.read(strKML);
};
vector_Layer.addFeatures(GetFeaturesFromKMLString('$newkml'));
这就是当前选择图层的方式:
var select = new OpenLayers.Control.SelectFeature(vector_Layer, {clickout: true});
vector_Layer.events.on({
"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect});
map.addControl(select);
select.activate();
select.handlers['feature'].stopDown = false;
select.handlers['feature'].stopUp = false;
这是我计划使用的点击事件监听器:
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': false,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this, {
'click': this.onClick
}, this.handlerOptions
);
},
onClick: function(evt) {
//function that seachers for and selects features at this point
},