com.mapbox.mapboxsdk.annotations.Icon Java Examples

The following examples show how to use com.mapbox.mapboxsdk.annotations.Icon. 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: MapAssets.java    From android with MIT License 6 votes vote down vote up
private Icon getTextIcon(Bitmap bitmap, int price) {
    if (price != Const.UNKNOWN_VALUE) {
        // Create Paint
        final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.WHITE);
        paint.setTextAlign(Paint.Align.CENTER);
        paint.setTextSize(markerTextSize);

        // Draw text on Canvas, center-aligned
        final Canvas canvas = new Canvas(bitmap);
        canvas.drawText(String.format(markerTextTemplate, price),
                X_CENTER * bitmap.getWidth(),
                Y_CENTER * bitmap.getHeight(),
                paint);
    }
    return iconFactory.fromBitmap(bitmap);
}
 
Example #2
Source File: MapAssets.java    From android with MIT License 6 votes vote down vote up
public Icon getLotMarkerIcon(int price, int type, boolean isBest) {
    // First, verify if same icon exists in cache
    final Icon cachedIcon = getCacheIcon(price, type, isBest);
    if (cachedIcon != null) {
        return cachedIcon;
    }

    // Copy to a mutable Bitmap
    Bitmap bitmap;
    if (isBest) {
        bitmap = markerBitmapOpenBest.copy(markerBitmapOpenBest.getConfig(), true);
    } else if (type == Const.BusinnessHourType.CLOSED) {
        bitmap = markerBitmapClosed.copy(markerBitmapClosed.getConfig(), true);
    } else {
        bitmap = markerBitmapOpen.copy(markerBitmapOpen.getConfig(), true);
    }

    final Icon icon = getTextIcon(bitmap, price);

    // Save icon to cache
    setCacheIcon(icon, price, type, isBest);

    return icon;
}
 
Example #3
Source File: ThemeSwitcher.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
/**
 * Returns a map marker {@link Icon} based on the current theme setting.
 *
 * @param context to retrieve an instance of {@link IconFactory}
 * @return {@link Icon} map marker dark or light
 */
public static Icon retrieveThemeMapMarker(Context context) {
  TypedValue destinationMarkerResId = resolveAttributeFromId(context, R.attr.navigationViewDestinationMarker);
  int markerResId = destinationMarkerResId.resourceId;
  IconFactory iconFactory = IconFactory.getInstance(context);
  return iconFactory.fromResource(markerResId);
}
 
Example #4
Source File: MapUtils.java    From android with MIT License 5 votes vote down vote up
public static Marker addSearchMarker(MapView mapView, LatLng latLng, Icon searchIcon) {
    final JsonSnippet snippet = new JsonSnippet.Builder()
            .search()
            .build();
    return mapView.addMarker(new MarkerOptions()
            .snippet(JsonSnippet.toJson(snippet))
            .position(latLng)
            .icon(searchIcon)
    );
}
 
Example #5
Source File: MapUtils.java    From android with MIT License 5 votes vote down vote up
public static void addCheckinMarkerIfAvailable(MapView mapView, Icon checkinIcon) {
    final CheckinData checkin = PrkngPrefs.getInstance(mapView.getContext()).getCheckinData();
    if (checkin != null) {
        final JsonSnippet snippet = new JsonSnippet.Builder()
                .checkin()
                .build();
        mapView.addMarker(new MarkerOptions()
                .icon(checkinIcon)
                .snippet(JsonSnippet.toJson(snippet))
                .position(checkin.getLatLng()));
    }
}
 
Example #6
Source File: MapAssets.java    From android with MIT License 5 votes vote down vote up
private Icon getCacheIcon(int price, int type, boolean isBest) {
    if (isBest) {
        return openBestMarkersCache.get(price, null);
    } else if (type == Const.BusinnessHourType.CLOSED) {
        return closedMarkersCache.get(price, null);
    } else {
        return openMarkersCache.get(price, null);
    }
}
 
