Search in sources :

Example 1 with Polyline

use of com.google.android.gms.maps.model.Polyline in project android-maps-utils by googlemaps.

the class Layer method setOnFeatureClickListener.

/**
     * Sets a single click listener for the entire GoogleMap object, that will be called
     * with the corresponding Feature object when an object on the map (Polygon,
     * Marker, Polyline) is clicked.
     *
     * If getFeature() returns null this means that either the object is inside a KMLContainer,
     * or the object is a MultiPolygon, MultiLineString or MultiPoint and must
     * be handled differently.
     *
     * @param listener Listener providing the onFeatureClick method to call.
     */
public void setOnFeatureClickListener(final OnFeatureClickListener listener) {
    GoogleMap map = getMap();
    map.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {

        @Override
        public void onPolygonClick(Polygon polygon) {
            if (getFeature(polygon) != null) {
                listener.onFeatureClick(getFeature(polygon));
            } else if (getContainerFeature(polygon) != null) {
                listener.onFeatureClick(getContainerFeature(polygon));
            } else {
                listener.onFeatureClick(getFeature(multiObjectHandler(polygon)));
            }
        }
    });
    map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {
            if (getFeature(marker) != null) {
                listener.onFeatureClick(getFeature(marker));
            } else if (getContainerFeature(marker) != null) {
                listener.onFeatureClick(getContainerFeature(marker));
            } else {
                listener.onFeatureClick(getFeature(multiObjectHandler(marker)));
            }
            return false;
        }
    });
    map.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {

        @Override
        public void onPolylineClick(Polyline polyline) {
            if (getFeature(polyline) != null) {
                listener.onFeatureClick(getFeature(polyline));
            } else if (getContainerFeature(polyline) != null) {
                listener.onFeatureClick(getContainerFeature(polyline));
            } else {
                listener.onFeatureClick(getFeature(multiObjectHandler(polyline)));
            }
        }
    });
}
Also used : GoogleMap(com.google.android.gms.maps.GoogleMap) Polyline(com.google.android.gms.maps.model.Polyline) Marker(com.google.android.gms.maps.model.Marker) Polygon(com.google.android.gms.maps.model.Polygon)

Example 2 with Polyline

use of com.google.android.gms.maps.model.Polyline in project android-maps-utils by googlemaps.

the class Renderer method addKmlPlacemarkToMap.

/**
     * Adds a single geometry object to the map with its specified style (used for KML)
     *
     * @param geometry defines the type of object to add to the map
     * @param style    defines styling properties to add to the object when added to the map
     * @return the object that was added to the map, this is a Marker, Polyline, Polygon or an array
     * of either objects
     */
protected Object addKmlPlacemarkToMap(KmlPlacemark placemark, Geometry geometry, KmlStyle style, KmlStyle inlineStyle, boolean isVisible) {
    String geometryType = geometry.getGeometryType();
    boolean hasDrawOrder = placemark.hasProperty("drawOrder");
    float drawOrder = 0;
    if (hasDrawOrder) {
        try {
            drawOrder = Float.parseFloat(placemark.getProperty("drawOrder"));
        } catch (NumberFormatException e) {
            hasDrawOrder = false;
        }
    }
    switch(geometryType) {
        case "Point":
            MarkerOptions markerOptions = style.getMarkerOptions();
            if (inlineStyle != null) {
                setInlinePointStyle(markerOptions, inlineStyle, style.getIconUrl());
            } else if (style.getIconUrl() != null) {
                // Use shared style
                addMarkerIcons(style.getIconUrl(), markerOptions);
            }
            Marker marker = addPointToMap(markerOptions, (KmlPoint) geometry);
            marker.setVisible(isVisible);
            setMarkerInfoWindow(style, marker, placemark);
            if (hasDrawOrder) {
                marker.setZIndex(drawOrder);
            }
            return marker;
        case "LineString":
            PolylineOptions polylineOptions = style.getPolylineOptions();
            if (inlineStyle != null) {
                setInlineLineStringStyle(polylineOptions, inlineStyle);
            } else if (style.isLineRandomColorMode()) {
                polylineOptions.color(KmlStyle.computeRandomColor(polylineOptions.getColor()));
            }
            Polyline polyline = addLineStringToMap(polylineOptions, (LineString) geometry);
            polyline.setVisible(isVisible);
            if (hasDrawOrder) {
                polyline.setZIndex(drawOrder);
            }
            return polyline;
        case "Polygon":
            PolygonOptions polygonOptions = style.getPolygonOptions();
            if (inlineStyle != null) {
                setInlinePolygonStyle(polygonOptions, inlineStyle);
            } else if (style.isPolyRandomColorMode()) {
                polygonOptions.fillColor(KmlStyle.computeRandomColor(polygonOptions.getFillColor()));
            }
            Polygon polygon = addPolygonToMap(polygonOptions, (DataPolygon) geometry);
            polygon.setVisible(isVisible);
            if (hasDrawOrder) {
                polygon.setZIndex(drawOrder);
            }
            return polygon;
        case "MultiGeometry":
            return addMultiGeometryToMap(placemark, (KmlMultiGeometry) geometry, style, inlineStyle, isVisible);
    }
    return null;
}
Also used : MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) Polyline(com.google.android.gms.maps.model.Polyline) GeoJsonLineString(com.google.maps.android.data.geojson.GeoJsonLineString) GeoJsonMultiLineString(com.google.maps.android.data.geojson.GeoJsonMultiLineString) Marker(com.google.android.gms.maps.model.Marker) Polygon(com.google.android.gms.maps.model.Polygon) GeoJsonPolygon(com.google.maps.android.data.geojson.GeoJsonPolygon) GeoJsonMultiPolygon(com.google.maps.android.data.geojson.GeoJsonMultiPolygon) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions)

Example 3 with Polyline

use of com.google.android.gms.maps.model.Polyline in project android-maps-utils by googlemaps.

the class Renderer method addLineStringToMap.

/**
     * Adds a LineString to the map as a Polyline
     *
     * @param polylineOptions contains relevant styling properties for the Polyline
     * @param lineString      contains coordinates for the Polyline
     * @return Polyline object created from given LineString
     */
protected Polyline addLineStringToMap(PolylineOptions polylineOptions, LineString lineString) {
    // Add coordinates
    polylineOptions.addAll(lineString.getGeometryObject());
    Polyline addedPolyline = mMap.addPolyline(polylineOptions);
    addedPolyline.setClickable(true);
    return addedPolyline;
}
Also used : Polyline(com.google.android.gms.maps.model.Polyline)

Aggregations

Polyline (com.google.android.gms.maps.model.Polyline)3 Marker (com.google.android.gms.maps.model.Marker)2 Polygon (com.google.android.gms.maps.model.Polygon)2 GoogleMap (com.google.android.gms.maps.GoogleMap)1 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)1 PolygonOptions (com.google.android.gms.maps.model.PolygonOptions)1 PolylineOptions (com.google.android.gms.maps.model.PolylineOptions)1 GeoJsonLineString (com.google.maps.android.data.geojson.GeoJsonLineString)1 GeoJsonMultiLineString (com.google.maps.android.data.geojson.GeoJsonMultiLineString)1 GeoJsonMultiPolygon (com.google.maps.android.data.geojson.GeoJsonMultiPolygon)1 GeoJsonPolygon (com.google.maps.android.data.geojson.GeoJsonPolygon)1