These are chat archives for openseadragon/openseadragon

10th
Mar 2016
Jeremy Shipman
@jedateach
Mar 10 2016 04:57
@foobarable @avandecreme - Here's my rough, but working implementation:
    function buildHash (bounds) {
        return [bounds.x, bounds.y, bounds.width, bounds.height].toString();
    }

    function parseHash (hash) {
        var parts = hash.substr(1).split(',');
        parts = parts.map(function (part) {
            return Number.parseFloat(part);
        });
        console.log(parts);
        if (parts.length !== 4) {
            return null;
        }
        return new OSD.Rect(parts[0], parts[1], parts[2], parts[3]);
    }

    viewer.addHandler('open', function () {
        var hashBounds = parseHash(window.location.hash);
        if (hashBounds) {
            viewer.viewport.fitBounds(hashBounds, true);
            console.log('setting', hashBounds);
        }
    });

    // TODO: debounce this by 10ms approx
    viewer.addHandler('viewport-change', function (e) {
        var hashBounds = e.eventSource.viewport.getBounds();
        if (!isNaN(hashBounds.x)) {
            window.location.hash = buildHash(hashBounds);
        }
    });
foobarable
@foobarable
Mar 10 2016 07:52
@jedateach looks good. I'll have to implement it in the angular wrapper though
Antoine Vandecreme
@avandecreme
Mar 10 2016 14:27
@jedateach @foobarable It probably won't work well with angular because it is using the hash. Using a query parameter seems more resilient to me. Looks good otherwise. What about making it a plugin? :)