Example #7
Source File: MapAssets.java    From android with MIT License 5 votes vote down vote up
private void setCacheIcon(Icon icon, int price, int type, boolean isBest) {
    if (isBest) {
        openBestMarkersCache.append(price, icon);
    } else if (type == Const.BusinnessHourType.CLOSED) {
        closedMarkersCache.append(price, icon);
    } else {
        openMarkersCache.append(price, icon);
    }
}
 
Example #8
Source File: MapAssets.java    From android with MIT License 5 votes vote down vote up
public Icon getLotMarkerIconSelected(int price) {
    final Icon cachedIcon = getCacheIconSelected(price);
    if (cachedIcon != null) {
        return cachedIcon;
    }

    Bitmap bitmap = markerBitmapSelected.copy(markerBitmapSelected.getConfig(), true);

    final Icon icon = getTextIcon(bitmap, price);

    // Save icon to cache
    setCacheIconSelected(icon, price);

    return icon;
}
 
Example #9
Source File: MapAssets.java    From android with MIT License 5 votes vote down vote up
public Icon getCarshareLotMarkerIcon(String company, int available) {
        switch (company) {
            case Const.CarshareCompanies.CAR2GO:
                return markerIconCarshareLotCar2go;
            case Const.CarshareCompanies.COMMUNAUTO:
                return markerIconCarshareLotCommunauto;
            default:
                // TODO Zipcar and Auto-mobile use the Communauto lot green icon
                return markerIconCarshareLotCommunauto;
//                return getCarshareVehicleMarkerIcon(company);
        }
    }
 
Example #10
Source File: MapAssets.java    From android with MIT License 5 votes vote down vote up
public Icon getCarshareVehicleMarkerIcon(String company) {
    switch (company) {
        case Const.CarshareCompanies.CAR2GO:
            return markerIconCarshareCar2go;
        case Const.CarshareCompanies.AUTOMOBILE:
            return markerIconCarshareAutomobile;
        case Const.CarshareCompanies.COMMUNAUTO:
            return markerIconCarshareCommunauto;
        case Const.CarshareCompanies.ZIPCAR:
            return markerIconCarshareZipcar;
    }
    return null;
}
 
Example #11
Source File: Images.java    From WhereAreTheEyes with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static final Icon getCameraIcon() {
    if( cameraIcon != null )
        return cameraIcon;
    IconFactory iconFactory = IconFactory.getInstance(mainContext);
    cameraIcon = iconFactory.fromResource(R.drawable.map_pin);
    return cameraIcon;
}
 
Example #12
Source File: Utils.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
/**
 * Demonstrates converting any Drawable to an Icon, for use as a marker icon.
 */
public static Icon drawableToIcon(@NonNull Context context, @DrawableRes int id) {
  Drawable vectorDrawable = ResourcesCompat.getDrawable(context.getResources(), id, context.getTheme());
  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());
  vectorDrawable.draw(canvas);
  return IconFactory.getInstance(context).fromBitmap(bitmap);
}
 
Example #13
Source File: EndNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void drawPaella() {
  Icon paellaIcon = IconFactory.getInstance(this).fromResource(R.drawable.paella_icon);
  paella = navigationView.retrieveNavigationMapboxMap().retrieveMap().addMarker(new MarkerOptions()
    .position(new LatLng(37.760615, -122.424306))
    .icon(paellaIcon)
  );
}
 
Example #14
Source File: NavigationMapboxMap.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@NonNull
private Marker createMarkerFromIcon(Context context, Point position) {
  LatLng markerPosition = new LatLng(position.latitude(),
    position.longitude());
  Icon markerIcon = ThemeSwitcher.retrieveThemeMapMarker(context);
  return mapboxMap.addMarker(new MarkerOptions()
    .position(markerPosition)
    .icon(markerIcon));
}
 
Example #15
Source File: MapAssets.java    From android with MIT License 4 votes vote down vote up
public Icon getMarkerIconTransparent() {
    return markerIconTransparent;
}
 
