branflake2267 / GWT-Maps-V3-Api

GWT Maps V3 Javascript Bindings
Other
144 stars 113 forks source link

Map not showing when setting MapTypeId directly on MapWidget #176

Open felixnutella opened 11 years ago

felixnutella commented 11 years ago

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.

branflake2267 commented 11 years ago

Does the map show up with a simpler configuration?

branflake2267 commented 11 years ago

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?

felixnutella commented 11 years ago

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

branflake2267 commented 11 years ago

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

felixnutella commented 11 years ago

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

branflake2267 commented 11 years ago

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