Example usage for com.google.gwt.maps.client.overlays MarkerOptions setMap

List of usage examples for com.google.gwt.maps.client.overlays MarkerOptions setMap

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.overlays MarkerOptions setMap.

Prototype

public final void setMap(StreetViewPanoramaWidget streetViewPanoramaWidget) 

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);//w  ww  .  j  a  va  2s . 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.StreetViewSideBySideMapWidget.java

License:Apache License

private void processPanoSearch(LatLng latlng, final StreetViewPanoramaData data, StreetViewStatus status) {
    if (status != StreetViewStatus.OK) {
        // TODO error
        return;/*from   w w  w .  ja  v a2 s.  c o  m*/
    }

    if (data == null) {
        // TODO error
        return;
    }

    // setup marker for location clicked
    MarkerOptions options = MarkerOptions.newInstance();
    options.setClickable(true);
    options.setPosition(latlng);
    options.setMap(mapWidget);
    options.setTitle(data.getLocation().getDescription());

    Marker marker = Marker.newInstance(options);

    // move back on click
    marker.addClickHandler(new ClickMapHandler() {
        public void onEvent(ClickMapEvent event) {
            moveStreetView(data);
        }
    });

    // move
    moveStreetView(data);
}

From source file:com.google.sampling.experiential.client.ChartPanel.java

License:Open Source License

private Widget renderEventsOnMap() {
    markers.clear();/*from w w w .java2  s .  c  o  m*/
    createMap();
    final LatLngBounds bounds = LatLngBounds.newInstance(google, google);
    for (final EventDAO event : data) {
        String latLon = event.getWhatByKey(input.getName());
        if (latLon == null || latLon.length() == 0) {
            continue;
        }
        String[] splits = latLon.split(",");
        if (splits == null || splits.length != 2) {
            continue;
        }
        try {
            double latitude = Double.parseDouble(splits[0]);
            double longitude = Double.parseDouble(splits[1]);

            MarkerOptions markerOptions = MarkerOptions.newInstance();
            markerOptions.setMap(map);
            markerOptions.setTitle(event.getWhatString());
            LatLng newInstance = LatLng.newInstance(latitude, longitude);
            final Marker marker = Marker.newInstance(markerOptions);
            marker.setPosition(newInstance);
            bounds.union(LatLngBounds.newInstance(marker.getPosition(), marker.getPosition()));
            marker.addClickHandler(new ClickMapHandler() {
                @Override
                public void onEvent(ClickMapEvent mapEvent) {
                    openInfoWindowForMarker(event, marker);
                }
            });
            markers.put(event, marker);
        } catch (NumberFormatException nfe) {
        }
    }

    map.fitBounds(bounds);

    final LatLng oldCenter = map.getCenter();
    final int oldZoom = map.getZoom();
    map.addResizeHandler(new ResizeMapHandler() {

        @Override
        public void onEvent(ResizeMapEvent event) {
            map.setCenter(oldCenter);
            map.setZoom(oldZoom);
            map.fitBounds(bounds);
        }
    });
    Window.addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(ResizeEvent event) {
            MapHandlerRegistration.trigger(map, MapEventType.RESIZE);
            GWT.log("Window has been resized!");
        }
    });
    return map;
}

From source file:net.cbtltd.client.field.MapField.java

/**
 * Adds a marker./*w  ww  . j a va2s  .  com*/
 *
 * @param value the position of the marker
 * @param text the text when clicked
 * @return the marker
 */
public Marker addMarker(LatLng value, String text) {
    if (value == null) {
        return null;
    }
    MarkerOptions markerOptions = MarkerOptions.newInstance();
    markerOptions.setClickable(true);
    markerOptions.setDraggable(isEnabled());
    markerOptions.setTitle(text);
    markerOptions.setPosition(value);
    markerOptions.setMap(map);
    markerOptions.setVisible(visible);
    marker = Marker.newInstance(markerOptions);
    markers.add(marker);

    marker.addClickHandler(new ClickMapHandler() {
        public void onEvent(ClickMapEvent event) {
            setValue(event.getMouseEvent().getLatLng());
        }
    });

    marker.addDragEndHandler(new DragEndMapHandler() {
        public void onEvent(DragEndMapEvent event) {
            setValue(marker.getPosition());
            fireChange(MapField.this);
        }
    });

    marker.addMouseOverHandler(new MouseOverMapHandler() {
        public void onEvent(MouseOverMapEvent event) {
            if (markerFunction != null) {
                markerFunction.onFocus(event);
            }
        }
    });

    marker.addMouseOutMoveHandler(new MouseOutMapHandler() {
        public void onEvent(MouseOutMapEvent event) {
            if (markerFunction != null) {
                markerFunction.onBlur(event);
            }
        }
    });
    return marker;
}