From d6a8c9465e80254857d3dcc1a996237a360f53fd Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Fri, 15 Jan 2016 14:44:41 +0100 Subject: [PATCH] Make pixel projection handling work in compiled mode The compiler seems to have trouble with functions that can run with different 'this' types. By moving the units handling to the callback, this issue can be avoided. --- src/ol/featureloader.js | 27 ++++++++++++++------------- src/ol/vectortile.js | 1 + 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/ol/featureloader.js b/src/ol/featureloader.js index d74673fdc9..b47b3eff5d 100644 --- a/src/ol/featureloader.js +++ b/src/ol/featureloader.js @@ -104,18 +104,9 @@ ol.featureloader.loadFeaturesXhr = function(url, format, success, failure) { goog.asserts.fail('unexpected format type'); } if (source) { - if (ol.ENABLE_VECTOR_TILE && this instanceof ol.VectorTile) { - var dataUnits = format.readProjection(source).getUnits(); - if (dataUnits === ol.proj.Units.TILE_PIXELS) { - projection = new ol.proj.Projection({ - code: this.getProjection().getCode(), - units: dataUnits - }); - this.setProjection(projection); - } - } success.call(this, format.readFeatures(source, - {featureProjection: projection})); + {featureProjection: projection}), + format.readProjection(source)); } else { goog.asserts.fail('undefined or null source'); } @@ -147,9 +138,18 @@ ol.featureloader.tile = function(url, format) { return ol.featureloader.loadFeaturesXhr(url, format, /** * @param {Array.} features The loaded features. + * @param {ol.proj.Projection} dataProjection Data projection. * @this {ol.VectorTile} */ - function(features) { + function(features, dataProjection) { + var dataUnits = dataProjection.getUnits(); + if (dataUnits === ol.proj.Units.TILE_PIXELS) { + var projection = new ol.proj.Projection({ + code: this.getProjection().getCode(), + units: dataUnits + }); + this.setProjection(projection); + } this.setFeatures(features); }, /** @@ -174,9 +174,10 @@ ol.featureloader.xhr = function(url, format) { return ol.featureloader.loadFeaturesXhr(url, format, /** * @param {Array.} features The loaded features. + * @param {ol.proj.Projection} dataProjection Data projection. * @this {ol.source.Vector} */ - function(features) { + function(features, dataProjection) { this.addFeatures(features); }, /* FIXME handle error */ ol.nullFunction); }; diff --git a/src/ol/vectortile.js b/src/ol/vectortile.js index 6a493ba78a..ac1e28db34 100644 --- a/src/ol/vectortile.js +++ b/src/ol/vectortile.js @@ -161,6 +161,7 @@ ol.VectorTile.prototype.load = function() { /** * @param {Array.} features Features. + * @api */ ol.VectorTile.prototype.setFeatures = function(features) { this.features_ = features;