Question

Im trying to create a website with a map using GAE and the GWT openlayers library. Im trying to implement it by using a MapWidget in the SiteNameWidget.ui.xml file, but i get the error below.

I've managed to get it working by using the RootPanel.get().add(MapWidget) approach, but i would like to be able to use the XML file approach, as is seems to be easier to manipulate the layout this way.

Anyone?

org.gwtopenmaps.openlayers.client.MapWidget has no default (zero args) constructor. To fix this, you can define a @UiFactory method on the UiBinder's owner, or annotate a constructor of MapWidget with @UiConstructor.

Was it helpful?

Solution

This means that, because a MapWidget can only be instantiated with arguments, you cannot just declare it as a @UiField in your view and rely on GWT to instantiate it using a default constructor.

Instead, you have to provide either a constructor (if you're specializing a widget) or a factory method that will be called to instantiate your MapWidget appropriately (with MapOptions as a argument in this case).

For instance, add:

@UiFactory MapWidget createMapWidget() {  // The method name is irrelevant
   MapOptions opts = MapOptions.newInstance();
   options.setScrollWheel(false);         // Some sample customization. You may use fields initialized in your actual view constructor (which is called before) to do so.
   return new MapWidget(opts);
}

See http://developers.google.com/web-toolkit/doc/latest/DevGuideUiBinder?#Using_a_widget

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top