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

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

Introduction

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

Prototype

public static <J extends JavaScriptObject> JsArray<J> toJsArray(J... objects) 

Source Link

Usage

From source file:com.arcbees.website.client.application.contact.ContactView.java

License:Apache License

private void onMapsLoaded() {
    // -- HOW TO STYLE A GOOGLE MAP
    // -> First, we create the style. To help : http://software.stadtwerk.org/google_maps_colorizr/
    MapTypeStyle style1 = MapTypeStyle.newInstance();
    style1.setElementType(MapTypeStyleElementType.GEOMETRY);
    style1.setFeatureType(MapTypeStyleFeatureType.ROAD);
    style1.setStylers(new MapTypeStyler[] { MapTypeStyler.newHueStyler("#FFF"),
            MapTypeStyler.newSaturationStyler(-100), MapTypeStyler.newLightnessStyler(100) });

    MapTypeStyle style2 = MapTypeStyle.newInstance();
    style2.setElementType(MapTypeStyleElementType.ALL);
    style2.setFeatureType(MapTypeStyleFeatureType.LANDSCAPE);
    style2.setStylers(new MapTypeStyler[] { MapTypeStyler.newHueStyler("#cccccc"),
            MapTypeStyler.newSaturationStyler(-100), MapTypeStyler.newLightnessStyler(-10) });

    MapTypeStyle style3 = MapTypeStyle.newInstance();
    style3.setElementType(MapTypeStyleElementType.ALL);
    style3.setFeatureType(MapTypeStyleFeatureType.POI);
    style3.setStylers(new MapTypeStyler[] { MapTypeStyler.newHueStyler("#f00"),
            MapTypeStyler.newSaturationStyler(-100), MapTypeStyler.newLightnessStyler(9), });

    MapTypeStyle style4 = MapTypeStyle.newInstance();
    style4.setElementType(MapTypeStyleElementType.ALL);
    style4.setFeatureType(MapTypeStyleFeatureType.WATER);
    style4.setStylers(new MapTypeStyler[] { MapTypeStyler.newHueStyler("#1c1c1c"),
            MapTypeStyler.newSaturationStyler(-100), MapTypeStyler.newLightnessStyler(86), });

    MapTypeStyle[] array = { style1, style2, style3, style4 };

    JsArray<MapTypeStyle> styles = ArrayHelper.toJsArray(array);

    // -> Then we tell the map to use our new style by default
    MapTypeControlOptions controlOptions = MapTypeControlOptions.newInstance();
    controlOptions.setMapTypeIds(new String[] {});
    controlOptions.setPosition(ControlPosition.TOP_RIGHT);

    // -> And tell the map what our custom style is
    StyledMapTypeOptions styledMapTypeOptions = StyledMapTypeOptions.newInstance();
    styledMapTypeOptions.setName("Arcbees");
    StyledMapType customMapType = StyledMapType.newInstance(styles, styledMapTypeOptions);

    // -> Then we define our Lat and Long
    LatLng arcbeesCoord = LatLng.newInstance(46.792097, -71.285362);

    // -> Then goes the map options
    MapOptions options = MapOptions.newInstance();
    options.setCenter(arcbeesCoord);//from w w w.j a v  a 2 s  .c  om
    options.setZoom(16);
    options.setScrollWheel(false);
    options.setMapTypeControlOptions(controlOptions);
    options.setMapTypeId(ARCBEES_MAPTYPE);
    options.setPanControl(false);
    options.setDraggable(Window.getClientWidth() > 649);

    ZoomControlOptions zoomControlOptions = ZoomControlOptions.newInstance();
    zoomControlOptions.setPosition(ControlPosition.RIGHT_CENTER);
    options.setZoomControlOptions(zoomControlOptions);

    // -> We create the map with our options
    MapWidget mapWidget = new MapWidget(options);
    mapWidget.addStyleName(page.style().map());
    mapWidget.setCustomMapType(ARCBEES_MAPTYPE, customMapType);

    // -> We define the marker
    MarkerOptions markerOptions = MarkerOptions.newInstance();
    markerOptions.setIcon(pageContactResources.marker().getSafeUri().asString());
    markerOptions.setMap(mapWidget);
    markerOptions.setPosition(arcbeesCoord);

    Marker.newInstance(markerOptions);

    // -> And finally, add it to its container
    container.add(mapWidget);
}

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

