0

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. 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. 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?

Any help is much appreciated.

PS. I'm using OpenLayers 2.11

EDIT:

Moving "return opts;" inside the function solved the above problem but it complained about CLASS_NAME is missing. 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? 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. It seems to me that the "selectBox" function is the one I need, but the subclass itself is not read by the return.

2 Answers 2

2

IMHO, the first approach is better. But there are some errors in your code.

  1. OpenLayers.Control.GetFeature is a class, but not a function that you can call directly. If you want to call the same function in parent class (i.e. OpenLayers.Control.GetFeature), the right way is:

    var opts = OpenLayers.Control.GetFeature.prototype.selectBox.apply(this, arguments);

  2. return opts is out the scope of selectBox function

  3. you need to specify the CLASS_NAME of your control at the end of the control:

    CLASS_NAME: 'OpenLayers.Control.myGetFeature'

Possibly there might be other errors. I would suggest you to read some OpenLayers API and also the source code, that might be of help.

0
1

finally it worked, thanks a lot for your suggestion Mingfeng, the trick is to use the prototype and selectBox and then apply the conversion between the base map projection and the displayProjection, in this case between 900913 and 4326. I got the idea here: http://osgeo-org.1560.n6.nabble.com/Order-Priority-of-Control-GetFeature-and-Control-WMSGetFeatureInfo-on-click-td4997282.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.