Class SpriteIndex


  • public class SpriteIndex
    extends Object
    Wrapper that takes the sprite index file (as a JSONObject) for a Mapbox Sprite Sheet and parses the all the individual icons as SpriteIndex.IconInfo objects. For example:
     
     {
        "goldfish": {
          "height": 32,
          "pixelRatio": 1,
          "width": 32,
          "x": 64,
          "y": 64
        },
        "owl": {
          "height": 64,
          "pixelRatio": 1,
          "width": 64,
          "x": 0,
          "y": 0
        }
     }
     
     
    See Also:
    https://www.mapbox.com/mapbox-gl-js/style-spec/#sprite
    • Constructor Detail

      • SpriteIndex

        public SpriteIndex​(String spriteIndexUrl,
                           JSONObject json)
        Parameters:
        spriteIndexUrl - The URL of the sprite index file (used for error messages).
        json - The sprite index file as a JSONObject.
    • Method Detail

      • parseIconInfoFromIndex

        protected static SpriteIndex.IconInfo parseIconInfoFromIndex​(JSONObject iconIndex,
                                                                     String iconName)
        Parse the SpriteIndex.IconInfo for the provided iconName in the provided icon index.
        Parameters:
        iconIndex - The icon index file.
        iconName - The name of the icon in the index file.
        Returns:
        An SpriteIndex.IconInfo for the icon.
      • getIcon

        public SpriteIndex.IconInfo getIcon​(String iconName)
        Get information about a single icon from the index
        Parameters:
        iconName - Name of the icon
        Returns:
        Info object describing the icons