Java Code Examples for com.google.android.gms.maps.model.BitmapDescriptorFactory#fromBitmap()

The following examples show how to use com.google.android.gms.maps.model.BitmapDescriptorFactory#fromBitmap() . 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: Renderer.java    From android-maps-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Scales a bitmap by a specified float, taking into account the display density such
 * that the bitmap is scaled for a standard sized KML point marker.
 *
 * @param unscaledBitmap Unscaled bitmap image to scale.
 * @param scale          Scale value. A "1.0" scale value corresponds to the original size of the Bitmap
 * @return A scaled bitmap image
 */
private BitmapDescriptor scaleIcon(Bitmap unscaledBitmap, double scale) {
    float density = mContext.getResources().getDisplayMetrics().density;
    int minSize = (int) (MARKER_ICON_SIZE * density * scale);

    int unscaledWidth = unscaledBitmap.getWidth();
    int unscaledHeight = unscaledBitmap.getHeight();

    int width;
    int height;
    if (unscaledWidth < unscaledHeight) {
        width = minSize;
        height = (int) ((float) (minSize * unscaledHeight) / (float) unscaledWidth);
    } else if (unscaledWidth > unscaledHeight) {
        width = (int) ((float) (minSize * unscaledWidth) / (float) unscaledHeight);
        height = minSize;
    } else {
        width = minSize;
        height = minSize;
    }

    Bitmap scaledBitmap = Bitmap.createScaledBitmap(unscaledBitmap, width, height, false);
    return BitmapDescriptorFactory.fromBitmap(scaledBitmap);
}
 
Example 2
Source File: PlaceMapFragment.java    From RxGpsService with Apache License 2.0 5 votes vote down vote up
private BitmapDescriptor getIconUser() {
    if (iconUser == null) {
        Bitmap bitmap = bitmapHelper.getBitmap(getContext(), R.drawable.ic_accessibility);
        bitmap = bitmapHelper.getTintedBitmap(bitmap, ContextCompat.getColor(getContext(), R.color.green));
        iconUser = BitmapDescriptorFactory.fromBitmap(bitmap);
    }

    return iconUser;
}
 
Example 3
Source File: GglMapCustomMarkerView.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public BitmapDescriptor createCustomMarkerViewForP2P(Context context, int res, float heightVale, int npos) {
    View view = LayoutInflater.from(context).inflate(R.layout.x8_map_custom_mark_view_for_point, null);
    ((TextView) view.findViewById(R.id.point_heightValue)).setText(X8NumberUtil.getDistanceNumberString(heightVale, 0, true));
    ImageView imageView = (ImageView) view.findViewById(R.id.markerIcon);
    if (res != 0) {
        imageView.setBackgroundResource(res);
    }
    return BitmapDescriptorFactory.fromBitmap(loadBitmapFromView(view, context));
}
 
Example 4
Source File: PlaceMapFragment.java    From RxGpsService with Apache License 2.0 5 votes vote down vote up
private BitmapDescriptor getIconRoute() {
    if (iconRoute == null) {
        Bitmap bitmap = bitmapHelper.getBitmap(getContext(), R.drawable.ic_assistant_photo);
        bitmap = bitmapHelper.getTintedBitmap(bitmap, ContextCompat.getColor(getContext(), R.color.red));
        iconRoute = BitmapDescriptorFactory.fromBitmap(bitmap);
    }

    return iconRoute;
}
 
Example 5
Source File: LocatrFragment.java    From AndroidProgramming3e with Apache License 2.0 5 votes vote down vote up
private void updateUI() {
    if (mMap == null || mMapImage == null) {
        return;
    }

    LatLng itemPoint = new LatLng(mMapItem.getLat(), mMapItem.getLon());
    LatLng myPoint = new LatLng(
            mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());

    BitmapDescriptor itemBitmap = BitmapDescriptorFactory.fromBitmap(mMapImage);
    MarkerOptions itemMarker = new MarkerOptions()
            .position(itemPoint)
            .icon(itemBitmap);
    MarkerOptions myMarker = new MarkerOptions()
            .position(myPoint);
    mMap.clear();
    mMap.addMarker(itemMarker);
    mMap.addMarker(myMarker);

    LatLngBounds bounds = new LatLngBounds.Builder()
            .include(itemPoint)
            .include(myPoint)
            .build();

    int margin = getResources().getDimensionPixelSize(R.dimen.map_inset_margin);
    CameraUpdate update = CameraUpdateFactory.newLatLngBounds(bounds, margin);
    mMap.animateCamera(update);
}
 
