Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Fetch Tiles into PPouchDB</title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
    <script src="http://cdn.kendostatic.com/2013.1.514/js/kendo.all.min.js"></script>
    <script src="https://googledrive.com/host/0B2Ay-nw1QSW2SHhjR0VBZXE2bUU/PouchTest/xhr2lib.js"></script>
    <script src="https://googledrive.com/host/0B2Ay-nw1QSW2SHhjR0VBZXE2bUU/PouchTest/pouchdb-nightly.js"></script>
    <link href="http://cdn.kendostatic.com/2013.1.514/styles/kendo.common.min.css" rel="stylesheet" />
    <link href="http://cdn.kendostatic.com/2013.1.514/styles/kendo.metroblack.min.css" rel="stylesheet" />
    <link href="http://cdn.kendostatic.com/2013.1.514/styles/kendo.dataviz.metroblack.min.css" rel="stylesheet" />
</head>

<body>
    <div id="deleteDB" class="shadow k-button ">Delete Database</div>
    <div class="gap">&nbsp;</div>
    <div id="downloadButton" class="k-button shadow ">Download Tiles</div>
    <div class="gap">&nbsp;</div>
    <div class="CSSTableGenerator">
        <table>
            <tr>
                <td>Item
                </td>
                <td>Value
                </td>
            </tr>
            <tr>
                <td>Status
                </td>
                <td data-bind="text: status">xxx
                </td>
            </tr>
            <tr>
                <td>XHR2 Support
                </td>
                <td data-bind="text: xhr">xxx
                </td>
            </tr>
            <tr>
                <td>Base64 blobs
                </td>
                <td data-bind="text: b64Flag">xxx
                </td>
            </tr>
            <tr>
                <td>DB Manifest
                </td>
                <td data-bind="text: dbManifest">xxx
                </td>
            </tr>
            <tr>
                <td>Tile Count
                </td>
                <td data-bind="text: tileCount">xxx
                </td>
            </tr>
            <tr>
                <td>Start Time
                </td>
                <td data-bind="text: startTime">xxx
                </td>
            </tr>
            <tr>
                <td>Fetch Time
                </td>
                <td data-bind="text: fetchTime">xxx
                </td>
            </tr>
            <tr>
                <td>Blob Count
                </td>
                <td data-bind="text: blobCount">xxx
                </td>
            </tr>
            <tr>
                <td>Total Time
                </td>
                <td data-bind="text: totalTime">xxx
                </td>
            </tr>
                        <tr>
                <td>Blobs/sec
                </td>
                <td data-bind="text: blobRate">xxx
                </td>
            </tr>
        </table>
    </div>
    <h1>Sample Image Fetched From PouchDB</h1>
    <div class="gap">&nbsp;</div>
    <div id="imgBox">
        <img id="imgTile" alt="MAP not loaded YET">
    </div>
</body>
</html>

            
          
!
            
              html
{
    font: 14px "Verdana", "Helvetica", sans-serif;
    margin-left: 8px;
    height: 100%;
    background-image: linear-gradient(bottom, rgb(83,181,217) 17%, rgb(147,208,219) 59%);
    background-image: -o-linear-gradient(bottom, rgb(83,181,217) 17%, rgb(147,208,219) 59%);
    background-image: -moz-linear-gradient(bottom, rgb(83,181,217) 17%, rgb(147,208,219) 59%);
    background-image: -webkit-linear-gradient(bottom, rgb(83,181,217) 17%, rgb(147,208,219) 59%);
    background-image: -ms-linear-gradient(bottom, rgb(83,181,217) 17%, rgb(147,208,219) 59%);
    background-image: -webkit-gradient( linear, left bottom, left top, color-stop(0.17, rgb(83,181,217)), color-stop(0.59, rgb(147,208,219)) );
}

body {
  height: 100%;
  wdith: 100%;
}


.gap
{
    display: block;
    height: 10px;
}

.shadow
{
    box-shadow: 0 1px 7px rgba(0, 0, 0, 0.65);
}

#imgBox
{
    padding: 4px;
    width: 256px;
    height: 256px;
    box-shadow: 0 1px 7px rgba(0, 0, 0, 0.65);
}

#imgTile
{
    width: 100%;
    height: 100%;
}

