Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ol.TileLoader.prototype._initTileLoader does not work with newer versions of OL #303

Open
senakafdo opened this issue Feb 11, 2019 · 0 comments

Comments

@senakafdo
Copy link

I have checked this code with OL 3.17.1 and it does work well. However, it does not work with OL 5.3.0. There are two issues.

  1. The way this is used in the code is not accurate, as it could be different within an event handler and in OL 5.3.0, they change it to something else. A better way would be to store a reference to this and use that instead.
  2. There is no longer a method called unByKey(). But, they support un() which works in OL 3.17.1 and also 5.3.0.
    The improvement below fixes the code such that it works on both OL 3.17.1 and 5.3.0.
ol.TileLoader.prototype._initTileLoader = function (map) {
    const _that = this;
    this._map = map;
    this._view = map.getView();
    this._centerChangedId = this._view.on('change:center', function (e) {
        _that._updateTiles();
    }, this);

    this._postcomposeKey = undefined;

    this._resolutionChangedId = this._view.on('change:resolution', function (evt) {
        _that._currentResolution = _that._view.getResolution();
        if (_that._postcomposeKey) return;
        _that.fire('mapZoomStart');
        _that._postcomposeKey = _that._map.on('postcompose', function (evt) {
            if (evt.frameState.viewState.resolution === _that._currentResolution) {
                _that._updateTiles();
                _that._map.un('postcompose', _that._postcomposeKey, _that);
                _that._postcomposeKey = undefined;
                _that.fire('mapZoomEnd');
            }
        }, _that);
    }, this);

    this._updateTiles();
};

I have however not tested this for versions in between these two. There is also widespread use of unByKey() in the code, which could be replaced with un().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant