Search in sources :

Example 1 with PolygonOptions

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

the class PolySimplifyDemoActivity method startDemo.

@Override
protected void startDemo() {
    GoogleMap mMap = getMap();
    // Original line
    List<LatLng> line = PolyUtil.decode(LINE);
    mMap.addPolyline(new PolylineOptions().addAll(line).color(Color.BLACK));
    getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(28.05870, -82.4090), 15));
    List<LatLng> simplifiedLine;
    /**
         * Simplified lines - increasing the tolerance will result in fewer points in the simplified
         * line
         */
    // meters
    double tolerance = 5;
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.RED - ALPHA_ADJUSTMENT));
    // meters
    tolerance = 20;
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.GREEN - ALPHA_ADJUSTMENT));
    // meters
    tolerance = 50;
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.MAGENTA - ALPHA_ADJUSTMENT));
    // meters
    tolerance = 500;
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.YELLOW - ALPHA_ADJUSTMENT));
    // meters
    tolerance = 1000;
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.BLUE - ALPHA_ADJUSTMENT));
    // Triangle polygon - the polygon should be closed
    ArrayList<LatLng> triangle = new ArrayList<>();
    // Should match last point
    triangle.add(new LatLng(28.06025, -82.41030));
    triangle.add(new LatLng(28.06129, -82.40945));
    triangle.add(new LatLng(28.06206, -82.40917));
    triangle.add(new LatLng(28.06125, -82.40850));
    triangle.add(new LatLng(28.06035, -82.40834));
    triangle.add(new LatLng(28.06038, -82.40924));
    // Should match first point
    triangle.add(new LatLng(28.06025, -82.41030));
    mMap.addPolygon(new PolygonOptions().addAll(triangle).fillColor(Color.BLUE - ALPHA_ADJUSTMENT).strokeColor(Color.BLUE).strokeWidth(5));
    // Simplified triangle polygon
    // meters
    tolerance = 88;
    List simplifiedTriangle = PolyUtil.simplify(triangle, tolerance);
    mMap.addPolygon(new PolygonOptions().addAll(simplifiedTriangle).fillColor(Color.YELLOW - ALPHA_ADJUSTMENT).strokeColor(Color.YELLOW).strokeWidth(5));
    // Oval polygon - the polygon should be closed
    List<LatLng> oval = PolyUtil.decode(OVAL_POLYGON);
    mMap.addPolygon(new PolygonOptions().addAll(oval).fillColor(Color.BLUE - ALPHA_ADJUSTMENT).strokeColor(Color.BLUE).strokeWidth(5));
    // Simplified oval polygon
    // meters
    tolerance = 10;
    List simplifiedOval = PolyUtil.simplify(oval, tolerance);
    mMap.addPolygon(new PolygonOptions().addAll(simplifiedOval).fillColor(Color.YELLOW - ALPHA_ADJUSTMENT).strokeColor(Color.YELLOW).strokeWidth(5));
}
Also used : GoogleMap(com.google.android.gms.maps.GoogleMap) PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LatLng(com.google.android.gms.maps.model.LatLng) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions)

Example 2 with PolygonOptions

use of com.google.android.gms.maps.model.PolygonOptions in project wigle-wifi-wardriving by wiglenet.

the class KmlRenderer method addPolygonToMap.

/**
 * Adds a KML Polygon to the map as a Polygon by combining the styling and coordinates
 *
 * @param polygon contains coordinates for the Polygon
 * @param style   contains relevant styling properties for the Polygon
 * @return Polygon object
 */
private Polygon addPolygonToMap(KmlPolygon polygon, KmlStyle style, KmlStyle inlineStyle) {
    PolygonOptions polygonOptions = style.getPolygonOptions();
    polygonOptions.addAll(polygon.getOuterBoundaryCoordinates());
    for (ArrayList<LatLng> innerBoundary : polygon.getInnerBoundaryCoordinates()) {
        polygonOptions.addHole(innerBoundary);
    }
    if (inlineStyle != null) {
        setInlinePolygonStyle(polygonOptions, inlineStyle);
    } else if (style.isPolyRandomColorMode()) {
        polygonOptions.fillColor(KmlStyle.computeRandomColor(polygonOptions.getFillColor()));
    }
    return mMap.addPolygon(polygonOptions);
}
Also used : PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) LatLng(com.google.android.gms.maps.model.LatLng)

Example 3 with PolygonOptions

use of com.google.android.gms.maps.model.PolygonOptions in project wigle-wifi-wardriving by wiglenet.

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) {
    PolygonOptions polygonOptions = new PolygonOptions();
    if (isFill) {
        polygonOptions.fillColor(originalPolygonOption.getFillColor());
    }
    if (isOutline) {
        polygonOptions.strokeColor(originalPolygonOption.getStrokeColor());
        polygonOptions.strokeWidth(originalPolygonOption.getStrokeWidth());
    }
    return polygonOptions;
}
Also used : PolygonOptions(com.google.android.gms.maps.model.PolygonOptions)

Example 4 with PolygonOptions

use of com.google.android.gms.maps.model.PolygonOptions in project wigle-wifi-wardriving by wiglenet.

the class GeoJsonRenderer method addPolygonToMap.

/**
 * Adds a GeoJsonPolygon to the map as a Polygon
 *
 * @param polygonStyle contains relevant styling properties for the Polygon
 * @param polygon      contains coordinates for the Polygon
 * @return Polygon object created from given GeoJsonPolygon
 */
private Polygon addPolygonToMap(GeoJsonPolygonStyle polygonStyle, GeoJsonPolygon polygon) {
    PolygonOptions polygonOptions = polygonStyle.toPolygonOptions();
    // First array of coordinates are the outline
    polygonOptions.addAll(polygon.getCoordinates().get(POLYGON_OUTER_COORDINATE_INDEX));
    // Following arrays are holes
    for (int i = POLYGON_INNER_COORDINATE_INDEX; i < polygon.getCoordinates().size(); i++) {
        polygonOptions.addHole(polygon.getCoordinates().get(i));
    }
    Polygon addedPolygon = mMap.addPolygon(polygonOptions);
    addedPolygon.setClickable(true);
    return addedPolygon;
}
Also used : PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) Polygon(com.google.android.gms.maps.model.Polygon)

Example 5 with PolygonOptions

use of com.google.android.gms.maps.model.PolygonOptions in project iNaturalistAndroid by inaturalist.

the class ActivityHelper method addMapPosition.

public void addMapPosition(final GoogleMap map, Observation observation, BetterJSONObject observationJson, boolean markerOnly, boolean updateCamera) {
    Double lat, lon;
    lat = observation.private_latitude == null ? observation.latitude : observation.private_latitude;
    lon = observation.private_longitude == null ? observation.longitude : observation.private_longitude;
    if (lat == null || lon == null) {
        // can't do anything
        return;
    }
    LatLng latlng = new LatLng(lat, lon);
    BitmapDescriptor obsIcon = TaxonUtils.observationMarkerIcon(observation.iconic_taxon_name);
    String currentUser = mApp.currentUserLogin();
    CameraUpdate cameraUpdate = null;
    int obsColor = observationColor(observation);
    Integer publicAcc = null;
    publicAcc = observationJson != null ? observationJson.getInteger("public_positional_accuracy") : null;
    // Add a single marker
    MarkerOptions opts = new MarkerOptions().position(latlng).icon(obsIcon);
    map.addMarker(opts);
    if (((observation.geoprivacy != null) && (observation.geoprivacy.equals("private"))) || (publicAcc == null) || (markerOnly)) {
        // No need to add anything other than the above marker
        cameraUpdate = CameraUpdateFactory.newLatLngZoom(latlng, 15);
    } else if ((currentUser != null) && (observation.user_login.equals(currentUser)) && (observation.positional_accuracy != null)) {
        // Show circle of private positional accuracy
        cameraUpdate = addCircle(map, latlng, observation.positional_accuracy, observation, updateCamera);
    } else {
        if ((observation.positional_accuracy != null) && (publicAcc != null) && (observation.positional_accuracy.equals(publicAcc))) {
            // Show circle of public positional accuracy
            cameraUpdate = addCircle(map, latlng, publicAcc, observation, updateCamera);
        } else {
            // Show uncertainty cell
            Double cellSize = 0.2;
            Double[] coords = new Double[] { lat, lon };
            Double[] ll = new Double[] { coords[0] - (coords[0] % cellSize), coords[1] - (coords[1] % cellSize) };
            Double[] uu = new Double[] { ll[0], ll[1] };
            for (int i = 0; i < coords.length; i++) {
                if (coords[i] < uu[i]) {
                    uu[i] -= cellSize;
                } else {
                    uu[i] += cellSize;
                }
            }
            LatLng[] rectPoints = new LatLng[] { new LatLng(Math.min(uu[0], ll[0]), Math.min(uu[1], ll[1])), new LatLng(Math.max(uu[0], ll[0]), Math.min(uu[1], ll[1])), new LatLng(Math.max(uu[0], ll[0]), Math.max(uu[1], ll[1])), new LatLng(Math.min(uu[0], ll[0]), Math.max(uu[1], ll[1])), new LatLng(Math.min(uu[0], ll[0]), Math.min(uu[1], ll[1])) };
            PolygonOptions polygonOpts = new PolygonOptions().add(rectPoints[0]).add(rectPoints[1]).add(rectPoints[2]).add(rectPoints[3]).add(rectPoints[4]).fillColor(// Add 50% opacity
            0x80FFFFFF & obsColor).strokeColor(obsColor);
            map.addPolygon(polygonOpts);
            if (updateCamera) {
                cameraUpdate = CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder().include(rectPoints[0]).include(rectPoints[1]).include(rectPoints[2]).include(rectPoints[3]).include(rectPoints[4]).build(), 10);
            }
        }
    }
    final CameraUpdate finalCameraUpdate = cameraUpdate;
    map.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {

        @Override
        public void onMapLoaded() {
            try {
                if (finalCameraUpdate != null)
                    map.moveCamera(finalCameraUpdate);
            } catch (IllegalStateException exc) {
                // Handles weird exception is raised ("View size is too small after padding is applied")
                exc.printStackTrace();
            }
        }
    });
}
Also used : MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) BitmapDescriptor(com.google.android.gms.maps.model.BitmapDescriptor) GoogleMap(com.google.android.gms.maps.GoogleMap) LatLng(com.google.android.gms.maps.model.LatLng) CameraUpdate(com.google.android.gms.maps.CameraUpdate)

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