Example usage for com.google.gwt.maps.client.overlay Marker addMarkerClickHandler

List of usage examples for com.google.gwt.maps.client.overlay Marker addMarkerClickHandler

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.overlay Marker addMarkerClickHandler.

Prototype

public void addMarkerClickHandler(final MarkerClickHandler handler) 

Source Link

Document

This event is fired when the marker icon was clicked.

Usage

From source file:com.google.gwt.gadgets.sample.traveler.client.TravelMap.java

License:Apache License

private Marker createMarker(final Location loc) {
    LatLng latlng = LatLng.newInstance(loc.getLatitude(), loc.getLongitude());
    final Marker marker = new Marker(latlng);
    marker.addMarkerClickHandler(new MarkerClickHandler() {
        public void onClick(MarkerClickEvent event) {
            final InfoWindow info = map.getInfoWindow();
            info.open(marker, newLocationDescription(loc, info, marker));
        }//from  w w w.  j ava  2s . com
    });
    return marker;
}

From source file:com.google.gwt.maps.sample.hellomaps.client.IconClassDemo.java

License:Apache License

/**
 * Creates a marker whose info window displays the letter corresponding to the
 * given index./*from   w w  w  .ja v a  2s.c  o  m*/
 */
private Marker createMarker(LatLng point, int index) {
    // Create a lettered icon for this point using our icon class
    final char letter = (char) ('A' + index);
    Icon icon = Icon.newInstance(baseIcon);
    icon.setImageURL("http://www.google.com/mapfiles/marker" + letter + ".png");
    MarkerOptions options = MarkerOptions.newInstance();
    options.setIcon(icon);
    final Marker marker = new Marker(point, options);

    marker.addMarkerClickHandler(new MarkerClickHandler() {

        public void onClick(MarkerClickEvent event) {
            InfoWindow info = map.getInfoWindow();
            info.open(event.getSender(), new InfoWindowContent("Marker <b>" + letter + "</b>"));
        }

    });

    return marker;
}

From source file:com.google.gwt.maps.sample.hellomaps.client.MarkerInfoWindowDemo.java

License:Apache License

private Marker createMarker(LatLng point, final int number) {
    final Marker marker = new Marker(point);

    marker.addMarkerClickHandler(new MarkerClickHandler() {
        public void onClick(MarkerClickEvent event) {
            InfoWindow info = map.getInfoWindow();
            info.open(marker, new InfoWindowContent("Marker #<b>" + number + "</b>"));
        }/*from www  . j  a  v  a 2s  .  c  om*/
    });

    return marker;
}

From source file:com.google.gwt.maps.sample.hellomaps.client.ReverseGeocoderDemo.java

License:Apache License

public ReverseGeocoderDemo() {
    VerticalPanel outer = new VerticalPanel();
    map = new MapWidget(LatLng.newInstance(0, 0), 1);
    outer.add(map);//from w  ww . j  a  v  a  2 s.  c  o  m
    map.setSize("500px", "300px");
    initWidget(outer);
    // Workaround for bug with click handler & setUItoDefaults() - see issue 260
    MapUIOptions opts = map.getDefaultUI();
    opts.setDoubleClick(false);
    map.setUI(opts);

    map.addMapClickHandler(new MapClickHandler() {

        public void onClick(final MapClickEvent event) {
            // Do not mis-interpret clicks on the info window and marker as
            // map click events to be reverse geocoded.
            if (event.getOverlay() != null) {
                return;
            }
            final Marker marker = new Marker(event.getLatLng());
            final VerticalPanel panel = new VerticalPanel();
            final InfoWindowContent content = new InfoWindowContent(panel);
            panel.add(new Label("LatLng: " + event.getLatLng().toString()));

            // Do a reverse geocode of this position
            geocoder.getLocations(event.getLatLng(), new LocationCallback() {

                public void onFailure(int statusCode) {
                    Window.alert("Failed to geocode position " + event.getLatLng() + ". Status: " + statusCode
                            + " " + StatusCodes.getName(statusCode));
                }

                public void onSuccess(JsArray<Placemark> locations) {
                    for (int i = 0; i < locations.length(); ++i) {
                        Placemark location = locations.get(i);
                        StringBuilder value = new StringBuilder();
                        if (location.getAddress() != null) {
                            value.append(location.getAddress());
                        } else {
                            if (location.getCity() != null) {
                                value.append(location.getCity());
                            }
                            if (location.getAdministrativeArea() != null) {
                                value.append(location.getAdministrativeArea() + ", ");
                            }
                            if (location.getCountry() != null) {
                                value.append(location.getCountry());
                            }
                        }
                        int ordinal = (i + 1);
                        panel.add(new Label("  " + ordinal + ") " + value.toString()));
                    }
                    map.addOverlay(marker);
                    map.getInfoWindow().open(marker, content);
                }
            });
            marker.addMarkerClickHandler(new MarkerClickHandler() {

                public void onClick(MarkerClickEvent markerClickEvent) {
                    if (!map.getInfoWindow().isVisible()) {
                        map.getInfoWindow().open(marker, content);
                    }
                }
            });
        }

    });
    geocoder = new Geocoder();
}

