Merge pull request #4518 from ahocevar/osm-vector-tiles
Add support for OSM vector tiles
This commit is contained in:
@@ -9,6 +9,9 @@ goog.require('goog.net.XhrIo');
|
||||
goog.require('goog.net.XhrIo.ResponseType');
|
||||
goog.require('ol.TileState');
|
||||
goog.require('ol.format.FormatType');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.proj.Projection');
|
||||
goog.require('ol.proj.Units');
|
||||
goog.require('ol.xml');
|
||||
|
||||
|
||||
@@ -100,12 +103,21 @@ ol.featureloader.loadFeaturesXhr = function(url, format, success, failure) {
|
||||
goog.asserts.fail('unexpected format type');
|
||||
}
|
||||
if (source) {
|
||||
var features = format.readFeatures(source,
|
||||
{featureProjection: projection});
|
||||
if (ol.ENABLE_VECTOR_TILE && success.length == 2) {
|
||||
success.call(this, features, format.readProjection(source));
|
||||
var dataProjection = format.readProjection(source);
|
||||
var units = dataProjection.getUnits();
|
||||
if (units === ol.proj.Units.TILE_PIXELS) {
|
||||
projection = new ol.proj.Projection({
|
||||
code: projection.getCode(),
|
||||
units: units
|
||||
});
|
||||
this.setProjection(projection);
|
||||
}
|
||||
success.call(this, format.readFeatures(source,
|
||||
{featureProjection: projection}), dataProjection);
|
||||
} else {
|
||||
success.call(this, features);
|
||||
success.call(this, format.readFeatures(source,
|
||||
{featureProjection: projection}));
|
||||
}
|
||||
} else {
|
||||
goog.asserts.fail('undefined or null source');
|
||||
@@ -142,7 +154,9 @@ ol.featureloader.tile = function(url, format) {
|
||||
* @this {ol.VectorTile}
|
||||
*/
|
||||
function(features, projection) {
|
||||
this.setProjection(projection);
|
||||
if (ol.proj.equivalent(projection, this.getProjection())) {
|
||||
this.setProjection(projection);
|
||||
}
|
||||
this.setFeatures(features);
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -677,12 +677,14 @@ ol.proj.get = function(projectionLike) {
|
||||
ol.proj.equivalent = function(projection1, projection2) {
|
||||
if (projection1 === projection2) {
|
||||
return true;
|
||||
} else if (projection1.getCode() === projection2.getCode()) {
|
||||
return projection1.getUnits() === projection2.getUnits();
|
||||
}
|
||||
var equalUnits = projection1.getUnits() === projection2.getUnits();
|
||||
if (projection1.getCode() === projection2.getCode()) {
|
||||
return equalUnits;
|
||||
} else {
|
||||
var transformFn = ol.proj.getTransformFromProjections(
|
||||
projection1, projection2);
|
||||
return transformFn === ol.proj.cloneTransform;
|
||||
return transformFn === ol.proj.cloneTransform && equalUnits;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ ol.source.VectorTile = function(options) {
|
||||
/**
|
||||
* @protected
|
||||
* @type {function(new: ol.VectorTile, ol.TileCoord, ol.TileState, string,
|
||||
* ol.format.Feature, ol.TileLoadFunctionType)}
|
||||
* ol.format.Feature, ol.TileLoadFunctionType, ol.proj.Projection)}
|
||||
*/
|
||||
this.tileClass = options.tileClass ? options.tileClass : ol.VectorTile;
|
||||
|
||||
@@ -83,8 +83,7 @@ ol.source.VectorTile.prototype.getTile =
|
||||
tileCoord,
|
||||
tileUrl !== undefined ? ol.TileState.IDLE : ol.TileState.EMPTY,
|
||||
tileUrl !== undefined ? tileUrl : '',
|
||||
this.format_,
|
||||
this.tileLoadFunction);
|
||||
this.format_, this.tileLoadFunction, projection);
|
||||
goog.events.listen(tile, goog.events.EventType.CHANGE,
|
||||
this.handleTileChange, false, this);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ goog.require('ol.Tile');
|
||||
goog.require('ol.TileCoord');
|
||||
goog.require('ol.TileLoadFunctionType');
|
||||
goog.require('ol.TileState');
|
||||
goog.require('ol.proj.Projection');
|
||||
|
||||
|
||||
/**
|
||||
@@ -25,8 +26,10 @@ 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) {
|
||||
ol.VectorTile =
|
||||
function(tileCoord, state, src, format, tileLoadFunction, projection) {
|
||||
|
||||
goog.base(this, tileCoord, state);
|
||||
|
||||
@@ -52,7 +55,7 @@ ol.VectorTile = function(tileCoord, state, src, format, tileLoadFunction) {
|
||||
* @private
|
||||
* @type {ol.proj.Projection}
|
||||
*/
|
||||
this.projection_ = null;
|
||||
this.projection_ = projection;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -124,7 +127,7 @@ ol.VectorTile.prototype.getKey = function() {
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.proj.Projection} Projection.
|
||||
* @return {ol.proj.Projection} Feature projection.
|
||||
*/
|
||||
ol.VectorTile.prototype.getProjection = function() {
|
||||
return this.projection_;
|
||||
@@ -138,7 +141,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, null);
|
||||
this.loader_(null, NaN, this.projection_);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -153,7 +156,7 @@ ol.VectorTile.prototype.setFeatures = function(features) {
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @param {ol.proj.Projection} projection Feature projection.
|
||||
*/
|
||||
ol.VectorTile.prototype.setProjection = function(projection) {
|
||||
this.projection_ = projection;
|
||||
|
||||
Reference in New Issue
Block a user