Example #16
Source File: MapAssets.java    From android with MIT License 4 votes vote down vote up
public Icon getCheckinMarkerIcon() {
    return markerIconCheckin;
}
 
Example #17
Source File: MapAssets.java    From android with MIT License 4 votes vote down vote up
public Icon getSearchMarkerIcon() {
    return markerIconSearch;
}
 
Example #18
Source File: MapAssets.java    From android with MIT License 4 votes vote down vote up
public Icon getMarkerIconSelected() {
    return markerIconSelected;
}
 
Example #19
Source File: MapAssets.java    From android with MIT License 4 votes vote down vote up
public Icon getMarkerIconPaid() {
    return markerIconPaid;
}
 
Example #20
Source File: MapAssets.java    From android with MIT License 4 votes vote down vote up
public Icon getMarkerIconFree() {
    return markerIconFree;
}
 
Example #21
Source File: MapAssets.java    From android with MIT License 4 votes vote down vote up
private Icon getCacheIconSelected(int price) {
    return selectedMarkersCache.get(price, null);
}
 
Example #22
Source File: MapAssets.java    From android with MIT License 4 votes vote down vote up
private void setCacheIconSelected(Icon icon, int price) {
    selectedMarkersCache.append(price, icon);
}
 
Example #23
Source File: SelectedFeature.java    From android with MIT License 4 votes vote down vote up
public Icon getMarkerIcon() {
    return markerIcon;
}
 
Example #24
Source File: SelectedFeature.java    From android with MIT License 4 votes vote down vote up
public void setMarkerIcon(Icon markerIcon) {
    this.markerIcon = markerIcon;
}
 
Example #25
Source File: MainMapFragment.java    From android with MIT License 4 votes vote down vote up
private void selectFeature(String featureId) {
    if (mFeatureAnnotsList == null) {
        return;
    }

    // Store the selected feature's ID, for restore
    mSelectedFeature = new SelectedFeature(featureId);

    final List<Annotation> annotations = mFeatureAnnotsList.get(featureId);
    if (annotations == null) {
        return;
    }

    // Reset the selection array
    mSelectedAnnotsList = new ArrayList<>();

    Icon icon;
    switch (mPrkngMapType) {
        case Const.MapSections.OFF_STREET:
            icon = mapAssets.getLotMarkerIconSelected(Const.UNKNOWN_VALUE);
            break;
        case Const.MapSections.ON_STREET:
        default:
            icon = mapAssets.getMarkerIconSelected();
            break;
    }

    for (Annotation annot : annotations) {
        if (annot instanceof Marker) {
            final Marker m = ((Marker) annot);

            if (!m.getIcon().getId().equals(mapAssets.getMarkerIconTransparent().getId())) {
                // Store the selected feature's marker Icon, for restore
                mSelectedFeature.setMarkerIcon(m.getIcon());

                // Change the marker's Icon
                final Marker selectedMarker = vMap.addMarker(
                        MapUtils.extractMarkerOptions(m)
                                .icon(icon)
                );

                // Add to the selection array
                mSelectedAnnotsList.add(selectedMarker);

                // Remove old marker from Map
                vMap.removeAnnotation(m);
            } else {
                // Store transparent buttons without any changes
                mSelectedAnnotsList.add(m);
            }
        } else if (annot instanceof Polyline) {
            final Polyline p = ((Polyline) annot);
            // Store the selected feature's polyline Color, for restore
            mSelectedFeature.setPolylineColor(p.getColor());

            // Change the polyline's color
            final Polyline selected = vMap.addPolyline(
                    MapUtils.extractPolylineOptions(p)
                            .color(mapAssets.getLineColorSelected())
            );
            // Add to the selection array
            mSelectedAnnotsList.add(selected);

            // Remove old polyline from Map
            vMap.removeAnnotation(p);
        }
    }

    // Update the global feature-annotations reference list
    mFeatureAnnotsList.put(featureId, mSelectedAnnotsList);
}