GWT-Maps-V3-Api icon indicating copy to clipboard operation
GWT-Maps-V3-Api copied to clipboard

Map not showing when setting MapTypeId directly on MapWidget

Open felixnutella opened this issue 11 years ago • 6 comments

Could it be that setting a maptype on a mapwidget BEFORE the widget is rendered would cause the map not to be displayed? Moving the maptype to the options object used instantiating the mapwidget works fine - but using the setMapTypeId(MapTypeId) screws it up.

This works:

private MapWidget setupMap() {
        MapOptions options = MapOptions.newInstance(true);
        options.setPanControl(false);
        options.setZoomControl(true);
        options.setZoomControlOptions(ZoomControlOptions.newInstance());
        options.getZoomControlOptions().setPosition(ControlPosition.LEFT_BOTTOM);
        options.setStreetViewControl(false);
        options.setMapTypeId(MapTypeId.HYBRID);
        options.setZoom(9);
        options.setCenter(LatLng.newInstance(57.063327, 9.896793));
        mapWidget = new MapWidget(options) {
            @Override
            protected void onAttach() {
                super.onAttach();
                Timer timer = new Timer() {

                    @Override
                    public void run() {
                        triggerResize();
                    }
                };
                timer.schedule(5);
            }
        };
        mapWidget.setSize("100%", "100%");
        mapWidget.getBounds().extend(mapWidget.getCenter());
        return mapWidget;
}

This does not:

private MapWidget setupMap() {
        MapOptions options = MapOptions.newInstance(true);
        options.setPanControl(false);
        options.setZoomControl(true);
        options.setZoomControlOptions(ZoomControlOptions.newInstance());
        options.getZoomControlOptions().setPosition(ControlPosition.LEFT_BOTTOM);
        options.setStreetViewControl(false);
        options.setZoom(9);
        options.setCenter(LatLng.newInstance(57.063327, 9.896793));
        mapWidget = new MapWidget(options) {
            @Override
            protected void onAttach() {
                super.onAttach();
                Timer timer = new Timer() {

                    @Override
                    public void run() {
                        triggerResize();
                    }
                };
                timer.schedule(5);
            }
        };
        mapWidget.setSize("100%", "100%");
        mapWidget.getBounds().extend(mapWidget.getCenter());
        mapWidget.setMapTypeId(MapTypeId.HYBRID);
        return mapWidget;
}

The only difference as I see is that the maptype is set on the options object when it works, and directly on the mapwidget when it does not.

Adding markers to the map works fine for both implementations, it's the map images and controls that does not show up.

felixnutella avatar Mar 20 '13 14:03 felixnutella

Does the map show up with a simpler configuration?

branflake2267 avatar Mar 20 '13 14:03 branflake2267

I'm not aware of the maptypeid having an issue yet. I'm wondering what the parent widget size is. Does the map show up at all in any configuration?

branflake2267 avatar Mar 20 '13 14:03 branflake2267

Think I found the cause of the error. Apparently the Options supports both upper and lowercase string value for the maptype. But setting the maptype on the map object is not working with uppercase. And taking the name() from the MapTypeId enum returns an uppercase value, which in turns makes it fail.

Woups - sorry for closing :)

felixnutella avatar Mar 20 '13 15:03 felixnutella

Thanks for reporting. I'm wondering if I should handle that. :)

branflake2267 avatar Mar 20 '13 16:03 branflake2267

Even if it is Googles mistake, I think it would be good if the project handles it - it's best if the code works as expected ;)

felixnutella avatar Mar 21 '13 08:03 felixnutella

Good point, I'll have to look deeper at it.

branflake2267 avatar Mar 21 '13 14:03 branflake2267