Ejemplo n.º 1
0
 IconManager(NativeMapView nativeMapView) {
   this.nativeMapView = nativeMapView;
   this.icons = new ArrayList<>();
   // load transparent icon for MarkerView to trace actual markers, see #6352
   loadIcon(
       IconFactory.recreate(IconFactory.ICON_MARKERVIEW_ID, IconFactory.ICON_MARKERVIEW_BITMAP));
 }
Ejemplo n.º 2
0
  Icon loadIconForMarker(Marker marker) {
    Icon icon = marker.getIcon();

    // calculating average before adding
    int iconSize = icons.size() + 1;

    // TODO replace former if case with anchor implementation,
    // current workaround for having extra pixels is diving height by 2
    if (icon == null) {
      icon = IconFactory.getInstance(nativeMapView.getContext()).defaultMarker();
      Bitmap bitmap = icon.getBitmap();
      averageIconHeight =
          averageIconHeight + (bitmap.getHeight() / 2 - averageIconHeight) / iconSize;
      averageIconWidth = averageIconWidth + (bitmap.getWidth() - averageIconWidth) / iconSize;
      marker.setIcon(icon);
    } else {
      Bitmap bitmap = icon.getBitmap();
      averageIconHeight = averageIconHeight + (bitmap.getHeight() - averageIconHeight) / iconSize;
      averageIconWidth = averageIconWidth + (bitmap.getWidth() - averageIconWidth) / iconSize;
    }

    if (!icons.contains(icon)) {
      icons.add(icon);
      loadIcon(icon);
    } else {
      Icon oldIcon = icons.get(icons.indexOf(icon));
      if (!oldIcon.getBitmap().sameAs(icon.getBitmap())) {
        throw new IconBitmapChangedException();
      }
    }
    return icon;
  }
Ejemplo n.º 3
0
  void ensureIconLoaded(Marker marker, MapboxMap mapboxMap) {
    Icon icon = marker.getIcon();
    if (icon == null) {
      icon = IconFactory.getInstance(nativeMapView.getContext()).defaultMarker();
      marker.setIcon(icon);
    }
    if (!icons.contains(icon)) {
      icons.add(icon);
      loadIcon(icon);
    } else {
      Icon oldIcon = icons.get(icons.indexOf(icon));
      if (!oldIcon.getBitmap().sameAs(icon.getBitmap())) {
        throw new IconBitmapChangedException();
      }
    }

    // this seems to be a costly operation according to the profiler so I'm trying to save some
    // calls
    Marker previousMarker =
        marker.getId() != -1 ? (Marker) mapboxMap.getAnnotation(marker.getId()) : null;
    if (previousMarker == null
        || previousMarker.getIcon() == null
        || previousMarker.getIcon() != marker.getIcon()) {
      marker.setTopOffsetPixels(getTopOffsetPixelsForIcon(icon));
    }
  }
Ejemplo n.º 4
0
 Icon loadIconForMarkerView(MarkerView marker) {
   Icon icon = marker.getIcon();
   int iconSize = icons.size() + 1;
   if (icon == null) {
     icon = IconFactory.getInstance(nativeMapView.getContext()).defaultMarkerView();
     marker.setIcon(icon);
   }
   Bitmap bitmap = icon.getBitmap();
   averageIconHeight = averageIconHeight + (bitmap.getHeight() - averageIconHeight) / iconSize;
   averageIconWidth = averageIconWidth + (bitmap.getWidth() - averageIconWidth) / iconSize;
   if (!icons.contains(icon)) {
     icons.add(icon);
   } else {
     Icon oldIcon = icons.get(icons.indexOf(icon));
     if (!oldIcon.getBitmap().sameAs(icon.getBitmap())) {
       throw new IconBitmapChangedException();
     }
   }
   return icon;
 }