0

我想知道是否有人可以指出我正确的方向来强制 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”函数是我需要的,但子类本身并没有被返回读取。

请帮助解决这个问题,在此先感谢,

4

2 回答 2

0

您的代码示例有一些语法错误。将来尝试使用一些 javascript 代码 linter,如jsHint来帮助调试这些错误。这是您的代码,已修复:

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;
    }
});

关于您关于自定义 GetFeature 的问题,我认为您走在正确的轨道上。这与我采取的方法相同。OpenLayers 在他们的示例中推荐了一种稍微不同的方法,但它执行相同的功能:

var control = new OpenLayers.Control.GetFeature();
OpenLayers.Util.extend(control, {
    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;
    }
});
于 2013-01-30T18:01:43.363 回答
0

终于成功了,诀窍是使用原型和 selectBox,然后应用基础地图投影和 displayProjection 之间的转换,在这种情况下,在 900913 和 4326 之间。我在这里得到了这个想法:http://osgeo-org.1560 .n6.nabble.com/Order-Priority-of-Control-GetFeature-and-Control-WMSGetFeatureInfo-on-click-td4997282.html

于 2013-01-31T23:51:19.877 回答