Example 6
Source File: Renderer.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a cached image needed for GroundOverlays images
 *
 * @param url URL to get cached image for
 * @return BitmapDescriptor
 */
protected BitmapDescriptor getCachedGroundOverlayImage(String url) {
    BitmapDescriptor bitmapDescriptor = mImagesCache.groundOverlayImagesCache.get(url);
    if (bitmapDescriptor == null) {
        Bitmap bitmap = mImagesCache.bitmapCache.get(url);
        if (bitmap != null) {
            bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
            mImagesCache.groundOverlayImagesCache.put(url, bitmapDescriptor);
        }
    }
    return bitmapDescriptor;
}
 
Example 7
Source File: MapFragment.java    From GNSS_Compare with Apache License 2.0 5 votes vote down vote up
/**
 * Demonstrates converting a {@link Drawable} to a {@link BitmapDescriptor},
 * for use as a marker icon.
 */
private BitmapDescriptor vectorToBitmap(@DrawableRes int id, @ColorInt int color) {
    Drawable vectorDrawable = ResourcesCompat.getDrawable(getResources(), id, null);
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
            vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    DrawableCompat.setTint(vectorDrawable, color);
    vectorDrawable.draw(canvas);
    return BitmapDescriptorFactory.fromBitmap(bitmap);
}
 
Example 8
Source File: MarkerActivity.java    From Complete-Google-Map-API-Tutorial with Apache License 2.0 5 votes vote down vote up
private BitmapDescriptor convertDrawableToBitmap(Drawable drawable)
{
	Canvas canvas = new Canvas();
	Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
	canvas.setBitmap(bitmap);
	drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
	drawable.draw(canvas);
	return BitmapDescriptorFactory.fromBitmap(bitmap);
}
 
Example 9
Source File: PlaceMapFragment.java    From RxGpsService with Apache License 2.0 5 votes vote down vote up
private BitmapDescriptor getIconPoi() {
    if (iconPoi == null) {
        Bitmap bitmap = bitmapHelper.getBitmap(getContext(), R.drawable.ic_place);
        bitmap = bitmapHelper.getTintedBitmap(bitmap, ContextCompat.getColor(getContext(), R.color.orange));
        iconPoi = BitmapDescriptorFactory.fromBitmap(bitmap);
    }

    return iconPoi;
}
 
