mapbox / mapbox-plugins-android

Mapbox Android Plugins are a collection of libraries that extend our other SDKs, helping you design powerful mapping features while the plugins handle most of the heavy lifting.
https://www.mapbox.com/android-docs/plugins/overview/
BSD 2-Clause "Simplified" License
241 stars 120 forks source link

icon-image loader #742

Closed tobrun closed 4 years ago

tobrun commented 6 years ago

The style-spec icon-image is currently exposed as

  public void setIconImage(String value) {
    jsonObject.addProperty("icon-image", value);
  }

We need an easier way to support Android resources, for example by allow setting a drawable, bitmap or resource id. This setup should also take in account to support re-adding the images if a style changes occurs #737.

chekdotdev commented 5 years ago

What would you suggest in the interim? Since IconFactory is deprecated, we haven't been successful in finding another way to set custom icon images.

tobrun commented 5 years ago

You add images to your style and create an id for them with:

Style.Builder#withImage or Style#addImage

You can use that id with:

Symbol#setIconImage

chekdotdev commented 5 years ago

@tobrun thanks for the quick reply!!!

tobrun commented 5 years ago

Updating here that it might make more sense for people reading this issue to start using the new image missing api from https://github.com/mapbox/mapbox-gl-native/pull/14320. This will land as part of the upcoming v7.4.0 release.

chloekraw commented 5 years ago

The style-spec icon-image is currently exposed as

public void setIconImage(String value) {
jsonObject.addProperty("icon-image", value);
}

We need an easier way to support Android resources, for example by allow setting a drawable, bitmap or resource id. This setup should also take in account to support re-adding the images if a style changes occurs #737.

@tobrun is there a better way that we could have exposed the icon-image property on Android?

Updating here that it might make more sense for people reading this issue to start using the new image missing api from mapbox/mapbox-gl-native#14320. This will land as part of the upcoming v7.4.0 release.

Interesting, so this means on Android with https://github.com/mapbox/mapbox-plugins-android/pull/1000, it will be easier to add an arbitrary image at runtime than to add a custom sprite uploaded to Studio at runtime?

tobrun commented 5 years ago

@chloekraw in https://github.com/mapbox/mapbox-plugins-android/pull/1000 I'm proposing an alternative way of loading the icons. Just call setIconImage(String value) with the name of the resource and it will be automatically loaded for you (this includes reloading it during style changes).

chloekraw commented 5 years ago

@tobrun ahh, I see! the proposed setIconImage(String value), where "String value" is the name or ID of the icon-image, works for both adding custom sprites to the map and arbitrary images, right?

tobrun commented 5 years ago

@tobrun ahh, I see! the proposed setIconImage(String value), where "String value" is the name or ID of the icon-image, works for both adding custom sprites to the map and arbitrary images, right?

correct, first core tries to match this value to an image in the spritesheet. If not found, the plugin will try loading a app resource with the name (fwiw, if no resource is found with that name, we log out message and do not crash the app).

chloekraw commented 5 years ago

Awesome, thanks @tobrun. That sounds like the ideal developer workflow for using images as icons.

stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] commented 4 years ago

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.