Make changes suggested during the review

This commit is contained in:
Andreas Hocevar
2015-10-27 21:04:38 +01:00
parent 2b2ac47b1f
commit 5832943773
20 changed files with 237 additions and 156 deletions

View File

@@ -102,7 +102,7 @@ ol.featureloader.loadFeaturesXhr = function(url, format, success, failure) {
if (source) {
var features = format.readFeatures(source,
{featureProjection: projection});
if (success.length == 2) {
if (ol.ENABLE_VECTOR_TILE && success.length == 2) {
success.call(this, features, format.readProjection(source));
} else {
success.call(this, features);
@@ -171,5 +171,5 @@ ol.featureloader.xhr = function(url, format) {
*/
function(features) {
this.addFeatures(features);
}, ol.nullFunction);
}, /* FIXME handle error */ ol.nullFunction);
};

View File

@@ -107,7 +107,7 @@ ol.format.MVT.prototype.readFeature_ = function(
goog.asserts.assertInstanceof(geometry, ol.geom.Geometry);
values[this.geometryName_] = geometry;
}
feature.setProperties(rawFeature.properties);
feature.setProperties(values);
feature.setGeometryName(this.geometryName_);
return feature;
};
@@ -121,21 +121,9 @@ ol.format.MVT.prototype.readFeature_ = function(
*/
ol.format.MVT.prototype.readRenderFeature_ = function(rawFeature, layer) {
var coords = rawFeature.loadGeometry();
var end = 0;
var ends = [];
var flatCoordinates = [];
var line, coord;
for (var i = 0, ii = coords.length; i < ii; ++i) {
line = coords[i];
for (var j = 0, jj = line.length; j < jj; ++j) {
coord = line[j];
// Non-tilespace coords can be calculated here when a TileGrid and
// TileCoord are known.
flatCoordinates.push(coord.x, coord.y);
}
end += 2 * j;
ends.push(end);
}
ol.format.MVT.calculateFlatCoordinates_(coords, flatCoordinates, ends);
var type = rawFeature.type;
/** @type {ol.geom.GeometryType} */
@@ -149,15 +137,14 @@ ol.format.MVT.prototype.readRenderFeature_ = function(rawFeature, layer) {
} else {
geometryType = ol.geom.GeometryType.MULTI_LINE_STRING;
}
} else {
} else if (type === 3) {
geometryType = ol.geom.GeometryType.POLYGON;
}
var properties = rawFeature.properties;
properties[this.layerName_] = layer;
var values = rawFeature.properties;
values[this.layerName_] = layer;
return new this.featureClass_(
geometryType, flatCoordinates, ends, rawFeature.properties);
return new this.featureClass_(geometryType, flatCoordinates, ends, values);
};
@@ -180,7 +167,7 @@ ol.format.MVT.prototype.readFeatures = function(source, opt_options) {
}
layer = tile.layers[name];
for (var i = 0, ii = layer.length; i < layer.length; ++i) {
for (var i = 0, ii = layer.length; i < ii; ++i) {
if (featureClass === ol.render.Feature) {
feature = this.readRenderFeature_(layer.feature(i), name);
} else {
@@ -214,20 +201,14 @@ ol.format.MVT.prototype.setLayers = function(layers) {
/**
* @private
* @param {Object} rawFeature Raw Mapbox feature.
* @return {ol.geom.Geometry} Geometry.
* @param {Object} coords Raw feature coordinates.
* @param {Array.<number>} flatCoordinates Flat coordinates to be populated by
* this function.
* @param {Array.<number>} ends Ends to be populated by this function.
*/
ol.format.MVT.readGeometry_ = function(rawFeature) {
var type = rawFeature.type;
if (type === 0) {
return null;
}
var coords = rawFeature.loadGeometry();
ol.format.MVT.calculateFlatCoordinates_ = function(
coords, flatCoordinates, ends) {
var end = 0;
var ends = [];
var flatCoordinates = [];
var line, coord;
for (var i = 0, ii = coords.length; i < ii; ++i) {
line = coords[i];
@@ -240,6 +221,24 @@ ol.format.MVT.readGeometry_ = function(rawFeature) {
end += 2 * j;
ends.push(end);
}
};
/**
* @private
* @param {Object} rawFeature Raw Mapbox feature.
* @return {ol.geom.Geometry} Geometry.
*/
ol.format.MVT.readGeometry_ = function(rawFeature) {
var type = rawFeature.type;
if (type === 0) {
return null;
}
var coords = rawFeature.loadGeometry();
var ends = [];
var flatCoordinates = [];
ol.format.MVT.calculateFlatCoordinates_(coords, flatCoordinates, ends);
var geom;
if (type === 1) {
@@ -251,7 +250,7 @@ ol.format.MVT.readGeometry_ = function(rawFeature) {
} else {
geom = new ol.geom.MultiLineString(null);
}
} else {
} else if (type === 3) {
geom = new ol.geom.Polygon(null);
}

View File

@@ -253,7 +253,8 @@ ol.geom.Geometry.prototype.translate = goog.abstractMethod;
*/
ol.geom.Geometry.prototype.transform = function(source, destination) {
goog.asserts.assert(
ol.proj.get(source).getUnits() !== ol.proj.Units.TILE_PIXELS,
ol.proj.get(source).getUnits() !== ol.proj.Units.TILE_PIXELS &&
ol.proj.get(destination).getUnits() !== ol.proj.Units.TILE_PIXELS,
'cannot transform geometries with TILE_PIXELS units');
this.applyTransform(ol.proj.getTransform(source, destination));
return this;

View File

@@ -677,11 +677,8 @@ ol.proj.get = function(projectionLike) {
ol.proj.equivalent = function(projection1, projection2) {
if (projection1 === projection2) {
return true;
} else if (projection1.getCode() === projection2.getCode() &&
projection1.getUnits() === projection2.getUnits()) {
return true;
} else if (projection1.getUnits() != projection2.getUnits()) {
return false;
} else if (projection1.getCode() === projection2.getCode()) {
return projection1.getUnits() === projection2.getUnits();
} else {
var transformFn = ol.proj.getTransformFromProjections(
projection1, projection2);

View File

@@ -1180,6 +1180,10 @@ ol.render.canvas.PolygonReplay = function(tolerance, maxExtent, resolution) {
miterLimit: undefined
};
/**
* @private
* @type {boolean}
*/
this.rightHanded_ = false;
};

View File

@@ -86,7 +86,7 @@ ol.render.Feature.prototype.getEnds = function() {
* @api
*/
ol.render.Feature.prototype.getExtent = function() {
if (!goog.isDef(this.extent_)) {
if (!this.extent_) {
this.extent_ = this.type_ === ol.geom.GeometryType.POINT ?
ol.extent.createOrUpdateFromCoordinate(this.flatCoordinates_) :
ol.extent.createOrUpdateFromFlatCoordinates(

View File

@@ -86,7 +86,8 @@ ol.renderer.canvas.VectorTileLayer.prototype.composeFrame =
var projection = viewState.projection;
var resolution = viewState.resolution;
var rotation = viewState.rotation;
var source = this.getLayer().getSource();
var layer = this.getLayer();
var source = layer.getSource();
goog.asserts.assertInstanceof(source, ol.source.VectorTile,
'Source is an ol.source.VectorTile');
@@ -94,7 +95,6 @@ ol.renderer.canvas.VectorTileLayer.prototype.composeFrame =
this.dispatchPreComposeEvent(context, frameState, transform);
var layer = this.getLayer();
var replayContext;
if (layer.hasListener(ol.render.EventType.RENDER)) {
// resize and clear
@@ -160,10 +160,7 @@ ol.renderer.canvas.VectorTileLayer.prototype.composeFrame =
ol.renderer.canvas.VectorTileLayer.prototype.createReplayGroup = function(tile,
layer, pixelRatio) {
var revision = layer.getRevision();
var renderOrder = layer.getRenderOrder();
if (renderOrder === undefined) {
renderOrder = null;
}
var renderOrder = layer.getRenderOrder() || null;
var replayState = tile.getReplayState();
if (!replayState.dirty && replayState.renderedRevision == revision &&

View File

@@ -112,7 +112,7 @@ ol.source.UrlTile.prototype.getTileUrlFunction = function() {
/**
* Return the URLs used for this XYZ source.
* Return the URLs used for this source.
* When a tileUrlFunction is used instead of url or urls,
* null will be returned.
* @return {!Array.<string>|null} URLs.

View File

@@ -170,7 +170,7 @@ ol.VectorTile.prototype.setState = function(tileState) {
/**
* Set the feeature loader for reading this tile's features.
* Set the feature loader for reading this tile's features.
* @param {ol.FeatureLoader} loader Feature loader.
* @api
*/