License:Apache License

private void drawShapes() {
    // add some draw shapes for folks
    CircleOptions cOpts = CircleOptions.newInstance();
    cOpts.setCenter(LatLng.newInstance(52.62d, -119.95d));
    cOpts.setFillColor("#FF0000");
    cOpts.setStrokeColor("CCFF44");
    cOpts.setFillOpacity(0.5d);//from   ww w.  j a v  a2  s .c om
    cOpts.setStrokeOpacity(0.9d);
    cOpts.setStrokeWeight(3);
    cOpts.setRadius(1000000d);
    cOpts.setMap(mapWidget);
    @SuppressWarnings("unused")
    Circle circle = Circle.newInstance(cOpts);

    cOpts = CircleOptions.newInstance();
    cOpts.setCenter(LatLng.newInstance(40.569d, -82.7929d));
    cOpts.setFillColor("#00FF00");
    cOpts.setStrokeColor("FFCCFF");
    cOpts.setFillOpacity(0.7d);
    cOpts.setStrokeOpacity(0.9d);
    cOpts.setStrokeWeight(10);
    cOpts.setRadius(300000d);
    cOpts.setMap(mapWidget);
    @SuppressWarnings("unused")
    Circle circle2 = Circle.newInstance(cOpts);

    LatLng[] a = new LatLng[18];
    a[0] = LatLng.newInstance(49.02824580511537, -104.0899658203125);
    a[1] = LatLng.newInstance(43.009982694835784, -104.0679931640625);
    a[2] = LatLng.newInstance(43.026047765621, -98.5528564453125);
    a[3] = LatLng.newInstance(42.73623356449312, -98.0255126953125);
    a[4] = LatLng.newInstance(42.89740952345494, -97.9156494140625);
    a[5] = LatLng.newInstance(42.83298955227273, -97.3883056640625);
    a[6] = LatLng.newInstance(42.52607693975099, -96.5753173828125);
    a[7] = LatLng.newInstance(43.20248609768505, -96.4654541015625);
    a[8] = LatLng.newInstance(43.521979415112206, -96.6192626953125);
    a[9] = LatLng.newInstance(43.69698341176971, -96.5093994140625);
    a[10] = LatLng.newInstance(45.32638440880054, -96.4215087890625);
    a[11] = LatLng.newInstance(45.54224714353031, -96.9708251953125);
    a[12] = LatLng.newInstance(45.757284242039375, -96.6851806640625);
    a[13] = LatLng.newInstance(46.23050041945144, -96.5533447265625);
    a[14] = LatLng.newInstance(46.714738770992284, -96.9049072265625);
    a[15] = LatLng.newInstance(47.67030090972658, -96.8170166015625);
    a[16] = LatLng.newInstance(47.98009843932673, -97.1466064453125);
    a[17] = LatLng.newInstance(48.97058369834937, -97.2125244140625);
    JsArray<LatLng> paths = ArrayHelper.toJsArray(a);

    PolygonOptions pOpts = PolygonOptions.newInstance();
    pOpts.setFillColor("#0000FF");
    pOpts.setStrokeColor("FFFFFF");
    pOpts.setFillOpacity(0.4d);
    pOpts.setStrokeOpacity(0.9d);
    pOpts.setStrokeWeight(6);
    pOpts.setPaths(paths);
    pOpts.setMap(mapWidget);
    @SuppressWarnings("unused")
    Polygon polygon = Polygon.newInstance(pOpts);
}

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

License:Apache License

private void findElevation(LatLng point) {

    LatLng[] a = new LatLng[] { point };

    JsArray<LatLng> locations = ArrayHelper.toJsArray(a);

    LocationElevationRequest request = LocationElevationRequest.newInstance();
    request.setLocations(locations);/*from w  ww .ja va 2  s.  c  o m*/

    ElevationService o = ElevationService.newInstance();
    o.getElevationForLocations(request, new ElevationServiceHandler() {
        @Override
        public void onCallback(JsArray<ElevationResult> result, ElevationStatus status) {

            if (status == ElevationStatus.INVALID_REQUEST) {

            } else if (status == ElevationStatus.OK) {
                ElevationResult e = result.get(0);
                double elevation = e.getElevation();
                LatLng location = e.getLocation();
                @SuppressWarnings("unused")
                double res = e.getResolution();

                GWT.log("worked elevation=" + elevation);
                drawInfoWindow(location, elevation);

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

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

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

            }

            GWT.log("elevation request finished");
        }
    });
}

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

License:Apache License

/**
 * Get (randomly_ weighted spatial data for use in tests
 * //  w w w.  j a  v a 2s .  c  o  m
 * @return
 */
@SuppressWarnings("unused")
// here as an example of WeightedDataPoints
private JsArray<WeightedLocation> getSampleWeightedData() {
    JsArray<LatLng> samplePoints = getSampleData();
    JsArray<WeightedLocation> sampleLocations = ArrayHelper.toJsArray(new WeightedLocation[] {});
    for (int n = 0, len = samplePoints.length(); n < len; n++) {
        sampleLocations.push(WeightedLocation.newInstance(samplePoints.get(n), 10 * Math.random()));
    }
    return sampleLocations;
}

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

License:Apache License

/**
 * Add {@link Polyline} overlay to {@link MapWidget} with an {@link IconSequence}
 *//* ww  w  . j  a  va2  s. c  o  m*/
private void drawPolyline() {

    /*** (1) A nice simple line ***/
    LatLng[] a = new LatLng[12];
    a[0] = LatLng.newInstance(35.859300, -78.765407);
    a[1] = LatLng.newInstance(35.860622, -78.763282);
    a[2] = LatLng.newInstance(35.861074, -78.763862);
    a[3] = LatLng.newInstance(35.861770, -78.764055);
    a[4] = LatLng.newInstance(35.863752, -78.763647);
    a[5] = LatLng.newInstance(35.867561, -78.763518);
    a[6] = LatLng.newInstance(35.869091, -78.762445);
    a[7] = LatLng.newInstance(35.869195, -78.761823);
    a[8] = LatLng.newInstance(35.868239, -78.759162);
    a[9] = LatLng.newInstance(35.868256, -78.758519);
    a[10] = LatLng.newInstance(35.871369, -78.756759);
    a[11] = LatLng.newInstance(35.874168, -78.756781);
    JsArray<LatLng> simpleLatLngArr = ArrayHelper.toJsArray(a);

    // Draw various recurring symbols on the map
    // different colors and sizes/types shown
    final Symbol icon1 = Symbol.newInstance(SymbolPath.CIRCLE, 4d);
    icon1.setStrokeColor("blue");
    final Symbol icon2 = Symbol.newInstance(SymbolPath.FORWARD_CLOSED_ARROW, 5d);
    icon2.setStrokeColor("yellow");
    final Symbol icon3 = Symbol.newInstance(SymbolPath.FORWARD_OPEN_ARROW, 3d);
    icon3.setStrokeColor("orange");

    // start different sequences in different areas
    final IconSequence iconSeq1 = IconSequence.newInstance();
    iconSeq1.setIcon(icon1);
    iconSeq1.setOffset("10%");
    iconSeq1.setRepeat("22%");

    final IconSequence iconSeq2 = IconSequence.newInstance();
    iconSeq2.setIcon(icon2);
    iconSeq2.setOffset("50%");
    iconSeq2.setRepeat("7%");

    final IconSequence iconSeq3 = IconSequence.newInstance();
    iconSeq3.setIcon(icon3);
    iconSeq3.setOffset("70%");
    iconSeq3.setRepeat("5%");

    final JsArray<IconSequence> iconsArr = ArrayHelper
            .toJsArray(new IconSequence[] { iconSeq1, iconSeq2, iconSeq3 });

    PolylineOptions opts = PolylineOptions.newInstance();
    // opts.setMap(mapWidget); // you can attach it to the map here
    opts.setPath(simpleLatLngArr);
    opts.setStrokeColor("#0000FF");
    opts.setStrokeOpacity(1.0);
    opts.setStrokeWeight(2);
    opts.setIcons(iconsArr);

    Polyline polyLine = Polyline.newInstance(opts);
    polyLine.setMap(mapWidget); // or here, but this can also reassign it if you
                                // like
                                // this allows you to make polylines with no map, and then display them as
                                // needed

    /*** (2) Another simple line reusing some of the above ***/
    LatLng[] b = new LatLng[12];
    b[0] = LatLng.newInstance(35.864535, -78.761544);
    b[1] = LatLng.newInstance(35.864048, -78.761458);
    b[2] = LatLng.newInstance(35.863804, -78.762360);
    b[3] = LatLng.newInstance(35.862900, -78.762188);
    b[4] = LatLng.newInstance(35.861300, -78.762960);
    b[5] = LatLng.newInstance(35.860813, -78.763003);
    b[6] = LatLng.newInstance(35.860953, -78.761544);
    b[7] = LatLng.newInstance(35.859944, -78.759613);
    b[8] = LatLng.newInstance(35.860187, -78.758497);
    b[9] = LatLng.newInstance(35.860187, -78.756952);
    b[10] = LatLng.newInstance(35.861057, -78.755836);
    b[11] = LatLng.newInstance(35.861926, -78.756180);
    JsArray<LatLng> simpleLatLngArr2 = ArrayHelper.toJsArray(b);

    PolylineOptions opts3 = PolylineOptions.newInstance();
    opts3.setMap(mapWidget);
    opts3.setPath(simpleLatLngArr2);
    opts3.setStrokeColor("#00FF00");
    opts3.setStrokeOpacity(1.0);
    opts3.setStrokeWeight(2);

    @SuppressWarnings("unused")
    Polyline polyLine2 = Polyline.newInstance(opts3);

    /*** (2) A longer line ***/
    // NOTE: this is just an example - usually you would pull these values from
    // a database via RPC/XHR or from an XML file
    double[] lngPoints = new double[] { -78.759110, -78.758900, -78.758660, -78.758530, -78.758340, -78.758230,
            -78.758300, -78.758210, -78.758070, -78.757890, -78.757790, -78.757810, -78.757890, -78.757770,
            -78.757650, -78.757260, -78.757160, -78.757250, -78.757200, -78.757230, -78.757370, -78.757300,
            -78.756980, -78.756940, -78.756950, -78.757140, -78.757190, -78.757190, -78.757090, -78.756930,
            -78.756590, -78.756760, -78.755650, -78.754790, -78.754450, -78.754060, -78.753400, -78.752990,
            -78.752630, -78.752510, -78.752290, -78.751970, -78.751630, -78.750420, -78.750010, -78.749700,
            -78.749320, -78.749260, -78.749250, -78.749190, -78.748670, -78.748560, -78.748240, -78.747880,
            -78.747230, -78.747420, -78.747840, -78.748150, -78.748260, -78.748730, -78.749330, -78.749870,
            -78.750190, -78.750540, -78.750890, -78.751370, -78.751640, -78.751730, -78.751780, -78.751740,
            -78.751850, -78.752040, -78.752230, -78.752370, -78.752720, -78.752800, -78.752650, -78.752610,
            -78.752790, -78.752750, -78.752840, -78.752770, -78.752640, -78.752730, -78.752610, -78.752490,
            -78.751960, -78.751580, -78.751160, -78.750290, -78.749940, -78.749190, -78.748980, -78.748680,
            -78.748300, -78.747970, -78.747470, -78.747370, -78.747100, -78.746850, -78.746750, -78.746240,
            -78.745870, -78.745760, -78.745600, -78.745610, -78.745440, -78.745460, -78.745330, -78.745140,
            -78.744340, -78.744180, -78.744100, -78.744140, -78.744020, -78.743890, -78.743470, -78.743340,
            -78.743060, -78.742930, -78.742790, -78.742580, -78.742420, -78.742240, -78.741820, -78.741480,
            -78.740300, -78.739860, -78.739570, -78.739560, -78.739620, -78.739690, -78.740100, -78.740230,
            -78.740200, -78.740010, -78.740050, -78.740190, -78.740570, -78.740800, -78.741020, -78.741110,
            -78.741060, -78.741330, -78.742010, -78.742190, -78.742510, -78.743730, -78.744190, -78.744470,
            -78.744880, -78.745090, -78.745490, -78.746380, -78.746680, -78.746870, -78.747030, -78.747120,
            -78.747390, -78.747580, -78.748200, -78.748440, -78.748640, -78.749100, -78.749330 };
    double[] latPoints = new double[] { 35.871900, 35.871910, 35.871810, 35.871630, 35.871530, 35.871600,
            35.872110, 35.872290, 35.872390, 35.872370, 35.872250, 35.872100, 35.871970, 35.871790, 35.871710,
            35.871760, 35.871900, 35.872140, 35.872560, 35.872710, 35.872920, 35.873100, 35.873510, 35.873950,
            35.874080, 35.874130, 35.874290, 35.874480, 35.874640, 35.874700, 35.874650, 35.874170, 35.874120,
            35.873970, 35.873830, 35.873500, 35.872870, 35.872390, 35.871770, 35.871290, 35.870800, 35.870690,
            35.870630, 35.870860, 35.870810, 35.870680, 35.870260, 35.870050, 35.869390, 35.869110, 35.868340,
            35.867830, 35.867830, 35.867400, 35.867170, 35.866810, 35.864720, 35.863690, 35.863360, 35.862590,
            35.861920, 35.861850, 35.861710, 35.861460, 35.861280, 35.861250, 35.861100, 35.861090, 35.861130,
            35.861440, 35.861490, 35.861400, 35.861120, 35.860650, 35.860030, 35.859720, 35.859260, 35.858510,
            35.857480, 35.857070, 35.856950, 35.856640, 35.856430, 35.855980, 35.855830, 35.855700, 35.855430,
            35.855120, 35.854880, 35.854720, 35.854700, 35.854770, 35.854710, 35.854610, 35.854310, 35.854280,
            35.854040, 35.854020, 35.854150, 35.854000, 35.853760, 35.853450, 35.853360, 35.853540, 35.854090,
            35.854210, 35.854670, 35.855360, 35.855920, 35.856130, 35.856580, 35.856720, 35.856950, 35.857300,
            35.857440, 35.857450, 35.857250, 35.857140, 35.856360, 35.855770, 35.855450, 35.855220, 35.855190,
            35.855260, 35.855760, 35.856060, 35.856790, 35.857200, 35.857730, 35.858260, 35.858770, 35.858920,
            35.859350, 35.859740, 35.859940, 35.860300, 35.860980, 35.861050, 35.861090, 35.861200, 35.861370,
            35.861490, 35.862020, 35.862050, 35.862030, 35.862270, 35.862460, 35.863130, 35.863280, 35.863250,
            35.863080, 35.863040, 35.863140, 35.863120, 35.863060, 35.862900, 35.862270, 35.862180, 35.862020,
            35.862000, 35.861690, 35.861620, 35.861620, 35.861870, 35.861920 };

    // how you can make a bunch of LatLng objects
    ArrayList<LatLng> ptList = new ArrayList<LatLng>();
    int n = 0;
    for (double lng : lngPoints) {
        ptList.add(LatLng.newInstance(latPoints[n], lng));
        n++;
    }
    JsArray<LatLng> bigLatLngArr = ArrayHelper.toJsArray(ptList.toArray(new LatLng[] {})); // convert
                                                                                           // list->array->JsArray

    PolylineOptions opts2 = PolylineOptions.newInstance(); // you can reuse
                                                           // this, if your
                                                           // lines look the
                                                           // same
    opts2.setMap(mapWidget);
    opts2.setPath(bigLatLngArr);
    opts2.setStrokeColor("#FF0000");
    opts2.setStrokeOpacity(1.0);
    opts2.setStrokeWeight(2);

    Polyline bigPolyLine = Polyline.newInstance(opts2);
    mapWidget.setCenter(getPolyLineCenter(bigPolyLine));

}

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

License:Apache License

private void drawMap() {

    /** Create all your styles **/
    // Style the roads
    MapTypeStyle style1 = MapTypeStyle.newInstance();
    style1.setElementType(MapTypeStyleElementType.GEOMETRY);
    style1.setFeatureType(MapTypeStyleFeatureType.ROAD);
    style1.setStylers(new MapTypeStyler[] { MapTypeStyler.newHueStyler("#CC3232"),
            MapTypeStyler.newSaturationStyler(100), MapTypeStyler.newLightnessStyler(-45) });

    // Style the landscape

    MapTypeStyle style2 = MapTypeStyle.newInstance();
    style2.setElementType(MapTypeStyleElementType.GEOMETRY);
    style2.setFeatureType(MapTypeStyleFeatureType.LANDSCAPE);
    style2.setStylers(new MapTypeStyler[] { MapTypeStyler.newHueStyler("#000000"),
            MapTypeStyler.newSaturationStyler(75), MapTypeStyler.newLightnessStyler(-100) });

    // Style the highways
    MapTypeStyle style3 = MapTypeStyle.newInstance();
    style3.setElementType(MapTypeStyleElementType.GEOMETRY);
    style3.setFeatureType(MapTypeStyleFeatureType.ROAD__HIGHWAY);
    style3.setStylers(new MapTypeStyler[] { MapTypeStyler.newHueStyler("#0000FF"),
            MapTypeStyler.newSaturationStyler(5), });

    // consolidate all style information
    MapTypeStyle[] array = { style1, style2, style3 };

    JsArray<MapTypeStyle> styles = ArrayHelper.toJsArray(array); // JS needs
                                                                 // JSArray,
                                                                 // convert
    StyledMapTypeOptions options = StyledMapTypeOptions.newInstance();
    options.setName("My Eyes Hurt!");// the name that appears on map controls
    options.setAlt("Hold onto your retinas!");
    StyledMapType customMapType = StyledMapType.newInstance(styles, options); // apply
                                                                              // to
                                                                              // new
                                                                              // styled
                                                                              // map

    /** Create you map **/
    // basic map options
    LatLng center = LatLng.newInstance(40.6743890, -73.9455);
    MapOptions opts = MapOptions.newInstance();
    opts.setZoom(12);/*from  w ww. j  a  v  a2s  .  c o  m*/
    opts.setCenter(center);
    opts.setMapTypeId(MapTypeId.ROADMAP);

    // NOTE: using the xString methods here on Map options b/c it can handle
    // either MapTypeId|string, but Java cannot.
    // If using custom id's, make sure to use the String methods (i.e. in below
    // block)
    MapTypeControlOptions controlOptions = MapTypeControlOptions.newInstance();
    controlOptions.setMapTypeIds(new String[] { MapTypeId.ROADMAP.toString(), MY_COOL_MAPTYPE });
    opts.setMapTypeControlOptions(controlOptions);
    opts.setMapTypeId(MY_COOL_MAPTYPE);

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

    // finally add the map to the type registry
    mapWidget.setCustomMapType(MY_COOL_MAPTYPE, customMapType);

}

From source file:com.google.gwt.visualization.sample.customvisualization.client.CustomVisualization.java

License:Apache License

public JsArray<Selection> getSelections() {
    if (cell == null) {
        return ArrayHelper.toJsArray(Selection.createCellSelection(0, 0));
    } else {//from   ww w.j  av a 2s .  co m
        // -1 because of the title row
        return ArrayHelper
                .toJsArray(Selection.createCellSelection(cell.getRowIndex() - 1, cell.getCellIndex()));
    }
}