Example 10
Source File: DefaultClusterRenderer.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a BitmapDescriptor for the given cluster that contains a rough count of the number of
 * items. Used to set the cluster marker icon in the default implementations of
 * {@link #onBeforeClusterRendered(Cluster, MarkerOptions)} and
 * {@link #onClusterUpdated(Cluster, Marker)}.
 *
 * @param cluster cluster to get BitmapDescriptor for
 * @return a BitmapDescriptor for the marker icon for the given cluster that contains a rough
 * count of the number of items.
 */
@NonNull
protected BitmapDescriptor getDescriptorForCluster(@NonNull Cluster<T> cluster) {
    int bucket = getBucket(cluster);
    BitmapDescriptor descriptor = mIcons.get(bucket);
    if (descriptor == null) {
        mColoredCircleBackground.getPaint().setColor(getColor(bucket));
        descriptor = BitmapDescriptorFactory.fromBitmap(mIconGenerator.makeIcon(getClusterText(bucket)));
        mIcons.put(bucket, descriptor);
    }
    return descriptor;
}
 
Example 11
Source File: GglMapCustomMarkerView.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public BitmapDescriptor createCurrentPointView(Context context, int res, int actionRes, int nPos) {
    View view = LayoutInflater.from(context).inflate(R.layout.x8_map_custom_mark_view4, null);
    ImageView imageView = (ImageView) view.findViewById(R.id.img_point);
    if (res != 0) {
        imageView.setBackgroundResource(res);
    }
    ImageView imageView2 = (ImageView) view.findViewById(R.id.img_action);
    if (res != 0) {
        imageView2.setBackgroundResource(actionRes);
    }
    ((TextView) view.findViewById(R.id.tv_index)).setText("" + nPos);
    return BitmapDescriptorFactory.fromBitmap(loadBitmapFromView(view, context));
}
 
Example 12
Source File: GglMapCustomMarkerView.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public BitmapDescriptor createCustomMarkerView2(Context context, int res, int nPos) {
    View view = LayoutInflater.from(context).inflate(R.layout.x8_map_custom_mark_view2, null);
    ((TextView) view.findViewById(R.id.point_heightValue)).setText("" + nPos);
    ImageView imageView = (ImageView) view.findViewById(R.id.markerIcon);
    if (res != 0) {
        imageView.setBackgroundResource(res);
    }
    return BitmapDescriptorFactory.fromBitmap(loadBitmapFromView(view, context));
}
 
Example 13
Source File: GglMapCustomMarkerView.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public BitmapDescriptor createPointEventWithPioView(Context context, int actionRes, int angleRes, float heightVale, int npos, float angle, boolean isSelect, boolean isRelation) {
    View view = LayoutInflater.from(context).inflate(R.layout.x8_map_marker_event_with_pio_view, null);
    ((X8MapPointMarkerViewGroup) view.findViewById(R.id.myview)).setPointEventValue(actionRes, angleRes, heightVale, npos, angle, isSelect, isRelation);
    return BitmapDescriptorFactory.fromBitmap(loadBitmapFromView(view, context));
}
 
Example 14
Source File: LocationBitmapFactory.java    From mage-android with Apache License 2.0 4 votes vote down vote up
public static BitmapDescriptor dotBitmapDescriptor(Context context, Location location) {
	Bitmap bitmap = createDot(context, location);
	return BitmapDescriptorFactory.fromBitmap(bitmap);
}
 
Example 15
Source File: GglMapCustomMarkerView.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public BitmapDescriptor createMapPointAngleNoPioView(Context context, int res, float heightVale, int npos, float angle, boolean isSelect, boolean isRelation) {
    View view = LayoutInflater.from(context).inflate(R.layout.x8_map_marker_no_pio_view, null);
    ((X8MapPointMarkerViewGroup) view.findViewById(R.id.myview)).setValueNoPio(res, heightVale, npos, angle, isSelect, isRelation);
    return BitmapDescriptorFactory.fromBitmap(loadBitmapFromView(view, context));
}
 
Example 16
Source File: GglMapCustomMarkerView.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public BitmapDescriptor createMapPointWithPioView(Context context, int res, float heightVale, int npos, int poi, float angle, boolean isSelect, boolean isRelation) {
    View view = LayoutInflater.from(context).inflate(R.layout.x8_map_marker_with_pio_view, null);
    ((X8MapPointMarkerViewGroup) view.findViewById(R.id.myview)).setValueWithPio(res, heightVale, npos, poi, angle, isSelect, isRelation);
    return BitmapDescriptorFactory.fromBitmap(loadBitmapFromView(view, context));
}
 
Example 17
Source File: BitmapGenerator.java    From android-custom-markers with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a bitmap icon showing a screenshot of the view passed in.
 *
 * @param view View to convert
 * @return Bitmap icon of view
 */
public static BitmapDescriptor fromView(View view) {

    // TODO: Single views have trouble with measure.
    final int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    view.measure(spec, spec);

    final int width = view.getMeasuredWidth();
    final int height = view.getMeasuredHeight();

    view.layout(0, 0, width, height);

    final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);

    view.draw(canvas);

    return BitmapDescriptorFactory.fromBitmap(bitmap);
}
 
Example 18
Source File: GglMapCustomMarkerView.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public BitmapDescriptor createMapPointNoAngleNoPioView(Context context, int res, float heightVale, int npos, boolean isSelect, boolean isRelation) {
    View view = LayoutInflater.from(context).inflate(R.layout.x8_map_marker_no_pio_view, null);
    ((X8MapPointMarkerViewGroup) view.findViewById(R.id.myview)).setValueNoPio(res, heightVale, npos, 0.0f, isSelect, isRelation);
    return BitmapDescriptorFactory.fromBitmap(loadBitmapFromView(view, context));
}
 
Example 19
Source File: GglMapCustomMarkerView.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public BitmapDescriptor createInreterstMarkerView0(Context context, int res) {
    return BitmapDescriptorFactory.fromBitmap(loadBitmapFromView(LayoutInflater.from(context).inflate(R.layout.x8_map_custom_mark_view3, null), context));
}
 
Example 20
Source File: CustomMarkerClusteringDemoActivity.java    From android-maps-utils with Apache License 2.0 2 votes vote down vote up
/**
 * Get a descriptor for a single person (i.e., a marker outside a cluster) from their
 * profile photo to be used for a marker icon
 *
 * @param person person to return an BitmapDescriptor for
 * @return the person's profile photo as a BitmapDescriptor
 */
private BitmapDescriptor getItemIcon(Person person) {
    mImageView.setImageResource(person.profilePhoto);
    Bitmap icon = mIconGenerator.makeIcon();
    return BitmapDescriptorFactory.fromBitmap(icon);
}