我想知道是否有人可以指出我正确的方向来强制 OpenLayers.Control.GetFeature 的 BBOX 始终处于长/纬度坐标中。我正在尝试使用 OpenLayers.Class 来实现这一点,因此新控件将继承 OpenLayers.Control.GetFeature,只需在 BBOX 中进行少量修改。这就是我所做的:
OpenLayers.Control.myGetFeature = OpenLayers.Class(OpenLayers.Control.GetFeature,{
selectBox: function(position){
var opts = OpenLayers.Control.GetFeature(position);
var baseSRSutm = this.map.getprojectionObject();
var layerSRSdd = new OpenLayers.Projection('EPSG:4326');
opts.params.bbox = this.map.getExtent().transform(baseSRSutm,layerSRSdd).toBBOX(null,firstLayer.reverseAxisOrder());
}
return opts;
});
但我知道有些“}”不见了。这是使用 OpenLayers.Class 做我想做的事情的正确方法吗?
任何帮助深表感谢。
PS。我正在使用 OpenLayers 2.11
编辑:
移动“返回选项”;函数内部解决了上述问题,但它抱怨缺少 CLASS_NAME。补充一点,它仍然抱怨同样的问题,但是经过几次点击或框后它发送了请求,但是发送的 bbox 仍然在 UTM 中,问题可能出在哪里?这是代码:
var mycontrol = function(){
var protocol = new OpenLayers.Protocol.HTTP({
url: 'http://www.....',
format: new OpenLayers.Format.GeoJSON({
ignoreExtraDims: true,
'internalProjection': new OpenLayers.Projection('EPSG:900913'),
'externalProjection': new OpenLayers.Projection('EPSG:4326')
})
});
OpenLayers.Control.myGetFeature = OpenLayers.Class(OpenLayers.Control.GetFeature,{
selectBox: function(position){
var opts = OpenLayers.Control.GetFeature(position);
var baseSRSutm = this.map.getprojectionObject();
console.log('this is the baseSRSutm' + baseSRSutm); // doesnt appear in firebug
var layerSRSdd = new OpenLayers.Projection('EPSG:4326');
opts.params.bbox = this.map.getExtent().transform(baseSRSutm,layerSRSdd).toBBOX(null,firstLayer.reverseAxisOrder());
console.log('this is the opts.params.bbox' + opts.params.bbox); // doesnt appear in firebug
return opts;
},
CLASS_NAME: "OpenLayers.Control.myGetFeature"
});
return new OpenLayers.Control.myGetFeature({
protocol: protocol,
box: true,
click: true,
single: false,
clickTolerance: 10,
eventListeners:{
// some stuff
}
});
};
因为console.log没有出现在firebug中,我认为问题出在OpenLayers.Control.myGetFeature和OpenLayers.Class中。在我看来,“selectBox”函数是我需要的,但子类本身并没有被返回读取。
请帮助解决这个问题,在此先感谢,