Java Code Examples for com.google.android.gms.maps.model.PolygonOptions#strokeColor()

The following examples show how to use com.google.android.gms.maps.model.PolygonOptions#strokeColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StyleUtils.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Set the style into the polygon options
 *
 * @param polygonOptions polygon options
 * @param style          style row
 * @param density        display density: {@link android.util.DisplayMetrics#density}
 * @return true if style was set into the polygon options
 */
public static boolean setStyle(PolygonOptions polygonOptions, StyleRow style, float density) {

    if (style != null) {

        Color color = style.getColorOrDefault();
        polygonOptions.strokeColor(color.getColorWithAlpha());

        double width = style.getWidthOrDefault();
        polygonOptions.strokeWidth((float) width * density);

        Color fillColor = style.getFillColor();
        if (fillColor != null) {
            polygonOptions.fillColor(fillColor.getColorWithAlpha());
        }
    }

    return style != null;
}
 
Example 2
Source File: Renderer.java    From android-maps-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the inline polygon style by copying over the styles that have been set
 *
 * @param polygonOptions polygon options object to add inline styles to
 * @param inlineStyle    inline styles to apply
 */
private void setInlinePolygonStyle(PolygonOptions polygonOptions, KmlStyle inlineStyle) {
    PolygonOptions inlinePolygonOptions = inlineStyle.getPolygonOptions();
    if (inlineStyle.hasFill() && inlineStyle.isStyleSet("fillColor")) {
        polygonOptions.fillColor(inlinePolygonOptions.getFillColor());
    }
    if (inlineStyle.hasOutline()) {
        if (inlineStyle.isStyleSet("outlineColor")) {
            polygonOptions.strokeColor(inlinePolygonOptions.getStrokeColor());
        }
        if (inlineStyle.isStyleSet("width")) {
            polygonOptions.strokeWidth(inlinePolygonOptions.getStrokeWidth());
        }
    }
    if (inlineStyle.isPolyRandomColorMode()) {
        polygonOptions.fillColor(KmlStyle.computeRandomColor(inlinePolygonOptions.getFillColor()));
    }
}
 
Example 3
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Add a Polygon to the map as markers
 *
 * @param shapeMarkers             google map shape markers
 * @param map                      google map
 * @param polygonOptions           polygon options
 * @param polygonMarkerOptions     polygon marker options
 * @param polygonMarkerHoleOptions polygon marker hole options
 * @param globalPolygonOptions     global polygon options
 * @return polygon markers
 */
public PolygonMarkers addPolygonToMapAsMarkers(
        GoogleMapShapeMarkers shapeMarkers, GoogleMap map,
        PolygonOptions polygonOptions, MarkerOptions polygonMarkerOptions,
        MarkerOptions polygonMarkerHoleOptions,
        PolygonOptions globalPolygonOptions) {

    PolygonMarkers polygonMarkers = new PolygonMarkers(this);

    if (globalPolygonOptions != null) {
        polygonOptions.fillColor(globalPolygonOptions.getFillColor());
        polygonOptions.strokeColor(globalPolygonOptions.getStrokeColor());
        polygonOptions.geodesic(globalPolygonOptions.isGeodesic());
        polygonOptions.visible(globalPolygonOptions.isVisible());
        polygonOptions.zIndex(globalPolygonOptions.getZIndex());
        polygonOptions.strokeWidth(globalPolygonOptions.getStrokeWidth());
    }

    com.google.android.gms.maps.model.Polygon polygon = addPolygonToMap(
            map, polygonOptions);
    polygonMarkers.setPolygon(polygon);

    List<Marker> markers = addPointsToMapAsMarkers(map,
            polygon.getPoints(), polygonMarkerOptions, true);
    polygonMarkers.setMarkers(markers);

    for (List<LatLng> holes : polygon.getHoles()) {
        List<Marker> holeMarkers = addPointsToMapAsMarkers(map, holes,
                polygonMarkerHoleOptions, true);
        PolygonHoleMarkers polygonHoleMarkers = new PolygonHoleMarkers(
                polygonMarkers);
        polygonHoleMarkers.setMarkers(holeMarkers);
        shapeMarkers.add(polygonHoleMarkers);
        polygonMarkers.addHole(polygonHoleMarkers);
    }

    return polygonMarkers;
}
 
Example 4
Source File: MapObservationManager.java    From mage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Set the polygon options
 *
 * @param style          shape style
 * @param polygonOptions polygon options
 * @param visible        visible flag
 */
private void setPolygonOptions(ObservationShapeStyle style, PolygonOptions polygonOptions, boolean visible) {
    polygonOptions.strokeWidth(style.getStrokeWidth());
    polygonOptions.strokeColor(style.getStrokeColor());
    polygonOptions.fillColor(style.getFillColor());
    polygonOptions.visible(visible);
    polygonOptions.geodesic(MapShapeObservation.GEODESIC);
}
 
Example 5
Source File: MapFragment.java    From Android-GoogleMaps-Part1 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void drawPolygon( LatLng startingLocation ) {
    LatLng point2 = new LatLng( startingLocation.latitude + .001, startingLocation.longitude );
    LatLng point3 = new LatLng( startingLocation.latitude, startingLocation.longitude + .001 );

    PolygonOptions options = new PolygonOptions();
    options.add(startingLocation, point2, point3);

    options.fillColor( getResources().getColor( R.color.fill_color ) );
    options.strokeColor( getResources().getColor( R.color.stroke_color ) );
    options.strokeWidth( 10 );

    getMap().addPolygon(options);
}
 
Example 6
Source File: MapFragment.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void drawPolygon( LatLng startingLocation ) {
    LatLng point2 = new LatLng( startingLocation.latitude + .001, startingLocation.longitude );
    LatLng point3 = new LatLng( startingLocation.latitude, startingLocation.longitude + .001 );

    PolygonOptions options = new PolygonOptions();
    options.add(startingLocation, point2, point3);

    options.fillColor( getResources().getColor( R.color.fill_color ) );
    options.strokeColor( getResources().getColor( R.color.stroke_color ) );
    options.strokeWidth( 10 );

    getMap().addPolygon(options);
}
 
Example 7
Source File: GeoJsonPolygonStyle.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source File: KmlStyle.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
    }
    polygonOptions.clickable(originalPolygonOption.isClickable());
    return polygonOptions;
}
 
