/** * Adds the marker icon stored in mMarkerIconCache, to the {@link com.google.android.gms.maps.model.Marker} * * @param iconUrl icon url of icon to add to markers * @param placemarks */ private void addIconToMarkers(String iconUrl, HashMap<KmlPlacemark, Object> placemarks) { for (Feature placemark : placemarks.keySet()) { KmlStyle urlStyle = getStylesRenderer().get(placemark.getId()); KmlStyle inlineStyle = ((KmlPlacemark) placemark).getInlineStyle(); if ("Point".equals(placemark.getGeometry().getGeometryType())) { boolean isInlineStyleIcon = inlineStyle != null && iconUrl .equals(inlineStyle.getIconUrl()); boolean isPlacemarkStyleIcon = urlStyle != null && iconUrl .equals(urlStyle.getIconUrl()); if (isInlineStyleIcon) { scaleBitmap(inlineStyle, placemarks, (KmlPlacemark) placemark); } else if (isPlacemarkStyleIcon) { scaleBitmap(urlStyle, placemarks, (KmlPlacemark) placemark); } } } }
/** * Enlarges or shrinks a bitmap image based on the scale provided * @param style Style to retrieve iconUrl and scale from * @param placemarks * @param placemark Placemark object to set the image to */ private void scaleBitmap(KmlStyle style, HashMap<KmlPlacemark, Object> placemarks, KmlPlacemark placemark) { double bitmapScale = style.getIconScale(); String bitmapUrl = style.getIconUrl(); Bitmap bitmapImage = getImagesCache().get(bitmapUrl); BitmapDescriptor scaledBitmap = scaleIcon(bitmapImage, bitmapScale); ((Marker) placemarks.get(placemark)).setIcon(scaledBitmap); }
MarkerOptions markerOptions = style.getMarkerOptions(); if (inlineStyle != null) { setInlinePointStyle(markerOptions, inlineStyle, style.getIconUrl()); } else if (style.getIconUrl() != null) { addMarkerIcons(style.getIconUrl(), markerOptions);
/** * Sets the inline point style by copying over the styles that have been set * * @param markerOptions marker options object to add inline styles to * @param inlineStyle inline styles to apply * @param markerUrlIconUrl default marker icon URL from shared style */ private void setInlinePointStyle(MarkerOptions markerOptions, KmlStyle inlineStyle, String markerUrlIconUrl) { MarkerOptions inlineMarkerOptions = inlineStyle.getMarkerOptions(); if (inlineStyle.isStyleSet("heading")) { markerOptions.rotation(inlineMarkerOptions.getRotation()); } if (inlineStyle.isStyleSet("hotSpot")) { markerOptions .anchor(inlineMarkerOptions.getAnchorU(), inlineMarkerOptions.getAnchorV()); } if (inlineStyle.isStyleSet("markerColor")) { markerOptions.icon(inlineMarkerOptions.getIcon()); } if (inlineStyle.isStyleSet("iconUrl")) { addMarkerIcons(inlineStyle.getIconUrl(), markerOptions); } else if (markerUrlIconUrl != null) { // Inline style with no icon defined addMarkerIcons(markerUrlIconUrl, markerOptions); } }