Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Adding example of onStyleImageMissing listener usage #1070

Merged
merged 1 commit into from
May 21, 2019

Conversation

osana
Copy link
Contributor

@osana osana commented May 16, 2019

This PR adds an example for handling missing image in Style.

If an icon-image cannot be found in a map Style, a custom image could be provided via
onStyleImageMissing listener

This example is based on @captainbarbosa's suggestion from
mapbox/ios-sdk-examples#289

ezgif com-resize

@osana osana changed the title Missing Icon example Missing Icon Example May 16, 2019
@osana osana force-pushed the osana-missing-icon branch from 392bb3b to 1af67f4 Compare May 17, 2019 01:42
@osana osana requested review from chloekraw and langsmith May 17, 2019 01:51
@langsmith langsmith force-pushed the osana-missing-icon branch 2 times, most recently from 822a330 to 22cc651 Compare May 20, 2019 17:53
@langsmith langsmith force-pushed the osana-missing-icon branch from 22cc651 to 507f774 Compare May 20, 2019 17:58
@langsmith
Copy link
Contributor

Ok, I've refactored this to mainly add more logic. This example is based around the idea of using onStyleImageMissing() to set an appropriate user profile photo at runtime. The profile photo SymbolLayer uses iconImage(get(PROFILE_NAME)), and then the switch/case below uses the id to set the right icon image

@Override
      public void onStyleImageMissing(@NonNull String id) {
        switch (id) {
          case CARLOS:
            addImage(id, R.drawable.carlos);
            break;
          case ANTONY:
            addImage(id, R.drawable.antony);
            break;
          case MARIA:
            addImage(id, R.drawable.maria);
            break;
          case LUCIANA:
            addImage(id, R.drawable.luciana);
            break;
          default:
            addImage(id, R.drawable.carlos);
            break;
        }
      }

private void addImage(String id, int drawableImage) {
    Style style = mapboxMap.getStyle();
    if (style != null) {
      style.addImageAsync(id, BitmapUtils.getBitmapFromDrawable(
        getResources().getDrawable(drawableImage)));
    }
  }

@langsmith langsmith requested review from tobrun and LukasPaczos and removed request for langsmith May 20, 2019 18:02
@langsmith langsmith self-assigned this May 20, 2019
@langsmith langsmith removed the request for review from chloekraw May 20, 2019 18:09
@langsmith langsmith changed the title Missing Icon Example Adding example of onStyleImageMissing listener usage May 20, 2019
Copy link
Member

@tobrun tobrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@langsmith langsmith merged commit 936b9fa into master May 21, 2019
@langsmith langsmith deleted the osana-missing-icon branch May 21, 2019 15:11
@langsmith langsmith mentioned this pull request May 22, 2019
5 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants