Skip to content

Examples

Tom edited this page Jul 14, 2021 · 3 revisions

Examples

Read a file from an input

To read a file from a simple input convert the target file from the input to a Uint8Array asynchronously.

<input type="file" id="myFile">
document.querySelector("#myFile").addEventListener("change", e => {
    let file = e.target.files[0];
    var myGBX = new GBX({
        data: file,
        onParse: function(e) {
            console.log(e)
        }
    })
}); 

Display thumbnail

To display the map thumbnail, first consider if there is any to not throw an error. Convert the Uint8Array to Base64 and include it in an image src for example. Note, that the map thumbnail is explicitly in jpg format.

var gbx = new GBX({
    //...
    thumbnail: "base64"
})
if(metadata.thumbnailSize > 0) {
    document.querySelector("img").src = "data:image/jpg;base64," + metadata.thumbnail;
}
Clone this wiki locally