|
19 | 19 | import com.google.maps.android.collections.PolylineManager;
|
20 | 20 | import com.google.maps.android.data.Feature;
|
21 | 21 | import com.google.maps.android.data.Geometry;
|
| 22 | +import com.google.maps.android.data.MultiGeometry; |
22 | 23 | import com.google.maps.android.data.Renderer;
|
23 | 24 |
|
24 | 25 | import java.io.IOException;
|
|
30 | 31 | import java.util.ArrayList;
|
31 | 32 | import java.util.HashMap;
|
32 | 33 | import java.util.Iterator;
|
| 34 | +import java.util.List; |
33 | 35 |
|
34 | 36 | /**
|
35 | 37 | * Renders all visible KmlPlacemark and KmlGroundOverlay objects onto the GoogleMap as Marker,
|
@@ -273,42 +275,92 @@ private void downloadMarkerIcons() {
|
273 | 275 |
|
274 | 276 | /**
|
275 | 277 | * Adds the marker icon stored in mMarkerIconCache, to the {@link com.google.android.gms.maps.model.Marker}
|
| 278 | + * recursing over multi-geometry placemarks to add icons to all point geometries |
276 | 279 | *
|
277 | 280 | * @param iconUrl icon url of icon to add to markers
|
278 |
| - * @param placemarks |
| 281 | + * @param placemarks map of placemark to features |
279 | 282 | */
|
280 | 283 | private void addIconToMarkers(String iconUrl, HashMap<KmlPlacemark, Object> placemarks) {
|
281 | 284 | for (Feature placemark : placemarks.keySet()) {
|
282 | 285 | KmlStyle urlStyle = getStylesRenderer().get(placemark.getId());
|
283 | 286 | KmlStyle inlineStyle = ((KmlPlacemark) placemark).getInlineStyle();
|
284 |
| - if ("Point".equals(placemark.getGeometry().getGeometryType())) { |
285 |
| - boolean isInlineStyleIcon = inlineStyle != null && iconUrl |
286 |
| - .equals(inlineStyle.getIconUrl()); |
287 |
| - boolean isPlacemarkStyleIcon = urlStyle != null && iconUrl |
288 |
| - .equals(urlStyle.getIconUrl()); |
289 |
| - if (isInlineStyleIcon) { |
290 |
| - scaleBitmap(inlineStyle, placemarks, (KmlPlacemark) placemark); |
291 |
| - } else if (isPlacemarkStyleIcon) { |
292 |
| - scaleBitmap(urlStyle, placemarks, (KmlPlacemark) placemark); |
293 |
| - } |
294 |
| - } |
| 287 | + Geometry geometry = placemark.getGeometry(); |
| 288 | + Object object = placemarks.get(placemark); |
| 289 | + addIconToGeometry(iconUrl, urlStyle, inlineStyle, geometry, object); |
| 290 | + } |
| 291 | + } |
| 292 | + |
| 293 | + /** |
| 294 | + * Checks for point geometry and adds icon to marker or |
| 295 | + * recurses over multi-geometries to add icon to point sub-geometries |
| 296 | + * |
| 297 | + * @param iconUrl icon url of icon to add to markers |
| 298 | + * @param urlStyle url style for placemark |
| 299 | + * @param inlineStyle inline style for placemark |
| 300 | + * @param geometry geometry to check |
| 301 | + * @param object object related to geometry, marker if point |
| 302 | + * or list of sub-objects for multi-geometries |
| 303 | + */ |
| 304 | + private void addIconToGeometry(String iconUrl, KmlStyle urlStyle, KmlStyle inlineStyle, Geometry geometry, Object object) { |
| 305 | + if (geometry == null) return; |
| 306 | + if ("Point".equals(geometry.getGeometryType())) { |
| 307 | + addIconToMarker(iconUrl, urlStyle, inlineStyle, (Marker) object); |
| 308 | + } else if ("MultiGeometry".equals(geometry.getGeometryType())) { |
| 309 | + addIconToMultiGeometry(iconUrl, urlStyle, inlineStyle, (MultiGeometry) geometry, (List<Object>) object); |
| 310 | + } |
| 311 | + } |
| 312 | + |
| 313 | + /** |
| 314 | + * Adds icon to point sub-geometries of multi-geometry placemarks |
| 315 | + * |
| 316 | + * @param iconUrl icon url of icon to add to markers |
| 317 | + * @param urlStyle url style for placemark |
| 318 | + * @param inlineStyle inline style for placemark |
| 319 | + * @param multiGeometry multi-geometry to iterator over sub-geometries of |
| 320 | + * @param objects list of sub-objects for sub-geometries |
| 321 | + */ |
| 322 | + private void addIconToMultiGeometry(String iconUrl, KmlStyle urlStyle, KmlStyle inlineStyle, MultiGeometry multiGeometry, List<Object> objects) { |
| 323 | + Iterator<Geometry> geometries = multiGeometry.getGeometryObject().iterator(); |
| 324 | + Iterator<Object> objItr = objects.iterator(); |
| 325 | + while (geometries.hasNext() && objItr.hasNext()) { |
| 326 | + Geometry geometry = geometries.next(); |
| 327 | + Object object = objItr.next(); |
| 328 | + addIconToGeometry(iconUrl, urlStyle, inlineStyle, geometry, object); |
| 329 | + } |
| 330 | + } |
| 331 | + |
| 332 | + /** |
| 333 | + * Add icon to marker for point geometry placemarks |
| 334 | + * |
| 335 | + * @param iconUrl icon url of icon to add to markers |
| 336 | + * @param urlStyle url style for placemark |
| 337 | + * @param inlineStyle inline style for placemark |
| 338 | + * @param marker marker to add icon to |
| 339 | + */ |
| 340 | + private void addIconToMarker(String iconUrl, KmlStyle urlStyle, KmlStyle inlineStyle, Marker marker) { |
| 341 | + boolean isInlineStyleIcon = inlineStyle != null && iconUrl |
| 342 | + .equals(inlineStyle.getIconUrl()); |
| 343 | + boolean isPlacemarkStyleIcon = urlStyle != null && iconUrl |
| 344 | + .equals(urlStyle.getIconUrl()); |
| 345 | + if (isInlineStyleIcon) { |
| 346 | + scaleBitmap(inlineStyle, marker); |
| 347 | + } else if (isPlacemarkStyleIcon) { |
| 348 | + scaleBitmap(urlStyle, marker); |
295 | 349 | }
|
296 | 350 | }
|
297 | 351 |
|
298 | 352 | /**
|
299 | 353 | * Enlarges or shrinks a bitmap image based on the scale provided
|
300 | 354 | *
|
301 |
| - * @param style Style to retrieve iconUrl and scale from |
302 |
| - * @param placemarks |
303 |
| - * @param placemark Placemark object to set the image to |
| 355 | + * @param style Style to retrieve iconUrl and scale from |
| 356 | + * @param marker Marker to set the image to |
304 | 357 | */
|
305 |
| - private void scaleBitmap(KmlStyle style, HashMap<KmlPlacemark, Object> placemarks, |
306 |
| - KmlPlacemark placemark) { |
| 358 | + private void scaleBitmap(KmlStyle style, Marker marker) { |
307 | 359 | double bitmapScale = style.getIconScale();
|
308 | 360 | String bitmapUrl = style.getIconUrl();
|
309 | 361 | Bitmap bitmapImage = getImagesCache().get(bitmapUrl);
|
310 | 362 | BitmapDescriptor scaledBitmap = scaleIcon(bitmapImage, bitmapScale);
|
311 |
| - ((Marker) placemarks.get(placemark)).setIcon(scaledBitmap); |
| 363 | + marker.setIcon(scaledBitmap); |
312 | 364 | }
|
313 | 365 |
|
314 | 366 | /**
|
|
0 commit comments