/** * Scales a Bitmap to a specified float. * * @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 static BitmapDescriptor scaleIcon(Bitmap unscaledBitmap, Double scale) { int width = (int) (unscaledBitmap.getWidth() * scale); int height = (int) (unscaledBitmap.getHeight() * scale); Bitmap scaledBitmap = Bitmap.createScaledBitmap(unscaledBitmap, width, height, false); return BitmapDescriptorFactory.fromBitmap(scaledBitmap); }
public Builder<T> iconId(int iconId) { try { markerOptions.icon(BitmapDescriptorFactory.fromResource(iconId)); } catch (NullPointerException ignored) { // google play services is not available } return this; }
/** * Sets the color for a marker * * @param color Color for a marker */ /* package */ void setMarkerColor(String color) { int integerColor = Color.parseColor("#" + convertColor(color)); mMarkerColor = getHueValue(integerColor); mMarkerOptions.icon(BitmapDescriptorFactory.defaultMarker(mMarkerColor)); mStylesSet.add("markerColor"); }
.title("Brisbane") .snippet("Population: 2,074,200") .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))); .title("Sydney") .snippet("Population: 4,627,300") .icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)) .infoWindowAnchor(0.5f, 0.5f)); 135 - 10 * Math.cos(i * Math.PI / (numMarkersInRainbow - 1)))) .title("Marker " + i) .icon(BitmapDescriptorFactory.defaultMarker(i * 360 / numMarkersInRainbow)) .flat(flat) .rotation(rotation));
public void createAllMarkersInvisible() { LatLng northPoleHideout = new LatLng(90.0D, 0.0D); destMarker = map.addMarker(new MarkerOptions().position(northPoleHideout).icon(BitmapDescriptorFactory.fromBitmap(drawableDest))); destMarker.setVisible(false); currentPosition = map.addMarker(new MarkerOptions().position(northPoleHideout) .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_maps_indicator_current_position_ohne)).anchor(0.5f, 0.5f)); currentPosition.setVisible(false); current_position_anim_ohne = map.addMarker(new MarkerOptions().position(northPoleHideout) .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_maps_indicator_current_position_anim_ohne)).anchor(0.5f, 0.5f)); current_position_anim_ohne.setVisible(false); }
public Builder<T> bitmap(Bitmap bitmap) { try { bitmapDescriptor(BitmapDescriptorFactory.fromBitmap(bitmap)); } catch (NullPointerException ignored) { // google play services is not available } return this; }
private void addMarker(GoogleMap map, double lat, double lon, int title, int snippet, int hue) { map.addMarker(new MarkerOptions().position(new LatLng(lat, lon)) .title(getString(title)) .snippet(getString(snippet)) .icon(BitmapDescriptorFactory.defaultMarker(hue))); } }
private Cap getSelectedCap(int pos) { switch (CAP_TYPE_NAME_RESOURCE_IDS[pos]) { case R.string.cap_butt: return new ButtCap(); case R.string.cap_square: return new SquareCap(); case R.string.cap_round: return new RoundCap(); case R.string.cap_image: return new CustomCap( BitmapDescriptorFactory.fromResource(R.drawable.chevron), CUSTOM_CAP_IMAGE_REF_WIDTH_PX); } return null; }
@Override protected void onBeforeClusterItemRendered(Person person, MarkerOptions markerOptions) { // Draw a single person. // Set the info window to show their name. mImageView.setImageResource(person.profilePhoto); Bitmap icon = mIconGenerator.makeIcon(); markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)).title(person.name); }
private void placeMarkers() { // Add a marker for every earthquake for (EarthQuakeRec rec : mRetainedFragment.getData()) { // Add a new marker for this earthquake mMap.addMarker(new MarkerOptions() // Set the Marker's position .position(new LatLng(rec.getLat(), rec.getLng())) // Set the title of the Marker's information window .title(String.valueOf(rec.getMagnitude())) // Set the color for the Marker .icon(BitmapDescriptorFactory .defaultMarker(getMarkerColor(rec .getMagnitude())))); } }
@Override public void onMapReady(GoogleMap map) { // Register a listener to respond to clicks on GroundOverlays. map.setOnGroundOverlayClickListener(this); map.moveCamera(CameraUpdateFactory.newLatLngZoom(NEWARK, 11)); mImages.clear(); mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.newark_nj_1922)); mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.newark_prudential_sunny)); // Add a small, rotated overlay that is clickable by default // (set by the initial state of the checkbox.) mGroundOverlayRotated = map.addGroundOverlay(new GroundOverlayOptions() .image(mImages.get(1)).anchor(0, 1) .position(NEAR_NEWARK, 4300f, 3025f) .bearing(30) .clickable(((CheckBox) findViewById(R.id.toggleClickability)).isChecked())); // Add a large overlay at Newark on top of the smaller overlay. mGroundOverlay = map.addGroundOverlay(new GroundOverlayOptions() .image(mImages.get(mCurrentEntry)).anchor(0, 1) .position(NEWARK, 8600f, 6500f)); mTransparencyBar.setOnSeekBarChangeListener(this); // Override the default content description on the view, for accessibility mode. // Ideally this string would be localised. map.setContentDescription("Google Map with ground overlay."); }
/** * Sets the marker icon if there was a url that was found * * @param styleUrl The style which we retrieve the icon url from * @param markerOptions The marker which is displaying the icon */ private void addMarkerIcons(String styleUrl, MarkerOptions markerOptions) { if (mImagesCache.get(styleUrl) != null) { // Bitmap stored in cache Bitmap bitmap = mImagesCache.get(styleUrl); markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap)); } else if (!mMarkerIconUrls.contains(styleUrl)) { mMarkerIconUrls.add(styleUrl); } }
/** * Adds a point style to all features to change the color of the marker based on its magnitude * property */ private void addColorsToMarkers(GeoJsonLayer layer) { // Iterate over all the features stored in the layer for (GeoJsonFeature feature : layer.getFeatures()) { // Check if the magnitude property exists if (feature.getProperty("mag") != null && feature.hasProperty("place")) { double magnitude = Double.parseDouble(feature.getProperty("mag")); // Get the icon for the feature BitmapDescriptor pointIcon = BitmapDescriptorFactory .defaultMarker(magnitudeToColor(magnitude)); // Create a new point style GeoJsonPointStyle pointStyle = new GeoJsonPointStyle(); // Set options for the point style pointStyle.setIcon(pointIcon); pointStyle.setTitle("Magnitude of " + magnitude); pointStyle.setSnippet("Earthquake occured " + feature.getProperty("place")); // Assign the point style to the feature feature.setPointStyle(pointStyle); } } }
@Override public void onMapReady(GoogleMap map) { map.setOnMarkerDragListener(SplitStreetViewPanoramaAndMapDemoActivity.this); // Creates a draggable marker. Long press to drag. mMarker = map.addMarker(new MarkerOptions() .position(markerPosition) .icon(BitmapDescriptorFactory.fromResource(R.drawable.pegman)) .draggable(true)); } });
@Override protected void onBeforeClusterRendered(Cluster<Person> cluster, MarkerOptions markerOptions) { // Draw multiple people. // Note: this method runs on the UI thread. Don't spend too much time in here (like in this example). List<Drawable> profilePhotos = new ArrayList<Drawable>(Math.min(4, cluster.getSize())); int width = mDimension; int height = mDimension; for (Person p : cluster.getItems()) { // Draw 4 at most. if (profilePhotos.size() == 4) break; Drawable drawable = getResources().getDrawable(p.profilePhoto); drawable.setBounds(0, 0, width, height); profilePhotos.add(drawable); } MultiDrawable multiDrawable = new MultiDrawable(profilePhotos); multiDrawable.setBounds(0, 0, width, height); mClusterImageView.setImageDrawable(multiDrawable); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); }
public void testIcon() throws Exception { BitmapDescriptor icon = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN); pointStyle .setIcon(icon); assertEquals(icon, pointStyle.getIcon()); assertEquals(icon, pointStyle.toMarkerOptions().getIcon()); }
.image(BitmapDescriptorFactory.fromResource(R.drawable.harbour_bridge)) .position(SYDNEY, 700000) .clickable(true));
/** * Called before the marker for a Cluster is added to the map. * The default implementation draws a circle with a rough count of the number of items. */ protected void onBeforeClusterRendered(Cluster<T> cluster, MarkerOptions markerOptions) { 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); } // TODO: consider adding anchor(.5, .5) (Individual markers will overlap more often) markerOptions.icon(descriptor); }
/** * Creates a new marker option from given properties of an existing marker option * * @param originalMarkerOption An existing MarkerOption instance * @param iconRandomColorMode True if marker color mode is random, false otherwise * @param markerColor Color of the marker * @return A new MarkerOption */ private static MarkerOptions createMarkerOptions(MarkerOptions originalMarkerOption, boolean iconRandomColorMode, float markerColor) { MarkerOptions newMarkerOption = new MarkerOptions(); newMarkerOption.rotation(originalMarkerOption.getRotation()); newMarkerOption.anchor(originalMarkerOption.getAnchorU(), originalMarkerOption.getAnchorV()); if (iconRandomColorMode) { float hue = getHueValue(computeRandomColor((int) markerColor)); originalMarkerOption.icon(BitmapDescriptorFactory.defaultMarker(hue)); } newMarkerOption.icon(originalMarkerOption.getIcon()); return newMarkerOption; }
@Override public BitmapDescriptor fromResource(@DrawableRes int resourceId) { return new BitmapDescriptorAdapter( com.google.android.gms.maps.model.BitmapDescriptorFactory.fromResource(resourceId) ); }