Skip to content

Commit

Permalink
feat(olHelpers): add support for tileLoadFunction and imageLoadFuncti…
Browse files Browse the repository at this point in the history
…on. (implements #273)

This enables the use of custom tileLoadFunction or imageLoadFunction, which is required, for
instance, to display cross-origin authenticated layers. For an example, see:
openlayers/openlayers#5401 (comment)
  • Loading branch information
lmillefiori authored and juristr committed Sep 22, 2016
1 parent 0beb753 commit 09d6cf5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/services/olHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $

oSource = new ol.source.XYZ({
url: url,
tileLoadFunction: source.tileLoadFunction,
attributions: createAttribution(source),
tilePixelRatio: pixelRatio > 1 ? 2 : 1
});
Expand All @@ -227,6 +228,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $

oSource = new ol.source.XYZ({
url: url,
tileLoadFunction: source.tileLoadFunction,
attributions: createAttribution(source),
tileSize: source.tileSize || [512, 512]
});
Expand All @@ -238,6 +240,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $
}
oSource = new ol.source.ImageWMS({
url: source.url,
imageLoadFunction: source.imageLoadFunction,
attributions: createAttribution(source),
crossOrigin: (typeof source.crossOrigin === 'undefined') ? 'anonymous' : source.crossOrigin,
params: deepCopy(source.params),
Expand All @@ -252,6 +255,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $
}

var wmsConfiguration = {
tileLoadFunction: source.tileLoadFunction,
crossOrigin: (typeof source.crossOrigin === 'undefined') ? 'anonymous' : source.crossOrigin,
params: deepCopy(source.params),
attributions: createAttribution(source)
Expand Down Expand Up @@ -279,6 +283,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $
}

var wmtsConfiguration = {
tileLoadFunction: source.tileLoadFunction,
projection: projection,
layer: source.layer,
attributions: createAttribution(source),
Expand Down Expand Up @@ -307,6 +312,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $

case 'OSM':
oSource = new ol.source.OSM({
tileLoadFunction: source.tileLoadFunction,
attributions: createAttribution(source)
});

Expand All @@ -323,6 +329,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $

var bingConfiguration = {
key: source.key,
tileLoadFunction: source.tileLoadFunction,
attributions: createAttribution(source),
imagerySet: source.imagerySet ? source.imagerySet : bingImagerySets[0],
culture: source.culture
Expand Down Expand Up @@ -359,6 +366,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $

oSource = new ol.source.XYZ({
attributions: createAttribution(source),
tileLoadFunction: source.tileLoadFunction,
url: _url
});

Expand All @@ -371,6 +379,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $

oSource = new ol.source.TileArcGISRest({
attributions: createAttribution(source),
tileLoadFunction: source.tileLoadFunction,
url: source.url
});

Expand Down Expand Up @@ -481,6 +490,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $
oSource = new ol.source.TileJSON({
url: source.url,
attributions: createAttribution(source),
tileLoadFunction: source.tileLoadFunction,
crossOrigin: 'anonymous'
});
break;
Expand All @@ -493,6 +503,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $
url: source.url,
projection: projection,
attributions: createAttribution(source),
tileLoadFunction: source.tileLoadFunction,
format: source.format,
tileGrid: new ol.tilegrid.createXYZ({
maxZoom: source.maxZoom || 19
Expand All @@ -508,6 +519,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $
url: source.url,
maxExtent: source.maxExtent,
attributions: createAttribution(source),
tileLoadFunction: source.tileLoadFunction,
tileGrid: new ol.tilegrid.TileGrid({
origin: source.tileGrid.origin,
resolutions: source.tileGrid.resolutions
Expand All @@ -532,6 +544,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $
oSource = new ol.source.TileImage({
url: source.url,
attributions: createAttribution(source),
tileLoadFunction: source.tileLoadFunction,
tileGrid: new ol.tilegrid.TileGrid({
origin: source.tileGrid.origin, // top left corner of the pixel projection's extent
resolutions: source.tileGrid.resolutions
Expand Down Expand Up @@ -563,6 +576,7 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $
return;
}
oSource = new ol.source.Stamen({
tileLoadFunction: source.tileLoadFunction,
layer: source.layer
});
break;
Expand Down Expand Up @@ -591,7 +605,8 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $
minZoom: source.minZoom,
maxZoom: source.maxZoom,
projection: source.projection,
tileUrlFunction: source.tileUrlFunction
tileUrlFunction: source.tileUrlFunction,
tileLoadFunction: source.tileLoadFunction
});
break;
case 'Zoomify':
Expand Down

0 comments on commit 09d6cf5

Please sign in to comment.