From source file:com.google.gwt.sample.vanfood.client.VanFood.java

private Marker createMarker(Vendor v) {
    double lat = v.getLat();
    double lon = v.getLon();
    final String name = v.getName();
    final String address = v.getAddress();
    LatLng point = LatLng.newInstance(lat, lon);
    final Marker marker = new Marker(point);

    marker.addMarkerClickHandler(new MarkerClickHandler() {
        public void onClick(MarkerClickEvent event) {
            InfoWindow info = map.getInfoWindow();
            info.open(marker, new InfoWindowContent("<b>" + name + "<br>" + address + "</b>"));
        }//  w  ww.  j  a v a2  s. c  o m
    });
    System.out.println(v.toString());
    return marker;
}

From source file:com.google.livingstories.client.lsp.views.contentitems.LocationView.java

License:Apache License

private MapWidget createMap() {
    final String description = location.getDescription();
    LatLng latLng = LatLng.newInstance(location.getLatitude(), location.getLongitude());

    final MapWidget map = new MapWidget(latLng, MAPS_ZOOM);
    map.setSize(MAPS_WIDTH + "px", MAPS_HEIGHT + "px");
    map.addControl(new SmallMapControl());
    map.setDoubleClickZoom(true);//  w  ww.j  ava2  s . co  m
    map.setDraggable(true);
    map.setScrollWheelZoomEnabled(true);
    if (!description.isEmpty()) {
        final Marker marker = new Marker(latLng);
        map.addOverlay(marker);
        final InfoWindowContent iwc = new InfoWindowContent(description);
        marker.addMarkerClickHandler(new MarkerClickHandler() {
            @Override
            public void onClick(MarkerClickEvent event) {
                InfoWindow infoWindow = map.getInfoWindow();
                if (infoWindow.isVisible()) {
                    infoWindow.close();
                } else {
                    infoWindow.open(marker, iwc);
                }
            }
        });
        map.setTitle(description);
    }
    return map;
}

From source file:es.upm.fi.dia.oeg.map4rdf.client.widget.mapcontrol.GeoResourcesMapControl.java

License:Open Source License

public void drawGeometry(Geometry geometry, final ClickHandler clickHandler) {
    if (geometry == null) {
        return;/*www.j a va 2s  . co  m*/
    }
    switch (geometry.getType()) {
    case POINT:
        final Marker marker = new Marker(GoogleMapsAdapters.getLatLng((Point) geometry));
        marker.addMarkerClickHandler(new MarkerClickHandler() {
            @Override
            public void onClick(MarkerClickEvent event) {
                latLong = marker.getLatLng();
                clickHandler.onClick(null); // TODO: null???
            }
        });
        addOverlay(marker);
        break;
    case POLYLINE:// 84002E rojo FF5B00 naranja
        // Polyline line = new
        // Polyline(GoogleMapsAdapters.getLatLngs(((PolyLine)
        // geometry).getPoints()), "#0000ff", 2);
        // colores:
        // Verde-viajero:#088A08
        // azul marino oscuro: #08088A
        // rojo oscuro: #B40404
        // morado: #8A0886
        Polyline line = new Polyline(GoogleMapsAdapters.getLatLngs(((PolyLine) geometry).getPoints()),
                "#088A08", 4, 0.9);
        line.addPolylineClickHandler(new PolylineClickHandler() {
            @Override
            public void onClick(PolylineClickEvent event) {
                latLong = event.getLatLng();
                // solo para webNmasuno resources!
                try {
                    // enviamos la polyline para poder cambiar el color.
                    ((WebNMasUnoClickHandler) clickHandler).onClick(null, event.getSender());
                } catch (Exception e) {
                    // class cast exception: no hacemos nada.
                    // significa que no es un webnmasuno resource.
                }
                clickHandler.onClick(null); // TODO: null???
            }
        });
        // Anado estos dos eventos vacios para que cambie el raton
        // automaticamente. Y si en el futuro se quiere hacer algo
        line.addPolylineMouseOverHandler(new PolylineMouseOverHandler() {
            @Override
            public void onMouseOver(PolylineMouseOverEvent event) {

            }
        });
        line.addPolylineMouseOutHandler(new PolylineMouseOutHandler() {
            @Override
            public void onMouseOut(PolylineMouseOutEvent event) {

            }
        });
        getMap().setCenter(line.getBounds().getCenter(), getMap().getBoundsZoomLevel(line.getBounds()));// line.getBounds().toSpan()
        addOverlay(line);
        break;
    case POLYGON:
        Polygon polygon = new Polygon(GoogleMapsAdapters
                .getLatLngs(((es.upm.fi.dia.oeg.map4rdf.share.Polygon) geometry).getPoints()));
        polygon.addPolygonClickHandler(new PolygonClickHandler() {
            @Override
            public void onClick(PolygonClickEvent event) {
                latLong = event.getLatLng();
                clickHandler.onClick(null); // TODO: null???
            }
        });
        addOverlay(polygon);
        break;
    }

}

From source file:org.maps.client.TRIFacilitiesLayer.java

License:Apache License

@Override
protected void refreshMarkers(LatLngBounds bounds, final IRefreshMarkersCallback callback) {

    if (getMap().getZoomLevel() < getStartZoomLevel()) {
        List<Marker> newMarkers = new ArrayList<Marker>();
        callback.onRefresh(newMarkers);/* w ww  . jav a 2s . c  o m*/
        return;
    }
    setCurrentZoomLevel(getMap().getZoomLevel());

    AsyncCallback<List<ITRIFacility>> serviceCallback = new AsyncCallback<List<ITRIFacility>>() {
        public void onFailure(Throwable caught) {
            callback.onError(caught);
        }

        public void onSuccess(List<ITRIFacility> result) {
            for (ITRIFacility facility : result) {
                MarkerOptions options = MarkerOptions.newInstance();
                options.setTitle(facility.getFacilityName());
                if (facility.getNumberOfFacilities() > 1) {
                    String url = "images/cluster.png";
                    Icon icon = Icon.newInstance(url);
                    options.setIcon(icon);
                }
                options.setDraggable(false);
                LatLng location = LatLng.newInstance(facility.getLatitude(), facility.getLongitude());
                Marker marker = new Marker(location, options);
                if (facility.getNumberOfFacilities() > 1) {
                    marker.addMarkerClickHandler(getClusterClickHandler());
                } else {
                    marker.addMarkerClickHandler(getFacilityClickHandler());
                }
                register(marker, facility);
            }
            callback.onRefresh(getMarkers());
        }
    };

    double swLat = bounds.getSouthWest().getLatitude();
    double swLng = bounds.getSouthWest().getLongitude();
    double neLat = bounds.getNorthEast().getLatitude();
    double neLng = bounds.getNorthEast().getLongitude();
    service.get(swLat, swLng, neLat, neLng, serviceCallback);

}

From source file:org.onebusaway.webapp.gwt.oba_application.control.MinTransitTimeResultHandler.java

License:Apache License

private void showSearchGrid(MinTransitTimeResult result) {
    for (final CoordinateBounds lb : result.getSearchGrid()) {
        LatLng a = LatLng.newInstance(lb.getMinLat(), lb.getMinLon());
        LatLng b = LatLng.newInstance(lb.getMaxLat(), lb.getMinLon());
        LatLng c = LatLng.newInstance(lb.getMaxLat(), lb.getMaxLon());
        LatLng d = LatLng.newInstance(lb.getMinLat(), lb.getMaxLon());
        LatLng[] points = { a, b, c, d, a };
        Polyline line = new Polyline(points);
        _mapManager.addOverlay(line, 10, 20);

        Marker marker = new Marker(b);
        marker.addMarkerClickHandler(new MarkerClickHandler() {
            public void onClick(MarkerClickEvent event) {
                System.out.println(lb.getMinLat() + " " + lb.getMinLon());
                System.out.println(lb.getMaxLat() + " " + lb.getMaxLon());
            }//from   w ww  .  ja  v  a2s  . com
        });

        _mapManager.addOverlay(marker, 10, 20);

    }
}

