Example usage for com.google.gwt.maps.client.events MapEventType RESIZE

List of usage examples for com.google.gwt.maps.client.events MapEventType RESIZE

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.events MapEventType RESIZE.

Prototype

MapEventType RESIZE

To view the source code for com.google.gwt.maps.client.events MapEventType RESIZE.

Click Source Link

Usage

From source file:com.google.sampling.experiential.client.ChartPanel.java

License:Open Source License

private Widget renderEventsOnMap() {
    markers.clear();//from ww  w  . java2s .c o m
    createMap();
    final LatLngBounds bounds = LatLngBounds.newInstance(google, google);
    for (final EventDAO event : data) {
        String latLon = event.getWhatByKey(input.getName());
        if (latLon == null || latLon.length() == 0) {
            continue;
        }
        String[] splits = latLon.split(",");
        if (splits == null || splits.length != 2) {
            continue;
        }
        try {
            double latitude = Double.parseDouble(splits[0]);
            double longitude = Double.parseDouble(splits[1]);

            MarkerOptions markerOptions = MarkerOptions.newInstance();
            markerOptions.setMap(map);
            markerOptions.setTitle(event.getWhatString());
            LatLng newInstance = LatLng.newInstance(latitude, longitude);
            final Marker marker = Marker.newInstance(markerOptions);
            marker.setPosition(newInstance);
            bounds.union(LatLngBounds.newInstance(marker.getPosition(), marker.getPosition()));
            marker.addClickHandler(new ClickMapHandler() {
                @Override
                public void onEvent(ClickMapEvent mapEvent) {
                    openInfoWindowForMarker(event, marker);
                }
            });
            markers.put(event, marker);
        } catch (NumberFormatException nfe) {
        }
    }

    map.fitBounds(bounds);

    final LatLng oldCenter = map.getCenter();
    final int oldZoom = map.getZoom();
    map.addResizeHandler(new ResizeMapHandler() {

        @Override
        public void onEvent(ResizeMapEvent event) {
            map.setCenter(oldCenter);
            map.setZoom(oldZoom);
            map.fitBounds(bounds);
        }
    });
    Window.addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(ResizeEvent event) {
            MapHandlerRegistration.trigger(map, MapEventType.RESIZE);
            GWT.log("Window has been resized!");
        }
    });
    return map;
}

From source file:com.google.sampling.experiential.client.ChartPanel.java

License:Open Source License

@Override
protected void onLoad() {
    // TODO Auto-generated method stub
    super.onLoad();
    MapHandlerRegistration.trigger(map, MapEventType.RESIZE);
}

From source file:gov.wa.wsdot.mobile.client.activities.ferries.vesselwatch.VesselWatchMapViewGwtImpl.java

License:Open Source License

public VesselWatchMapViewGwtImpl() {

    initWidget(uiBinder.createAndBindUi(this));

    accessibilityPrepare();/*from w  w  w.j  av  a 2  s.c o  m*/

    if (MGWT.getOsDetection().isAndroid()) {
        leftFlexSpacer.setVisible(false);
    }

    if (localStorage != null) {
        storageMap = new StorageMap(localStorage);
        if (!storageMap.containsKey("KEY_SHOW_CAMERAS")) {
            localStorage.setItem("KEY_SHOW_CAMERAS", "true"); // Set initial default value
        }

        // Set initial default location and zoom to Seattle area.
        localStorage.setItem("KEY_MAP_LAT", "47.565125");
        localStorage.setItem("KEY_MAP_LON", "-122.480508");
        localStorage.setItem("KEY_MAP_ZOOM", "11");
    }

    final TrafficLayer trafficLayer = TrafficLayer.newInstance();

    LatLng center = LatLng.newInstance(Double.valueOf(localStorage.getItem("KEY_MAP_LAT")),
            Double.valueOf(localStorage.getItem("KEY_MAP_LON")));

    MapOptions opts = MapOptions.newInstance();
    opts.setMapTypeId(MapTypeId.ROADMAP);
    opts.setCenter(center);
    opts.setZoom(Integer.valueOf(localStorage.getItem("KEY_MAP_ZOOM"), 10));
    opts.setPanControl(false);
    opts.setZoomControl(false);
    opts.setMapTypeControl(false);
    opts.setScaleControl(false);
    opts.setStreetViewControl(false);
    opts.setOverviewMapControl(false);

    // Custom map style to remove all "Points of Interest" labels from map
    MapTypeStyle style1 = MapTypeStyle.newInstance();
    style1.setFeatureType(MapTypeStyleFeatureType.POI);
    style1.setElementType(MapTypeStyleElementType.LABELS);
    style1.setStylers(new MapTypeStyler[] { MapTypeStyler.newVisibilityStyler("off") });
    MapTypeStyle[] styles = { style1 };

    opts.setMapTypeStyles(styles);

    mapWidget = new MyMapWidget(opts);
    trafficLayer.setMap(mapWidget);
    flowPanel.add(mapWidget);

    mapWidget.setSize(Window.getClientWidth() + "px",
            (Window.getClientHeight() - ParserUtils.windowUI()) + "px");

    Window.addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(ResizeEvent event) {
            MapHandlerRegistration.trigger(mapWidget, MapEventType.RESIZE);

        }
    });

    mapWidget.addResizeHandler(new ResizeMapHandler() {
        @Override
        public void onEvent(ResizeMapEvent event) {
            mapWidget.setSize(Window.getClientWidth() + "px",
                    (Window.getClientHeight() - ParserUtils.windowUI()) + "px");
        }
    });

    mapWidget.addIdleHandler(new IdleMapHandler() {

        @Override
        public void onEvent(IdleMapEvent event) {
            localStorage.setItem("KEY_MAP_LAT", String.valueOf(mapWidget.getCenter().getLatitude()));
            localStorage.setItem("KEY_MAP_LON", String.valueOf(mapWidget.getCenter().getLongitude()));
            localStorage.setItem("KEY_MAP_ZOOM", String.valueOf(mapWidget.getZoom()));

            if (presenter != null) {
                presenter.onMapIsIdle();
            }
        }
    });

}

