Example usage for com.google.gwt.maps.client.layers TrafficLayer getMap

List of usage examples for com.google.gwt.maps.client.layers TrafficLayer getMap

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.layers TrafficLayer getMap.

Prototype

public final MapWidget getMap() 

Source Link

Usage

From source file:com.google.gwt.maps.testing.client.maps.AdvancedLayersWidget.java

License:Apache License

/**
 * Buttons for toggling layers/*from  w w w  .  j  ava2 s  .com*/
 */
private void drawLayerControls() {

    final TrafficLayer trafficLayer = TrafficLayer.newInstance();
    final Button button = new Button("Traffic");
    button.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (trafficLayer.getMap() == null) {
                trafficLayer.setMap(mapWidget);
                button.getElement().getStyle().setColor("red");
            } else {
                trafficLayer.setMap(null);
                button.getElement().getStyle().setColor("black");
            }
        }
    });

    final TransitLayer transitLayer = TransitLayer.newInstance();
    final Button button2 = new Button("Transit");
    button2.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (transitLayer.getMap() == null) {
                transitLayer.setMap(mapWidget);
                button2.getElement().getStyle().setColor("red");
            } else {
                transitLayer.setMap(null);
                button2.getElement().getStyle().setColor("black");
            }
        }
    });

    final BicyclingLayer bikeLayer = BicyclingLayer.newInstance();
    final Button button3 = new Button("Bicycle");
    button3.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (bikeLayer.getMap() == null) {
                bikeLayer.setMap(mapWidget);
                button3.getElement().getStyle().setColor("red");
            } else {
                bikeLayer.setMap(null);
                button3.getElement().getStyle().setColor("black");
            }
        }
    });

    FlowPanel widget = new FlowPanel();
    widget.add(button);
    widget.add(new HTML("Advanced Layers"));
    widget.add(button);
    widget.add(button2);
    widget.add(button3);

    DOM.setStyleAttribute(widget.getElement(), "background", "white");
    DOM.setStyleAttribute(widget.getElement(), "padding", "5px");
    DOM.setStyleAttribute(widget.getElement(), "margin", "3px");
    DOM.setStyleAttribute(widget.getElement(), "border", "3px solid darkgray");

    mapWidget.setControls(ControlPosition.RIGHT_CENTER, widget);

    // apply button so people can see more interesting map
    trafficLayer.setMap(mapWidget);
    button.getElement().getStyle().setColor("red");
}