Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

Please help on this one, thanks in advance,

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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

share|improve this answer
add comment

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.

share|improve this answer
    
thanks for the answer, I'll try your suggestions and post if it worked. –  Gery Jan 31 '13 at 22:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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