Mapbox-gl-js: Any support for adding base64 image rather than by url

Created on 3 Mar 2017  路  1Comment  路  Source: mapbox/mapbox-gl-js

Right now, it seems that adding an image overlay requires an image url

"overlay": {
            "type": "image",
            "url": "https://www.mapbox.com/mapbox-gl-js/assets/radar.gif",
            "coordinates": [
                [-80.425, 46.437],
                [-71.516, 46.437],
                [-71.516, 37.936],
                [-80.425, 37.936]
            ]
        }

However, what if i have the image as a base64 string, is that anyway i can add it rather than from a url?

thanks

Most helpful comment

i managed to get this to work using

img = new Image
img.src = "data:image/png;base64," + image
img.onload = (e) ->
        map.addSource('image', {
          coordinates,
          type:         'image'
          url:          "data:image/png;base64," + image
        })

maybe useful to add this to documentation?

>All comments

i managed to get this to work using

img = new Image
img.src = "data:image/png;base64," + image
img.onload = (e) ->
        map.addSource('image', {
          coordinates,
          type:         'image'
          url:          "data:image/png;base64," + image
        })

maybe useful to add this to documentation?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rigoneri picture rigoneri  路  3Comments

foundryspatial-duncan picture foundryspatial-duncan  路  3Comments

muesliq picture muesliq  路  3Comments

samanpwbb picture samanpwbb  路  3Comments

yoursweater picture yoursweater  路  3Comments