Example 9
Source File: MainActivity.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
/**
 * 戦場1つを描画する
 */
private void drawField(Field field) {
    // マーカー定義
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.title(field.getName()); // 名前を設定
    markerOptions.snippet(field.getMemo()); // 説明を設定
    markerOptions.position(calcCenter(field.getVertexes())); // マーカーの座標を設定(区画の中心を自動算出)
    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(field.getColorHue())); // 色を設定

    // マップにマーカーを追加
    mGoogleMap.addMarker(markerOptions);

    // 区画を描画
    final LatLng[] vertexes = field.getVertexes();
    if (vertexes != null && vertexes.length > 3) {
        // ポリゴン定義
        PolygonOptions polygonOptions = new PolygonOptions();

        // RGBそれぞれの色を作成
        final int[] colorRgb = field.getColorRgb();
        int colorRed = colorRgb[0];
        int colorGreen = colorRgb[1];
        int colorBlue = colorRgb[2];

        // 区画の輪郭について設定
        polygonOptions.strokeColor(Color.argb(0x255, colorRed, colorGreen, colorBlue));
        polygonOptions.strokeWidth(5);

        // 区画の塗りつぶしについて設定
        polygonOptions.fillColor(Color.argb(0x40, colorRed, colorGreen, colorBlue));

        // 各頂点の座標を設定
        polygonOptions.add(vertexes); // LatLngでもLatLng[]でもOK

        // マップにポリゴンを追加
        mGoogleMap.addPolygon(polygonOptions);
    }
}