Search in sources :

Example 1 with Polygon

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

the class Renderer method addPolygonToMap.

/**
     * Adds a DataPolygon to the map as a Polygon
     *
     * @param polygonOptions
     * @param polygon      contains coordinates for the Polygon
     * @return Polygon object created from given DataPolygon
     */
protected Polygon addPolygonToMap(PolygonOptions polygonOptions, DataPolygon polygon) {
    // First array of coordinates are the outline
    polygonOptions.addAll(polygon.getOuterBoundaryCoordinates());
    // Following arrays are holes
    List<List<LatLng>> innerBoundaries = polygon.getInnerBoundaryCoordinates();
    for (List<LatLng> innerBoundary : innerBoundaries) {
        polygonOptions.addHole(innerBoundary);
    }
    Polygon addedPolygon = mMap.addPolygon(polygonOptions);
    addedPolygon.setClickable(true);
    return addedPolygon;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) LatLng(com.google.android.gms.maps.model.LatLng) Polygon(com.google.android.gms.maps.model.Polygon) GeoJsonPolygon(com.google.maps.android.data.geojson.GeoJsonPolygon) GeoJsonMultiPolygon(com.google.maps.android.data.geojson.GeoJsonMultiPolygon)

Example 2 with Polygon

use of com.google.android.gms.maps.model.Polygon 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 3 with Polygon

use of com.google.android.gms.maps.model.Polygon 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 4 with Polygon

use of com.google.android.gms.maps.model.Polygon in project AirMapView by airbnb.

the class NativeGoogleMapFragment method addPolygon.

@Override
public <T> void addPolygon(AirMapPolygon<T> polygon) {
    Polygon googlePolygon = googleMap.addPolygon(polygon.getPolygonOptions());
    polygon.setGooglePolygon(googlePolygon);
}
Also used : Polygon(com.google.android.gms.maps.model.Polygon)

Aggregations

Polygon (com.google.android.gms.maps.model.Polygon)4 Marker (com.google.android.gms.maps.model.Marker)2 Polyline (com.google.android.gms.maps.model.Polyline)2 GeoJsonMultiPolygon (com.google.maps.android.data.geojson.GeoJsonMultiPolygon)2 GeoJsonPolygon (com.google.maps.android.data.geojson.GeoJsonPolygon)2 GoogleMap (com.google.android.gms.maps.GoogleMap)1 LatLng (com.google.android.gms.maps.model.LatLng)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 ArrayList (java.util.ArrayList)1 List (java.util.List)1