Search in sources :

Example 11 with PolygonOptions

use of com.google.android.gms.maps.model.PolygonOptions in project android-samples by googlemaps.

the class PolygonDemoActivity method onMapReady.

@Override
public void onMapReady(GoogleMap map) {
    // Override the default content description on the view, for accessibility mode.
    map.setContentDescription(getString(R.string.polygon_demo_description));
    int fillColorArgb = Color.HSVToColor(mFillAlphaBar.getProgress(), new float[] { mFillHueBar.getProgress(), 1, 1 });
    int strokeColorArgb = Color.HSVToColor(mStrokeAlphaBar.getProgress(), new float[] { mStrokeHueBar.getProgress(), 1, 1 });
    // Create a rectangle with two rectangular holes.
    mMutablePolygon = map.addPolygon(new PolygonOptions().addAll(createRectangle(CENTER, 5, 5)).addHole(createRectangle(new LatLng(-22, 128), 1, 1)).addHole(createRectangle(new LatLng(-18, 133), 0.5, 1.5)).fillColor(fillColorArgb).strokeColor(strokeColorArgb).strokeWidth(mStrokeWidthBar.getProgress()).clickable(mClickabilityCheckbox.isChecked()));
    mFillHueBar.setOnSeekBarChangeListener(this);
    mFillAlphaBar.setOnSeekBarChangeListener(this);
    mStrokeWidthBar.setOnSeekBarChangeListener(this);
    mStrokeHueBar.setOnSeekBarChangeListener(this);
    mStrokeAlphaBar.setOnSeekBarChangeListener(this);
    mStrokeJointTypeSpinner.setOnItemSelectedListener(this);
    mStrokePatternSpinner.setOnItemSelectedListener(this);
    mMutablePolygon.setStrokeJointType(getSelectedJointType(mStrokeJointTypeSpinner.getSelectedItemPosition()));
    mMutablePolygon.setStrokePattern(getSelectedPattern(mStrokePatternSpinner.getSelectedItemPosition()));
    // Move the map so that it is centered on the mutable polygon.
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(CENTER, 4));
    // Add a listener for polygon clicks that changes the clicked polygon's stroke color.
    map.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {

        @Override
        public void onPolygonClick(Polygon polygon) {
            // Flip the red, green and blue components of the polygon's stroke color.
            polygon.setStrokeColor(polygon.getStrokeColor() ^ 0x00ffffff);
        }
    });
}
Also used : PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) GoogleMap(com.google.android.gms.maps.GoogleMap) LatLng(com.google.android.gms.maps.model.LatLng) Polygon(com.google.android.gms.maps.model.Polygon)

Example 12 with PolygonOptions

use of com.google.android.gms.maps.model.PolygonOptions in project android-samples by googlemaps.

the class TagsDemoActivity method addObjectsToMap.

private void addObjectsToMap() {
    // A circle centered on Adelaide.
    mAdelaideCircle = mMap.addCircle(new CircleOptions().center(ADELAIDE).radius(500000).fillColor(Color.argb(150, 66, 173, 244)).strokeColor(Color.rgb(66, 173, 244)).clickable(true));
    mAdelaideCircle.setTag(new CustomTag("Adelaide circle"));
    // A ground overlay at Sydney.
    mSydneyGroundOverlay = mMap.addGroundOverlay(new GroundOverlayOptions().image(BitmapDescriptorFactory.fromResource(R.drawable.harbour_bridge)).position(SYDNEY, 700000).clickable(true));
    mSydneyGroundOverlay.setTag(new CustomTag("Sydney ground overlay"));
    // A marker at Hobart.
    mHobartMarker = mMap.addMarker(new MarkerOptions().position(HOBART));
    mHobartMarker.setTag(new CustomTag("Hobart marker"));
    // A polygon centered at Darwin.
    mDarwinPolygon = mMap.addPolygon(new PolygonOptions().add(new LatLng(DARWIN.latitude + 3, DARWIN.longitude - 3), new LatLng(DARWIN.latitude + 3, DARWIN.longitude + 3), new LatLng(DARWIN.latitude - 3, DARWIN.longitude + 3), new LatLng(DARWIN.latitude - 3, DARWIN.longitude - 3)).fillColor(Color.argb(150, 34, 173, 24)).strokeColor(Color.rgb(34, 173, 24)).clickable(true));
    mDarwinPolygon.setTag(new CustomTag("Darwin polygon"));
    // A polyline from Perth to Brisbane.
    mPolyline = mMap.addPolyline(new PolylineOptions().add(PERTH, BRISBANE).color(Color.rgb(103, 24, 173)).width(30).clickable(true));
    mPolyline.setTag(new CustomTag("Perth to Brisbane polyline"));
}
Also used : MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) CircleOptions(com.google.android.gms.maps.model.CircleOptions) GroundOverlayOptions(com.google.android.gms.maps.model.GroundOverlayOptions) PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) LatLng(com.google.android.gms.maps.model.LatLng) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions)

