Search code examples
gwtgoogle-maps-api-3jsni

Referring to Javascript Constants within GWT code


Is there a way using JSNI and JSOT (javascript overlay types) to map a JavaScript constants to a custom java-type?

Example:

I map the Google Map V3 javascript API to GWT and there is the MapTypeId constants. I'd like to refer in my javacode to the TERRAIN constant (which is a javascript string) as a MapTypeId object (which is a POJO and not a java.lang.String). So far, the compiler says it could not map the javascript string to my custom type.


Solution

  • The only I made it work is to wrap the string constants in a pure javascript object and map it as a dumb overlay-types. The GWT java-to-js compiler then is able to cast that as my strongly-typed MapTypeId.

    public static native MapTypeId getHybrid() /*-{
            return { value : $wnd.google.maps.MapTypeId.HYBRID };
        }-*/;