简体   繁体   English

具有OpenLayers.Control.GetFeature的OpenLayers.Class

[英]OpenLayers.Class with OpenLayers.Control.GetFeature

I'm wondering if someone could point me in the right direction to force the BBOX of OpenLayers.Control.GetFeature to be always in long/lat coordinates. 我想知道是否有人可以指向我正确的方向,以迫使OpenLayers.Control.GetFeature的BBOX始终位于长/纬度坐标中。 I'm trying to get this with OpenLayers.Class, so the new control will inherit OpenLayers.Control.GetFeature with just the small modification in BBOX. 我正在尝试通过OpenLayers.Class来实现这一点,因此新控件将仅在BBOX中进行少量修改即可继承OpenLayers.Control.GetFeature。 This is what I've done: 这是我所做的:

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

but I'm getting that some "}" are missing. 但我发现缺少一些“}”。 Is this the right way to use OpenLayers.Class to do what I want? 这是使用OpenLayers.Class做我想要的正确方法吗?

Any help is much appreciated. 任何帮助深表感谢。

PS. PS。 I'm using OpenLayers 2.11 我正在使用OpenLayers 2.11

EDIT: 编辑:

Moving "return opts;" 移动“返回选择”; inside the function solved the above problem but it complained about CLASS_NAME is missing. 函数内部解决了上述问题,但它抱怨缺少CLASS_NAME。 Adding that, it still complained about the same, but after a couple of clicks or boxes it sent the request, however the sent bbox is still in UTM, where could the problem be? 除此之外,它仍然抱怨相同,但是在单击或单击几次后,它发送了请求,但是发送的bbox仍在UTM中,问题可能出在哪里? here it is the code: 这是代码:

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

because the console.log doesn't appear in firebug, I think the problem is in the OpenLayers.Control.myGetFeature and OpenLayers.Class. 因为console.log没有出现在萤火虫中,所以我认为问题出在OpenLayers.Control.myGetFeature和OpenLayers.Class中。 It seems to me that the "selectBox" function is the one I need, but the subclass itself is not read by the return. 在我看来,“ selectBox”功能是我需要的功能,但是子类本身不会被返回读取。

Please help on this one, thanks in advance, 请对此提供帮助,在此先感谢,

Your code sample has some syntax errors. 您的代码示例有一些语法错误。 Try using some javascript code linters like jsHint in the future to help debug these errors. 将来尝试使用诸如jsHint之类的JavaScript代码来帮助调试这些错误。 Here's your code, fixed: 这是您的固定代码:

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

With regards to your question about a custom GetFeature, I think you're on the right track. 关于您关于自定义GetFeature的问题,我认为您的方向正确。 This is the same approach I'd take. 这与我采用的方法相同。 OpenLayers recommends a slightly different approach in their examples , but it performs the same function: 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;
    }
});

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM