Example usage for com.google.gwt.maps.client.maptypes StyledMapType newInstance

List of usage examples for com.google.gwt.maps.client.maptypes StyledMapType newInstance

Introduction

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

Prototype

public static StyledMapType newInstance(JsArray<MapTypeStyle> styles, StyledMapTypeOptions options) 

Source Link

Document

Creates a styled MapType with the specified options.

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);//www  .j  a  v  a  2s.  co m
    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.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);/*  ww  w.j  ava2s .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);

}