From source file:gov.wa.wsdot.mobile.client.activities.trafficmap.TrafficMapViewGwtImpl.java

License:Open Source License

public TrafficMapViewGwtImpl() {

    initWidget(uiBinder.createAndBindUi(this));

    accessibilityPrepare();/*from w  w w  .ja va  2  s .co m*/

    if (MGWT.getOsDetection().isAndroid()) {
        leftFlexSpacer.setVisible(false);
    }

    if (localStorage != null) {
        storageMap = new StorageMap(localStorage);
        if (!storageMap.containsKey("KEY_SHOW_CAMERAS")) {
            localStorage.setItem("KEY_SHOW_CAMERAS", "true"); // Set initial default value
        }
        if (!storageMap.containsKey("KEY_SHOW_RESTAREAS")) {
            localStorage.setItem("KEY_SHOW_RESTAREAS", "false"); // Set initial default value
        }

        // Set initial default location and zoom to Seattle area.
        if (!storageMap.containsKey("KEY_MAP_LAT")) {
            localStorage.setItem("KEY_MAP_LAT", "47.5990");
        }
        if (!storageMap.containsKey("KEY_MAP_LON")) {
            localStorage.setItem("KEY_MAP_LON", "-122.3350");
        }
        if (!storageMap.containsKey("KEY_MAP_ZOOM")) {
            localStorage.setItem("KEY_MAP_ZOOM", "12");
        }
    }

    final TrafficLayer trafficLayer = TrafficLayer.newInstance();

    LatLng center = LatLng.newInstance(Double.valueOf(localStorage.getItem("KEY_MAP_LAT")),
            Double.valueOf(localStorage.getItem("KEY_MAP_LON")));

    MapOptions opts = MapOptions.newInstance();
    opts.setMapTypeId(MapTypeId.ROADMAP);
    opts.setCenter(center);
    opts.setZoom(Integer.valueOf(localStorage.getItem("KEY_MAP_ZOOM"), 10));
    opts.setPanControl(false);
    opts.setZoomControl(false);
    opts.setMapTypeControl(false);
    opts.setScaleControl(false);
    opts.setStreetViewControl(false);
    opts.setOverviewMapControl(false);

    // Custom map style to remove all "Points of Interest" labels from map
    MapTypeStyle style1 = MapTypeStyle.newInstance();
    style1.setFeatureType(MapTypeStyleFeatureType.POI);
    style1.setElementType(MapTypeStyleElementType.LABELS);
    style1.setStylers(new MapTypeStyler[] { MapTypeStyler.newVisibilityStyler("off") });
    MapTypeStyle[] styles = { style1 };

    opts.setMapTypeStyles(styles);

    mapWidget = new MyMapWidget(opts);
    trafficLayer.setMap(mapWidget);
    flowPanel.add(mapWidget);

    mapWidget.setSize(Window.getClientWidth() + "px",
            (Window.getClientHeight() - ParserUtils.windowUI()) + "px");

    Window.addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(ResizeEvent event) {
            MapHandlerRegistration.trigger(mapWidget, MapEventType.RESIZE);

        }
    });

    mapWidget.addResizeHandler(new ResizeMapHandler() {
        @Override
        public void onEvent(ResizeMapEvent event) {
            mapWidget.setSize(Window.getClientWidth() + "px",
                    (Window.getClientHeight() - ParserUtils.windowUI()) + "px");
        }
    });

    mapWidget.addIdleHandler(new IdleMapHandler() {

        @Override
        public void onEvent(IdleMapEvent event) {
            localStorage.setItem("KEY_MAP_LAT", String.valueOf(mapWidget.getCenter().getLatitude()));
            localStorage.setItem("KEY_MAP_LON", String.valueOf(mapWidget.getCenter().getLongitude()));
            localStorage.setItem("KEY_MAP_ZOOM", String.valueOf(mapWidget.getZoom()));

            if (presenter != null) {
                presenter.onMapIsIdle();
            }
        }
    });
}