Wednesday, August 27, 2014

GWT, OpenLayers mControl triggers

Hello

I'm working with GWT and OpenLayer, and need to activate clicks on a map.

For this I created a mControl.js with the following code:

OpenLayers.Control.mControl = OpenLayers.Class(OpenLayers.Control, {
    defaultHandlerOptions: { },
    initialize: function(options) {
        this.handlerOptions = OpenLayers.Util.extend(this.defaultHandlerOptions, options);
        OpenLayers.Control.prototype.initialize.apply(this, arguments);
        if (options.handlerType=='Polygon')
        this.handler = new OpenLayers.Handler.Polygon(this, {'done': this.trigger}, this.handlerOptions);
        else if (options.handlerType=='Click')
        this.handler = new OpenLayers.Handler.Click(this, {'click': this.trigger }, this.handlerOptions);
        else if (options.handlerType=='Box')
        this.handler = new OpenLayers.Handler.Box(this, {'done': this.trigger }, this.handlerOptions);
    },
    trigger: function(e) {
    var res = null;
if (this.handlerType=='Polygon')
res = e;
        else if (this.handlerType=='Click')
        res = this.map.getLonLatFromViewPortPx(e.xy);
        else if (this.handlerType=='Box'){
        if(e.left && e.right && e.bottom && e.top){
var ll = this.map.getLonLatFromPixel(new OpenLayers.Pixel(e.left, e.bottom)); 
var ur = this.map.getLonLatFromPixel(new OpenLayers.Pixel(e.right, e.top));
res = new OpenLayers.Bounds(ll.lon,ll.lat,ur.lon,ur.lat);
            }
        }
res.transform(new OpenLayers.Projection(this.map.getProjection()), this.map.displayProjection);
    if (this.onTrigger) this.onTrigger(res);
    }
});

In mControlImpl.java class have the following methods:

public class mControlImpl {
public static native JSObject create(JSObject paramJSObject) /*-{ 
return new $wnd.OpenLayers.Control.mControl(paramJSObject);
}-*/;

public static native void setOnTrigger(JSObject paramJSObject, mControl control) /*-{ 
  $wnd.OpenLayers.Control.mControl(paramJSObject, control);
}-*/;

My problem is that the setOnTrigger method, gives error: TypeError: this.CLASSNAME is undefined OpenLayers.js: 157


Can somebody help me?


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment