Example usage for com.google.gwt.maps.client.layers TransitLayer newInstance

List of usage examples for com.google.gwt.maps.client.layers TransitLayer newInstance

Introduction

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

Prototype

public static final TransitLayer newInstance() 

Source Link

Document

creates a traffic layer

Usage

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

License:Apache License

/**
 * Buttons for toggling layers/*from   ww w.j a  va 2 s .c om*/
 */
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");
}

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

License:Apache License

private void drawMap() {
    // zoom out for the clouds
    LatLng center = LatLng.newInstance(40.74, -73.94);
    MapOptions opts = MapOptions.newInstance();
    opts.setZoom(11);/*from  w  w w .  j  a  v  a  2s  .c o m*/
    opts.setCenter(center);
    opts.setMapTypeId(MapTypeId.TERRAIN);

    mapWidget = new MapWidget(opts);
    pWidget.add(mapWidget);
    mapWidget.setSize("750px", "500px");

    // show transit layer
    TransitLayer transitLayer = TransitLayer.newInstance();
    transitLayer.setMap(mapWidget);

    // create layer
    HeatMapLayerOptions options = HeatMapLayerOptions.newInstance();
    options.setOpacity(0.9);
    options.setRadius(5);
    options.setGradient(getSampleGradient());
    options.setMaxIntensity(3);
    options.setMap(mapWidget);

    HeatMapLayer heatMapLayer = HeatMapLayer.newInstance(options);
    // set data
    JsArray<LatLng> dataPoints = getSampleData();
    heatMapLayer.setData(dataPoints);

    // the other way to set data
    // note JS array can be set from this method, but only MVCArray from the
    // options setData() method
    // MVCArray<WeightedLocation> weightedDataPoints =
    // MVCArray.newInstance(getSampleWeightedData());
    // heatMapLayer.setDataWeighted(weightedDataPoints);
    GWT.log("Plotting " + dataPoints.length() + " points on HeatMap");
}