Untangle vector tile feature reprojection

This commit is contained in:
Andreas Hocevar
2016-01-27 00:42:51 +01:00
parent 682e65fead
commit 483376deb2
6 changed files with 76 additions and 39 deletions

View File

@@ -12,7 +12,6 @@ goog.require('ol.VectorTile');
goog.require('ol.format.FormatType');
goog.require('ol.proj');
goog.require('ol.proj.Projection');
goog.require('ol.proj.Units');
goog.require('ol.xml');
@@ -142,14 +141,7 @@ ol.featureloader.tile = function(url, format) {
* @this {ol.VectorTile}
*/
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.setProjection(dataProjection);
this.setFeatures(features);
},
/**

View File

@@ -41,7 +41,7 @@ ol.format.MVT = function(opt_options) {
* @type {ol.proj.Projection}
*/
this.defaultDataProjection = new ol.proj.Projection({
code: 'EPSG:3857',
code: '',
units: ol.proj.Units.TILE_PIXELS
});

View File

@@ -13,6 +13,7 @@ goog.require('ol.dom');
goog.require('ol.extent');
goog.require('ol.geom.flat.transform');
goog.require('ol.layer.VectorTile');
goog.require('ol.proj');
goog.require('ol.proj.Units');
goog.require('ol.render.EventType');
goog.require('ol.render.canvas.ReplayGroup');
@@ -205,9 +206,10 @@ ol.renderer.canvas.VectorTileLayer.prototype.composeFrame = function(frameState,
* @param {ol.VectorTile} tile Tile.
* @param {ol.layer.VectorTile} layer Vector tile layer.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
*/
ol.renderer.canvas.VectorTileLayer.prototype.createReplayGroup = function(tile,
layer, pixelRatio) {
layer, pixelRatio, projection) {
var revision = layer.getRevision();
var renderOrder = layer.getRenderOrder() || null;
@@ -227,14 +229,19 @@ ol.renderer.canvas.VectorTileLayer.prototype.createReplayGroup = function(tile,
'Source is an ol.source.VectorTile');
var tileGrid = source.getTileGrid();
var tileCoord = tile.getTileCoord();
var pixelSpace = tile.getProjection().getUnits() == ol.proj.Units.TILE_PIXELS;
var extent;
var tileProjection = tile.getProjection();
var pixelSpace = tileProjection.getUnits() == ol.proj.Units.TILE_PIXELS;
var extent, reproject;
if (pixelSpace) {
var tilePixelSize = source.getTilePixelSize(tileCoord[0], pixelRatio,
tile.getProjection());
extent = [0, 0, tilePixelSize[0], tilePixelSize[1]];
} else {
extent = tileGrid.getTileCoordExtent(tileCoord);
if (!ol.proj.equivalent(projection, tileProjection)) {
reproject = true;
tile.setProjection(projection);
}
}
var resolution = tileGrid.getResolution(tileCoord[0]);
var tileResolution =
@@ -276,7 +283,14 @@ ol.renderer.canvas.VectorTileLayer.prototype.createReplayGroup = function(tile,
if (renderOrder && renderOrder !== replayState.renderedRenderOrder) {
features.sort(renderOrder);
}
features.forEach(renderFeature, this);
var feature;
for (var i = 0, ii = features.length; i < ii; ++i) {
feature = features[i];
if (reproject) {
feature.getGeometry().transform(tileProjection, projection);
}
renderFeature.call(this, feature);
}
replayGroup.finish();
@@ -464,7 +478,7 @@ ol.renderer.canvas.VectorTileLayer.prototype.prepareFrame = function(frameState,
tile = tilesToDraw[tileCoordKey];
if (tile.getState() == ol.TileState.LOADED) {
replayables.push(tile);
this.createReplayGroup(tile, layer, pixelRatio);
this.createReplayGroup(tile, layer, pixelRatio, projection);
}
}
}

View File

@@ -1,6 +1,5 @@
goog.provide('ol.source.VectorTile');
goog.require('goog.asserts');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('ol.TileState');
@@ -54,7 +53,7 @@ ol.source.VectorTile = function(options) {
/**
* @protected
* @type {function(new: ol.VectorTile, ol.TileCoord, ol.TileState, string,
* ol.format.Feature, ol.TileLoadFunctionType, ol.proj.Projection)}
* ol.format.Feature, ol.TileLoadFunctionType)}
*/
this.tileClass = options.tileClass ? options.tileClass : ol.VectorTile;
@@ -70,7 +69,6 @@ ol.source.VectorTile.prototype.getTile = function(z, x, y, pixelRatio, projectio
if (this.tileCache.containsKey(tileCoordKey)) {
return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
} else {
goog.asserts.assert(projection, 'argument projection is truthy');
var tileCoord = [z, x, y];
var urlTileCoord = this.getTileCoordForTileUrlFunction(
tileCoord, projection);
@@ -80,7 +78,7 @@ ol.source.VectorTile.prototype.getTile = function(z, x, y, pixelRatio, projectio
tileCoord,
tileUrl !== undefined ? ol.TileState.IDLE : ol.TileState.EMPTY,
tileUrl !== undefined ? tileUrl : '',
this.format_, this.tileLoadFunction, projection);
this.format_, this.tileLoadFunction);
goog.events.listen(tile, goog.events.EventType.CHANGE,
this.handleTileChange, false, this);

View File

@@ -26,9 +26,8 @@ ol.TileReplayState;
* @param {string} src Data source url.
* @param {ol.format.Feature} format Feature format.
* @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function.
* @param {ol.proj.Projection} projection Feature projection.
*/
ol.VectorTile = function(tileCoord, state, src, format, tileLoadFunction, projection) {
ol.VectorTile = function(tileCoord, state, src, format, tileLoadFunction) {
goog.base(this, tileCoord, state);
@@ -57,10 +56,11 @@ ol.VectorTile = function(tileCoord, state, src, format, tileLoadFunction, projec
this.loader_;
/**
* Data projection
* @private
* @type {ol.proj.Projection}
*/
this.projection_ = projection;
this.projection_;
/**
* @private
@@ -154,7 +154,7 @@ ol.VectorTile.prototype.load = function() {
if (this.state == ol.TileState.IDLE) {
this.setState(ol.TileState.LOADING);
this.tileLoadFunction_(this, this.url_);
this.loader_(null, NaN, this.projection_);
this.loader_(null, NaN, null);
}
};