Example usage for com.google.gwt.ajaxloader.client ArrayHelper toJsArrayString

List of usage examples for com.google.gwt.ajaxloader.client ArrayHelper toJsArrayString

Introduction

In this page you can find the example usage for com.google.gwt.ajaxloader.client ArrayHelper toJsArrayString.

Prototype

public static JsArrayString toJsArrayString(String... strings) 

Source Link

Document

Converts an array of Java strings to an array of JavaScript strings.

Usage

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

License:Apache License

private void getDistance() {
    String origin = "Arlington, WA";
    String destination = "Seattle, WA";

    String[] ao = new String[1];
    ao[0] = origin;//from   w w w. j  a  v a2 s .  co  m
    JsArrayString origins = ArrayHelper.toJsArrayString(ao);

    String[] ad = new String[1];
    ad[0] = destination;
    JsArrayString destinations = ArrayHelper.toJsArrayString(ad);

    DistanceMatrixRequest request = DistanceMatrixRequest.newInstance();
    request.setOrigins(origins);
    request.setDestinations(destinations);
    request.setTravelMode(TravelMode.DRIVING);

    DistanceMatrixService o = DistanceMatrixService.newInstance();
    o.getDistanceMatrix(request, new DistanceMatrixRequestHandler() {
        public void onCallback(DistanceMatrixResponse response, DistanceMatrixStatus status) {
            GWT.log("status=" + status.value());

            if (status == DistanceMatrixStatus.INVALID_REQUEST) {

            } else if (status == DistanceMatrixStatus.MAX_DIMENSIONS_EXCEEDED) {

            } else if (status == DistanceMatrixStatus.MAX_ELEMENTS_EXCEEDED) {

            } else if (status == DistanceMatrixStatus.OK) {

                @SuppressWarnings("unused")
                JsArrayString dest = response.getDestinationAddresses();
                @SuppressWarnings("unused")
                JsArrayString org = response.getOriginAddresses();
                JsArray<DistanceMatrixResponseRow> rows = response.getRows();

                GWT.log("rows.length=" + rows.length());
                DistanceMatrixResponseRow d = rows.get(0);
                JsArray<DistanceMatrixResponseElement> elements = d.getElements();
                for (int i = 0; i < elements.length(); i++) {
                    DistanceMatrixResponseElement e = elements.get(i);
                    Distance distance = e.getDistance();
                    Duration duration = e.getDuration();

                    @SuppressWarnings("unused")
                    DistanceMatrixElementStatus st = e.getStatus();
                    GWT.log("distance=" + distance.getText() + " value=" + distance.getValue());
                    GWT.log("duration=" + duration.getText() + " value=" + duration.getValue());

                    String html = "&nbsp;&nbsp;Distance=" + distance.getText() + " Duration="
                            + duration.getText() + " ";
                    htmlDistanceMatrixService.setHTML(html);
                }

            } else if (status == DistanceMatrixStatus.OVER_QUERY_LIMIT) {

            } else if (status == DistanceMatrixStatus.REQUEST_DENIED) {

            } else if (status == DistanceMatrixStatus.UNKNOWN_ERROR) {

            }

        }
    });

}

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

License:Apache License

/**
 * Sample gradient from <a href=// w  w w .ja  v  a  2 s .  c  o m
 * "https://google-developers.appspot.com/maps/documentation/javascript/examples/layer-heatmap"
 * >Google Maps Example</a>
 * 
 * @return
 */
private JsArrayString getSampleGradient() {
    String[] sampleColors = new String[] { "rgba(0, 255, 255, 0)", "rgba(0, 255, 255, 1)",
            "rgba(0, 191, 255, 1)", "rgba(0, 127, 255, 1)", "rgba(0, 63, 255, 1)", "rgba(0, 0, 255, 1)",
            "rgba(0, 0, 223, 1)", "rgba(0, 0, 191, 1)", "rgba(0, 0, 159, 1)", "rgba(0, 0, 127, 1)",
            "rgba(63, 0, 91, 1)", "rgba(127, 0, 63, 1)", "rgba(191, 0, 31, 1)", "rgba(255, 0, 0, 1)" };
    return ArrayHelper.toJsArrayString(sampleColors);
}