From source file:org.onebusaway.webapp.gwt.oba_application.view.ResultsTablePresenter.java

License:Apache License

private void refresh() {

    clear();/*ww w .  j  a va2s .c o m*/

    if (_minimized) {

        DivPanel panel = new DivPanel();
        panel.addStyleName(_css.ResultsTableWidgetMinimized());
        _tablePanel.add(panel);

        Anchor showAllEntries = new Anchor("Show all results...");
        showAllEntries.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent arg0) {
                _control.clearActiveSearchResult();
            }
        });
        panel.add(showAllEntries);

        constructAttributionPanel();

    } else {

        _tablePanel.add(_filterWidget);

        List<TimedLocalSearchResult> entries = _model.getActiveEntries();

        Grid grid = new Grid(entries.size() + 1, 4);
        grid.addStyleName(_css.ResultsTableWidgetResultsTable());
        grid.setText(0, 0, "");
        grid.setWidget(0, 1, getTableHeaderWidget("Name", EResultsSort.NAME));
        grid.setWidget(0, 2, getTableHeaderWidget("Rating", EResultsSort.RATING));
        grid.setWidget(0, 3, getTableHeaderWidget("Distance", EResultsSort.DISTANCE));

        grid.getRowFormatter().addStyleName(0, "ResultsTableWidget-ResultsTable-HeaderRow");

        grid.getCellFormatter().addStyleName(0, 1, "ResultsTableWidget-ResultsTable-HeaderRow-Name");
        grid.getCellFormatter().addStyleName(0, 2, "ResultsTableWidget-ResultsTable-HeaderRow-Rating");
        grid.getCellFormatter().addStyleName(0, 3, "ResultsTableWidget-ResultsTable-HeaderRow-Distance");

        int index = 0;

        LatLngBounds bounds = LatLngBounds.newInstance();

        for (TimedLocalSearchResult tlsr : entries) {

            LocalSearchResult entry = tlsr.getLocalSearchResult();

            int tableRow = index + 1;
            EntryClickHandler handler = new EntryClickHandler(tlsr);

            String labelPre = index < ROW_LABELS.length() ? (ROW_LABELS.charAt(index) + "") : "";
            grid.setWidget(tableRow, 0, new SpanWidget(labelPre));
            grid.getCellFormatter().addStyleName(tableRow, 0, "ResultsTableWidget-ResultsTable-LabelColumn");

            Anchor name = new Anchor(entry.getName());
            name.addClickHandler(handler);
            grid.setWidget(tableRow, 1, name);
            grid.getCellFormatter().addStyleName(tableRow, 1, "ResultsTableWidget-ResultsTable-NameColumn");

            if (entry.getRatingUrlSmall() != null) {
                Image image = new Image(entry.getRatingUrlSmall());
                grid.setWidget(tableRow, 2, image);
            } else {
                String rating = entry.getRating() + "/" + entry.getMaxRating();
                grid.setText(tableRow, 2, rating);
            }
            grid.getCellFormatter().addStyleName(tableRow, 2, "ResultsTableWidget-ResultsTable-RatingColumn");

            int minutes = tlsr.getTime() / 60;
            String minLabel = minutes + " " + (minutes == 1 ? " min" : " mins");
            grid.setText(tableRow, 3, minLabel);
            grid.getCellFormatter().addStyleName(tableRow, 3, "ResultsTableWidget-ResultsTable-TimeColumn");

            grid.getRowFormatter().addStyleName(tableRow, "ResultsTableWidget-ResultsTable-ResultRow");

            Marker marker = getMarker(index, entry);
            marker.addMarkerClickHandler(handler);
            _mapOverlayManager.addOverlay(marker, 10, 20);
            _overlays.add(marker);

            index++;

            bounds.extend(marker.getLatLng());
        }

        if (!bounds.isEmpty()) {
            MapWidget map = _mapOverlayManager.getMapWidget();
            LatLngBounds currentView = map.getBounds();
            if (!currentView.containsBounds(bounds)) {
                _mapOverlayManager.setCenterAndZoom(bounds);
            }
        }

        _tablePanel.add(grid);

        constructItemNavigationPanel(entries);
        constructAttributionPanel();
    }
}