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

Asynchronos tile URL calculation #1036

Merged
merged 7 commits into from Sep 20, 2013
Merged

Conversation

twpayne
Copy link
Contributor

@twpayne twpayne commented Sep 18, 2013

This PR, developed with @elemoine and @vmx, allows the way that tiles are loaded to be overridden. This allows tile URLs to be generated asynchronously, as requested by @vmx in #792. This functionality is needed to eventually support tiles accessed with JavaScripts File API, or tiles stored in some databases, such as PouchDB.

As a demonstration of its use, here a one second setTimeout is used to simulate asynchronous tile URL lookup:

var map = new ol.Map({
  layers: [
    new ol.layer.Tile({
      source: new ol.source.XYZ({
        tileLoadFunction: function(imageTile, src) {
          window.setTimeout(function() {
            imageTile.getImage().src = src;
          }, 1);
        },
        url: 'http://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'
      })
    })
  ]
  // ...
});

@twpayne twpayne mentioned this pull request Sep 18, 2013
@fredj
Copy link
Member

fredj commented Sep 19, 2013

This option should be available for all the ol.source.TileImage based classes (not only ol.source.XYZ) but this can be done later.

@fredj
Copy link
Member

fredj commented Sep 19, 2013

FYI I've backported my ol2 pointillism hack to ol3: http://fredj.io/ol/pointillism/pointillism.html

@elemoine
Copy link
Member

@fredj very nice. I'm interested to know why you need to call removeAttribute('crossorigin') on the image.

@twpayne
Copy link
Contributor Author

twpayne commented Sep 19, 2013

Very cool demo @fredj!

@fredj
Copy link
Member

fredj commented Sep 19, 2013

@fredj very nice. I'm interested to know why you need to call removeAttribute('crossorigin') on the image.

Good question: the img is configured with crossOrigin = anonymous (in ol.source.OSM). At first, the src is set to a remote image (pointillism.js line 30) but inside the tileLoadFunction function the src is set again using canvas.toDataURL(): because this second image is not CORS enabled (see https://developer.mozilla.org/en-US/docs/HTML/CORS_Enabled_Image) a security error would be raised.

twpayne added a commit that referenced this pull request Sep 20, 2013
Asynchronos tile URL calculation
@twpayne twpayne merged commit a8d9dad into openlayers:master Sep 20, 2013
@twpayne twpayne deleted the async-tile-load branch September 20, 2013 09:23
afabiani pushed a commit to geosolutions-it/openlayers that referenced this pull request Nov 7, 2017
singleTile overlays repeating when base layer has wrapDateLine false. r=@bartvde
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

Successfully merging this pull request may close these issues.

None yet

3 participants