.CSSTableGenerator
{
    margin: 0px;
    padding: 0px;
    width: 80%;
    box-shadow: 0 1px 7px rgba(0, 0, 0, 0.65);
    border: 1px solid #000000;
    -moz-border-radius-bottomleft: 0px;
    -webkit-border-bottom-left-radius: 0px;
    border-bottom-left-radius: 0px;
    -moz-border-radius-bottomright: 0px;
    -webkit-border-bottom-right-radius: 0px;
    border-bottom-right-radius: 0px;
    -moz-border-radius-topright: 0px;
    -webkit-border-top-right-radius: 0px;
    border-top-right-radius: 0px;
    -moz-border-radius-topleft: 0px;
    -webkit-border-top-left-radius: 0px;
    border-top-left-radius: 0px;
}

    .CSSTableGenerator table
    {
        width: 100%;
        height: 100%;
        margin: 0px;
        padding: 0px;
    }

    .CSSTableGenerator tr:last-child td:last-child
    {
        -moz-border-radius-bottomright: 0px;
        -webkit-border-bottom-right-radius: 0px;
        border-bottom-right-radius: 0px;
    }

    .CSSTableGenerator table tr:first-child td:first-child
    {
        -moz-border-radius-topleft: 0px;
        -webkit-border-top-left-radius: 0px;
        border-top-left-radius: 0px;
    }

    .CSSTableGenerator table tr:first-child td:last-child
    {
        -moz-border-radius-topright: 0px;
        -webkit-border-top-right-radius: 0px;
        border-top-right-radius: 0px;
    }

    .CSSTableGenerator tr:last-child td:first-child
    {
        -moz-border-radius-bottomleft: 0px;
        -webkit-border-bottom-left-radius: 0px;
        border-bottom-left-radius: 0px;
    }

    .CSSTableGenerator tr:hover td
    {
    }

    .CSSTableGenerator tr:nth-child(odd)
    {
        background-color: #aad4ff;
    }

    .CSSTableGenerator tr:nth-child(even)
    {
        background-color: #ffffff;
    }

    .CSSTableGenerator td
    {
        vertical-align: middle;
        border: 1px solid #000000;
        border-width: 0px 1px 1px 0px;
        text-align: left;
        padding: 8px;
        font-size: 14px;
        font-family: Verdana;
        font-weight: normal;
        color: #000000;
    }

    .CSSTableGenerator tr:last-child td
    {
        border-width: 0px 1px 0px 0px;
    }

    .CSSTableGenerator tr td:last-child
    {
        border-width: 0px 0px 1px 0px;
    }

    .CSSTableGenerator tr:last-child td:last-child
    {
        border-width: 0px 0px 0px 0px;
    }

    .CSSTableGenerator tr:first-child td
    {
        background: -o-linear-gradient(bottom, #005fbf 5%, #003f7f 100%);
        background: -webkit-gradient( linear, left top, left bottom, color-stop(0.05, #005fbf), color-stop(1, #003f7f) );
        background: -moz-linear-gradient( center top, #005fbf 5%, #003f7f 100% );
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#005fbf", endColorstr="#003f7f");
        background: -o-linear-gradient(top,#005fbf,003f7f);
        background-color: #005fbf;
        border: 0px solid #000000;
        text-align: center;
        border-width: 0px 0px 1px 1px;
        font-size: 16px;
        font-family: Verdana;
        font-weight: bold;
        color: #ffffff;
    }

    .CSSTableGenerator tr:first-child:hover td
    {
        background: -o-linear-gradient(bottom, #005fbf 5%, #003f7f 100%);
        background: -webkit-gradient( linear, left top, left bottom, color-stop(0.05, #005fbf), color-stop(1, #003f7f) );
        background: -moz-linear-gradient( center top, #005fbf 5%, #003f7f 100% );
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#005fbf", endColorstr="#003f7f");
        background: -o-linear-gradient(top,#005fbf,003f7f);
        background-color: #005fbf;
    }

    .CSSTableGenerator tr:first-child td:first-child
    {
        border-width: 0px 0px 1px 0px;
    }

    .CSSTableGenerator tr:first-child td:last-child
    {
        border-width: 0px 0px 1px 1px;
    }

1px 1px;
}

            
          
!
            
              var baseURL = "https://googledrive.com/host/0B2Ay-nw1QSW2SHhjR0VBZXE2bUU/TinyBlueMarble/";

var DBNAME = "MapTiles";
var DB = null;
var manifest = null;
var vm = null;
var showID = "4-9-6";
var fetchCnt = 0;
var imageType = "jpg";
var maxTiles = 999999;

window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
if (!window.indexedDB) {
    window.alert("Your browser doesn't support a stable version of IndexedDB.");
}

// executed when all js and css is loaded (i.e. document ready event)
$(function () {
    makeVM();
    vm.set("status", "Initializing");
    testXHR();
    testBase64();
    openDB();
    setup();
});

function makeVM() {
    vm = kendo.observable({
        status: "",
        xhr: false,
        b64Flag: false,
        dbManifest: false,
        tileCount: 0,
        startTime: "",
        fetchTime: "0",
        blobCount: 0,
        totalTime: "0",
        blobRate: 0
    });
    kendo.bind(document.body, vm);
}

function testXHR() {
    vm.set("xhr", $xhr.supported());
}

function testBase64() {
    var b64Flag = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
    vm.set("b64Flag", b64Flag);
}

function setup() {
    $("#deleteDB").click(deleteDB);
    $("#downloadButton").click(download);
    $xhr.defaultError(function (text, code) {
        console.error("xhr2 error: ", text, " code: ", code, " url: ", this.xhr2data.url);
    });
}

function openDB() {
    DB = Pouch(DBNAME);
    DB.get("MANIFEST", function (err, doc) {
        if (err) {
            console.error("Manifest fetch error: ", err.error, " reason: ", err.reason, " status: ", err.status);
            manifest = null;
            vm.set("dbManifest", false);
            getManifest();
        } else {
            manifest = doc.data;
            vm.set("dbManifest", true);
            vm.set("tileCount", manifest.files.length);
            vm.set("status", "Ready");
        }
    });
}

function deleteDB() {
    Pouch.destroy(DBNAME, function (err, info) {
        if (err) {
            console.error("Could not Delete DB: ", info);
        } else {
            console.log("db deleted");
            vm.set("dbManifest", false);
        }
    });
    manifest = null;
    vm.set("tileCount", 0);
    vm.set("status", "Reload");
}

function getManifest() {
    $xhr.ajax({
        url: baseURL + "manifest.json",
        dataType: "json",
        success: parseManifest
    });
}

function parseManifest(data) {
    data.files = data.files.slice(0, maxTiles - 1);
    manifest = data;
    DB.put({ _id: "MANIFEST", data: data }, function (err, response) {
        if (err) {
            console.error("Could store MANIFEST: error: " + err.error + " reason: " + err.reason + " status: " + err.status);
        } else {
            console.log("saved: ", response.id + " rev: " + response.rev);
            vm.set("dbManifest", true);
        }
    });
    vm.set("tileCount", manifest.files.length);
    vm.set("status", "Ready");
}

function download() {
    if (manifest == null) {
        alert("No Manifest, reload");
        return;
    }
    fetchCnt = 0;
    vm.set("blobCount", 0);
    vm.set("startTime", new Date());
    vm.set("fetchTime", "0");
    getBlobs(manifest.files);
}

function getBlobs(fileList) {
    console.log("starting to fetch blobs");
    $.each(fileList, function (i, val) {
        var path = baseURL + val.id + "." + imageType;
        $xhr.ajax({
            url: path,
            dataType: "blob",
            success: function (data) { saveBlob(data, val.size, val.id); }
        });
    });
}

function saveBlob(blob, length, id) {
    if (blob.size != length) {
        console.error("Blob Length found: ", blob.size, " expected: ", length);
    }
    putBlob(blob, id);
    ++fetchCnt;
    if (fetchCnt == manifest.files.length) {
        setTimeout(fetchComplete, 0);
    }
}

function fetchComplete() {
    var startTime = vm.get("startTime");
    var elapsed = new Date() - startTime;
    var fetchTime = ms2Time(elapsed);
    vm.set("fetchTime", fetchTime);
    console.log("Done Fetching Tiles");
}

function putBlob(blob, id) {
    var cnt;
    var type = blob.type;
    DB.putAttachment(id + "/pic", blob, type, function (err, response) {
        if (err) {
            console.error("Could store blob: error: " + err.error + " reason: " + err.reason + " status: " + err.status);
        } else {
            console.log("saved: ", response.id + " rev: " + response.rev);
            cnt = vm.get("blobCount");
            vm.set("blobCount", ++cnt);
            if (cnt == manifest.files.length) {
                setTimeout(storeComplete, 0);
            }
        }
    });
}

function storeComplete() {
    console.log("Done Storing Tiles");
    var startTime = vm.get("startTime");
    var elapsed = new Date() - startTime;
    var totalTime = ms2Time(elapsed);
    vm.set("totalTime", totalTime);
    var rate = manifest.files.length * 1000 / elapsed;
    vm.set("blobRate", rate);
    setImage();
}

function setImage() {
    var id = showID;
    var blob;
    DB.getAttachment(id + "/pic", function (err, response) {
        if (err) {
            console.error("Could find blob id: ", id, " error: ", err.error, " reason: ", err.reason, " status: ", err.status);
        } else {
            blob = response;
            var imgURL = URL.createObjectURL(blob);
            // Set img src to ObjectURL
            $("#imgTile").attr("src", imgURL);
            // Revoking ObjectURL
            URL.revokeObjectURL(imgURL);
        }
    });
}

function ms2Time(ms) {
    var secs = ms / 1000;
    ms = Math.floor(ms % 1000);
    var minutes = secs / 60;
    secs = Math.floor(secs % 60);
    var hours = minutes / 60;
    minutes = Math.floor(minutes % 60);
    hours = Math.floor(hours % 24);
    return hours + ":" + minutes + ":" + secs + "." + ms;
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console