You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
setSprite does not handle scales <1.0x or >2.0x #2506
As I discovered while working on #2440 the current core setSprite function is not flexible enough for the needs of Android. @friedbunny also noted that 3x needed for new iOS devices is also not supported.
The scale parameter crashes if you pass it <1.0 or >2.0. Android needs to support at least up to 4.0 (currently - future devices can increase this) and below 1.0.
A below 1.0 case might be where a developer only includes hdpi bitmaps assets, then a user runs the app on a ldpi or mdpi phone. In this case we need to scale down.
There are two ways I can see to fix this:
scale the Bitmap to the correct 1x or 2x sprite texture size using the CPU - will result in blurry markers on higher DPI devices
make sprites scale independent by storing them in their native resolution in the texture, then using the vertex shader to scale them on the CPU
@bleege Until this bug is fixed I think in v2.1.0 and forwards we should make setSprite private. There could be big changes to the way this function works and I think it would be easier to not support for the moment. Developers can still use the Maki sprites from the styles just like Sirius does.
A workaround pending a Core GL refactor might be to override the Android platforms default Bitmap DPI selection and just force load a 1x or 2x sprite as required, essentially copying iOS.
Can use getResources().getDrawableForDensity(id, density); for this. mdpi = 1x, xhdpi = 2x
I think the confusion is that the iOS SDK used to allow you to name a sprite from the style’s sprite sheet. That’s no longer the case and to my knowledge no longer supported by mbgl.
No, this API is what the platform clients use to set runtime marker imagery, i.e. rasters as textures outside of the stock style resources.
Agreed @incanus. The confusion was around the statement that "Developers can still use the Maki sprites from the styles just like Sirius does." This means using Style Specific Sprites that are in the Style Sprite JSON Sheets and not Maki icons in their traditional sense.
Activity
ljbade commentedon Oct 3, 2015
@bleege Until this bug is fixed I think in v2.1.0 and forwards we should make
setSpriteprivate. There could be big changes to the way this function works and I think it would be easier to not support for the moment. Developers can still use the Maki sprites from the styles just like Sirius does.ljbade commentedon Oct 12, 2015
A workaround pending a Core GL refactor might be to override the Android platforms default Bitmap DPI selection and just force load a 1x or 2x sprite as required, essentially copying iOS.
Can use
getResources().getDrawableForDensity(id, density);for this.mdpi= 1x,xhdpi= 2xbleege commentedon Oct 14, 2015
Just to clarify, that for Android this means loading a Style specific sprite from the sprite style sheet. For example, with Emerald style this means that the image has to be in https://github.com/mapbox/mapbox-gl-styles/blob/mb-pages/sprites/emerald.json.
incanus commentedon Oct 14, 2015
No, this API is what the platform clients use to set runtime marker imagery, i.e. rasters as textures outside of the stock style resources.
1ec5 commentedon Oct 14, 2015
I think the confusion is that the iOS SDK used to allow you to name a sprite from the style’s sprite sheet. That’s no longer the case and to my knowledge no longer supported by mbgl.
bleege commentedon Oct 14, 2015
Agreed @incanus. The confusion was around the statement that "Developers can still use the Maki sprites from the styles just like Sirius does." This means using Style Specific Sprites that are in the Style Sprite JSON Sheets and not Maki icons in their traditional sense.
ljbade commentedon Oct 14, 2015
@1ec5 Wait a minute, you mean iOS no longer allows you to specify a String as the sprite? It only allows loading from a provided Bitmap?
2 remaining items
jfirebaugh commentedon Oct 16, 2015
@ljbade What
scaleparameter are you referring to? Can you link to code? Also, can you post a stack trace of the crash?ljbade commentedon Oct 21, 2015
@jfirebaugh Sorry
spriteis the parameter on the Java side.In C++ side it is the
pixelRatioofSpriteImageclass.ljbade commentedon Oct 21, 2015
@jfirebaugh here is the stack trace:
ljbade commentedon Oct 21, 2015
After looking closer at the crash log ^ I realised C++ was throwing an exception because the expected pixel data size, and actual size did not match.
Turns out there was a bug in the JNI for
setSprite.After fixing I now get the default sprite marker loading correctly:

Next steps are to refactor the Marker APIs to take Bitmaps (or perhaps a object to manage loaded sprites) instead of Strings.
@friedbunny Seems to me like it should be possible to load iOS 3x bitmaps?
/cc @bleege @jfirebaugh
ljbade commentedon Oct 21, 2015
The fix:
e149fb8
jfirebaugh commentedon Oct 21, 2015
@ljbade So can this be closed?
ljbade commentedon Oct 22, 2015
@jfirebaugh Once I get that branch merged. Currently waiting on 2.1.0 release branch to be merged into master.
[android] Fix bug in setSprite when calculating pixel data size
[android] Fix bug in setSprite when calculating pixel data size