I use GWT and GWT API GoogleMaps ( v3.8.0 ). Everything is fine and works fine for me.
However, I would like to disable some of the default features that come with GoogleMaps, such as street names, the ability to click restaurants, etc. Basically, I would like it to actually be a map layer, which I add my own custom layers.
I thought I could do this using styles. I am trying to use MapTypeStyler with visibility using MapTypeStyle of any type that I wanted to disable (in this case, MapTypeStyle.ROAD).
Here is the test code I'm trying to run:
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.core.client.JsArray; 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; import com.google.maps.gwt.client.MapTypeStyle; import com.google.maps.gwt.client.MapTypeStyleElementType; import com.google.maps.gwt.client.MapTypeStyleFeatureType; import com.google.maps.gwt.client.MapTypeStyler; 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() { JsArray<MapTypeStyle> styles = (JsArray<MapTypeStyle>) JsArray.<MapTypeStyle>createArray(); JsArray<MapTypeStyler> roadStylers = (JsArray<MapTypeStyler>) JsArray.<MapTypeStyler>createArray(); MapTypeStyler roadStyler = MapTypeStyler.visibility("off"); roadStylers.push(roadStyler); MapTypeStyle roadStyle = MapTypeStyle.create(); roadStyle.setStylers(roadStylers); roadStyle.setFeatureType(MapTypeStyleFeatureType.ROAD);
However, when I run this, I get an exception:
14:49:52.756 [ERROR] [gwttest] Uncaught exception escaped java.lang.ExceptionInInitializerError: null at com.test.client.GwtTest.createMap(GwtTest.java:43) at com.test.client.GwtTest$1.run(GwtTest.java:25) at com.google.gwt.ajaxloader.client.ExceptionHelper.runProtected(ExceptionHelper.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NullPointerException: null at com.google.maps.gwt.client.MapTypeStyleFeatureType$.register(MapTypeStyleFeatureType.java:227) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338) at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) at com.google.maps.gwt.client.MapTypeStyleFeatureType$.create(MapTypeStyleFeatureType.java) at com.google.maps.gwt.client.MapTypeStyleFeatureType$.<clinit>(MapTypeStyleFeatureType.java:39) at com.test.client.GwtTest.createMap(GwtTest.java:43) at com.test.client.GwtTest$1.run(GwtTest.java:25) at com.google.gwt.ajaxloader.client.ExceptionHelper.runProtected(ExceptionHelper.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364) at java.lang.Thread.run(Thread.java:745)
It is strange that the exception seems to be internal to GoogleMaps, so I really don't know what is going on?
Am I doing something obviously dumb with styles?
Edit: I also asked this question on the GWT forum.
java javascript google-maps gwt
Kevin workman
source share