Example 13 with PolygonOptions

use of com.google.android.gms.maps.model.PolygonOptions 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);
            } else if (style.getIconUrl() != null) {
                // Use shared style
                addMarkerIcons(style.getIconUrl(), style.getIconScale(), 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) GeoJsonMultiPolygon(com.google.maps.android.data.geojson.GeoJsonMultiPolygon) Polygon(com.google.android.gms.maps.model.Polygon) GeoJsonPolygon(com.google.maps.android.data.geojson.GeoJsonPolygon) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions)

Example 14 with PolygonOptions

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

the class GeoJsonPolygonStyle method toPolygonOptions.

/**
 * Gets a new PolygonOptions object containing styles for the GeoJsonPolygon
 *
 * @return new PolygonOptions object
 */
public PolygonOptions toPolygonOptions() {
    PolygonOptions polygonOptions = new PolygonOptions();
    polygonOptions.fillColor(mPolygonOptions.getFillColor());
    polygonOptions.geodesic(mPolygonOptions.isGeodesic());
    polygonOptions.strokeColor(mPolygonOptions.getStrokeColor());
    polygonOptions.strokeJointType(mPolygonOptions.getStrokeJointType());
    polygonOptions.strokePattern(mPolygonOptions.getStrokePattern());
    polygonOptions.strokeWidth(mPolygonOptions.getStrokeWidth());
    polygonOptions.visible(mPolygonOptions.isVisible());
    polygonOptions.zIndex(mPolygonOptions.getZIndex());
    polygonOptions.clickable(mPolygonOptions.isClickable());
    return polygonOptions;
}
Also used : PolygonOptions(com.google.android.gms.maps.model.PolygonOptions)

Example 15 with PolygonOptions

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

the class KmlStyle method createPolygonOptions.

/**
 * Creates a new PolygonOption from given properties of an existing PolygonOption
 *
 * @param originalPolygonOption An existing PolygonOption instance
 * @param isFill                Whether the fill for a polygon is set
 * @param isOutline             Whether the outline for a polygon is set
 * @return A new PolygonOption
 */
private static PolygonOptions createPolygonOptions(PolygonOptions originalPolygonOption, boolean isFill, boolean isOutline) {
    float originalWidth = 0.0f;
    PolygonOptions polygonOptions = new PolygonOptions();
    if (isFill) {
        polygonOptions.fillColor(originalPolygonOption.getFillColor());
    }
    if (isOutline) {
        polygonOptions.strokeColor(originalPolygonOption.getStrokeColor());
        originalWidth = originalPolygonOption.getStrokeWidth();
    }
    polygonOptions.strokeWidth(originalWidth);
    polygonOptions.clickable(originalPolygonOption.isClickable());
    return polygonOptions;
}
Also used : PolygonOptions(com.google.android.gms.maps.model.PolygonOptions)

Aggregations

PolygonOptions (com.google.android.gms.maps.model.PolygonOptions)16 LatLng (com.google.android.gms.maps.model.LatLng)8 PolylineOptions (com.google.android.gms.maps.model.PolylineOptions)6 Polygon (com.google.android.gms.maps.model.Polygon)4 GoogleMap (com.google.android.gms.maps.GoogleMap)3 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)3 CameraUpdate (com.google.android.gms.maps.CameraUpdate)2 Polyline (com.google.android.gms.maps.model.Polyline)2 Intent (android.content.Intent)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 BitmapDescriptor (com.google.android.gms.maps.model.BitmapDescriptor)1 CircleOptions (com.google.android.gms.maps.model.CircleOptions)1 GroundOverlayOptions (com.google.android.gms.maps.model.GroundOverlayOptions)1 Marker (com.google.android.gms.maps.model.Marker)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 ArrayList (java.util.ArrayList)1