Monday, December 22, 2014

Re: ExceptionInIntializerError with MapTypeStyleFeatureType and MapTypeStyleElementType

I found one workaround involving writing native JavaScript that bypasses the GoogleMaps GWT API:

    package com.test.client;
   
   
import com.google.gwt.ajaxloader.client.AjaxLoader;
   
import com.google.gwt.ajaxloader.client.AjaxLoader.AjaxLoaderOptions;
   
import com.google.gwt.core.client.EntryPoint;
   
import com.google.gwt.dom.client.Document;
   
import com.google.maps.gwt.client.GoogleMap;
   
import com.google.maps.gwt.client.LatLng;
   
import com.google.maps.gwt.client.MapOptions;
   
import com.google.maps.gwt.client.MapTypeId;
   
   
public class GwtTest implements EntryPoint {
   
   
@Override
   
public void onModuleLoad() {
   
AjaxLoaderOptions options = AjaxLoaderOptions.newInstance();
    options
.setOtherParms("sensor=false");
   
Runnable callback = new Runnable() {
   
public void run() {
    createMap
();
   
}
   
};
   
AjaxLoader.loadApi("maps", "3", callback, options);
   
}
   
   
public void createMap() {
   
   
MapOptions mapOpts = MapOptions.create();
    mapOpts
.setZoom(4);
    mapOpts
.setCenter(LatLng.create(37.09024, -95.712891));
    mapOpts
.setMapTypeId(MapTypeId.TERRAIN);
    mapOpts
.setStreetViewControl(false);
   
   
GoogleMap map = GoogleMap.create(Document.get().getElementById("map_canvas"), mapOpts);
   
    styleMap
(map);
   
}
   
   
   
public native void styleMap(GoogleMap map) /*-{
    map.set('styles', [
     {
       "featureType": "road",
       "stylers": [
         { "visibility": "off" }
       ]
     },{
       "featureType": "poi",
       "stylers": [
         { "visibility": "off" }
       ]
     },{
       "stylers": [
         { "invert_lightness": true }
       ]
     }
    ]);
    }-*/
;
   
}


I'd still be curious to find out if there's a pure Java workaround, but if anybody else has this problem, this native approach works. And it has the added bonus that it works directly with JSON you can export from the GoogleMaps Styling Wizard.

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