Example usage for com.google.gwt.maps.client.maptypes MapTypeStyleFeatureType ROAD__HIGHWAY

List of usage examples for com.google.gwt.maps.client.maptypes MapTypeStyleFeatureType ROAD__HIGHWAY

Introduction

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

Prototype

MapTypeStyleFeatureType ROAD__HIGHWAY

To view the source code for com.google.gwt.maps.client.maptypes MapTypeStyleFeatureType ROAD__HIGHWAY.

Click Source Link

Document

Apply the rule to highways.

Usage

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);/* w  w  w  . j ava2  s  .co  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);

}