Use a ReadFeatures object instead of sourceProjection/targetProjection
This commit is contained in:
@@ -1144,6 +1144,29 @@ olx.control.ZoomToExtentOptions.prototype.tipLabel;
|
|||||||
olx.control.ZoomToExtentOptions.prototype.extent;
|
olx.control.ZoomToExtentOptions.prototype.extent;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{dataProjection: (ol.proj.ProjectionLike|undefined),
|
||||||
|
* featureProjection: (ol.proj.ProjectionLike|undefined)}}
|
||||||
|
*/
|
||||||
|
olx.format.ReadOptions;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Projection of the data we are reading. Default is the projection derived from
|
||||||
|
* the data.
|
||||||
|
* @type {ol.proj.ProjectionLike|undefined}
|
||||||
|
*/
|
||||||
|
olx.format.ReadOptions.prototype.dataProjection;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Projection of the feature geometries created by the format reader. Default
|
||||||
|
* is the `dataProjection`.
|
||||||
|
* @type {ol.proj.ProjectionLike|undefined}
|
||||||
|
*/
|
||||||
|
olx.format.ReadOptions.prototype.featureProjection;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{defaultProjection: ol.proj.ProjectionLike,
|
* @typedef {{defaultProjection: ol.proj.ProjectionLike,
|
||||||
* geometryName: (string|undefined)}}
|
* geometryName: (string|undefined)}}
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ ol.format.Feature.prototype.getType = goog.abstractMethod;
|
|||||||
* Read a single feature from a source.
|
* Read a single feature from a source.
|
||||||
*
|
*
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_targetProjection Target projection.
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_sourceProjection Source projection.
|
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
*/
|
*/
|
||||||
ol.format.Feature.prototype.readFeature = goog.abstractMethod;
|
ol.format.Feature.prototype.readFeature = goog.abstractMethod;
|
||||||
@@ -46,8 +45,7 @@ ol.format.Feature.prototype.readFeature = goog.abstractMethod;
|
|||||||
* Read all features from a source.
|
* Read all features from a source.
|
||||||
*
|
*
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_targetProjection Target projection.
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_sourceProjection Source projection.
|
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
*/
|
*/
|
||||||
ol.format.Feature.prototype.readFeatures = goog.abstractMethod;
|
ol.format.Feature.prototype.readFeatures = goog.abstractMethod;
|
||||||
@@ -57,8 +55,7 @@ ol.format.Feature.prototype.readFeatures = goog.abstractMethod;
|
|||||||
* Read a single geometry from a source.
|
* Read a single geometry from a source.
|
||||||
*
|
*
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_targetProjection Target projection.
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_sourceProjection Source projection.
|
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
*/
|
*/
|
||||||
ol.format.Feature.prototype.readGeometry = goog.abstractMethod;
|
ol.format.Feature.prototype.readGeometry = goog.abstractMethod;
|
||||||
|
|||||||
@@ -64,22 +64,26 @@ ol.format.GeoJSON.EXTENSIONS_ = ['.geojson'];
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {GeoJSONObject} object Object.
|
* @param {GeoJSONObject} object Object.
|
||||||
* @param {ol.proj.Projection} targetProjection Target projection.
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @param {ol.proj.Projection} sourceProjection Source projection.
|
|
||||||
* @private
|
* @private
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.readGeometry_ = function(
|
ol.format.GeoJSON.readGeometry_ = function(object, opt_options) {
|
||||||
object, targetProjection, sourceProjection) {
|
|
||||||
if (goog.isNull(object)) {
|
if (goog.isNull(object)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
var featureProjection = goog.isDef(opt_options) &&
|
||||||
|
goog.isDef(opt_options.featureProjection) ?
|
||||||
|
ol.proj.get(opt_options.featureProjection) : null;
|
||||||
|
var dataProjection = goog.isDef(opt_options) &&
|
||||||
|
goog.isDef(opt_options.dataProjection) ?
|
||||||
|
ol.proj.get(opt_options.dataProjection) : null;
|
||||||
var geometryReader = ol.format.GeoJSON.GEOMETRY_READERS_[object.type];
|
var geometryReader = ol.format.GeoJSON.GEOMETRY_READERS_[object.type];
|
||||||
goog.asserts.assert(goog.isDef(geometryReader));
|
goog.asserts.assert(goog.isDef(geometryReader));
|
||||||
var geometry = geometryReader(object);
|
var geometry = geometryReader(object);
|
||||||
if (!goog.isNull(targetProjection) && !goog.isNull(sourceProjection) &&
|
if (!goog.isNull(featureProjection) && !goog.isNull(dataProjection) &&
|
||||||
!ol.proj.equivalent(targetProjection, sourceProjection)) {
|
!ol.proj.equivalent(featureProjection, dataProjection)) {
|
||||||
geometry.transform(sourceProjection, targetProjection);
|
geometry.transform(dataProjection, featureProjection);
|
||||||
}
|
}
|
||||||
return geometry;
|
return geometry;
|
||||||
};
|
};
|
||||||
@@ -87,13 +91,12 @@ ol.format.GeoJSON.readGeometry_ = function(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {GeoJSONGeometryCollection} object Object.
|
* @param {GeoJSONGeometryCollection} object Object.
|
||||||
* @param {ol.proj.Projection} targetProjection Target projection.
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @param {ol.proj.Projection} sourceProjection Source projection.
|
|
||||||
* @private
|
* @private
|
||||||
* @return {ol.geom.GeometryCollection} Geometry collection.
|
* @return {ol.geom.GeometryCollection} Geometry collection.
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.readGeometryCollectionGeometry_ = function(
|
ol.format.GeoJSON.readGeometryCollectionGeometry_ = function(
|
||||||
object, targetProjection, sourceProjection) {
|
object, opt_options) {
|
||||||
goog.asserts.assert(object.type == 'GeometryCollection');
|
goog.asserts.assert(object.type == 'GeometryCollection');
|
||||||
var geometries = goog.array.map(object.geometries,
|
var geometries = goog.array.map(object.geometries,
|
||||||
/**
|
/**
|
||||||
@@ -101,8 +104,7 @@ ol.format.GeoJSON.readGeometryCollectionGeometry_ = function(
|
|||||||
* @return {ol.geom.Geometry} geometry Geometry.
|
* @return {ol.geom.Geometry} geometry Geometry.
|
||||||
*/
|
*/
|
||||||
function(geometry) {
|
function(geometry) {
|
||||||
return ol.format.GeoJSON.readGeometry_(
|
return ol.format.GeoJSON.readGeometry_(geometry, opt_options);
|
||||||
geometry, targetProjection, sourceProjection);
|
|
||||||
});
|
});
|
||||||
return new ol.geom.GeometryCollection(geometries);
|
return new ol.geom.GeometryCollection(geometries);
|
||||||
};
|
};
|
||||||
@@ -348,8 +350,7 @@ ol.format.GeoJSON.prototype.getExtensions = function() {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_targetProjection Target projection.
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_sourceProjection Source projection.
|
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -362,8 +363,7 @@ ol.format.GeoJSON.prototype.readFeature;
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_targetProjection Target projection.
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_sourceProjection Source projection.
|
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -374,16 +374,11 @@ ol.format.GeoJSON.prototype.readFeatures;
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.prototype.readFeatureFromObject = function(
|
ol.format.GeoJSON.prototype.readFeatureFromObject = function(
|
||||||
object, opt_targetProjection, opt_sourceProjection) {
|
object, opt_options) {
|
||||||
var geoJSONFeature = /** @type {GeoJSONFeature} */ (object);
|
var geoJSONFeature = /** @type {GeoJSONFeature} */ (object);
|
||||||
goog.asserts.assert(geoJSONFeature.type == 'Feature');
|
goog.asserts.assert(geoJSONFeature.type == 'Feature');
|
||||||
var targetProjection = goog.isDef(opt_targetProjection) ?
|
|
||||||
ol.proj.get(opt_targetProjection) : null;
|
|
||||||
var sourceProjection = goog.isDef(opt_sourceProjection) ?
|
|
||||||
ol.proj.get(opt_sourceProjection) :
|
|
||||||
this.readProjectionFromObject(object);
|
|
||||||
var geometry = ol.format.GeoJSON.readGeometry_(geoJSONFeature.geometry,
|
var geometry = ol.format.GeoJSON.readGeometry_(geoJSONFeature.geometry,
|
||||||
targetProjection, sourceProjection);
|
opt_options);
|
||||||
var feature = new ol.Feature();
|
var feature = new ol.Feature();
|
||||||
if (goog.isDef(this.geometryName_)) {
|
if (goog.isDef(this.geometryName_)) {
|
||||||
feature.setGeometryName(this.geometryName_);
|
feature.setGeometryName(this.geometryName_);
|
||||||
@@ -403,7 +398,7 @@ ol.format.GeoJSON.prototype.readFeatureFromObject = function(
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.prototype.readFeaturesFromObject = function(
|
ol.format.GeoJSON.prototype.readFeaturesFromObject = function(
|
||||||
object, opt_targetProjection, opt_sourceProjection) {
|
object, opt_options) {
|
||||||
var geoJSONObject = /** @type {GeoJSONObject} */ (object);
|
var geoJSONObject = /** @type {GeoJSONObject} */ (object);
|
||||||
if (geoJSONObject.type == 'Feature') {
|
if (geoJSONObject.type == 'Feature') {
|
||||||
return [this.readFeatureFromObject(object)];
|
return [this.readFeatureFromObject(object)];
|
||||||
@@ -416,7 +411,7 @@ ol.format.GeoJSON.prototype.readFeaturesFromObject = function(
|
|||||||
var i, ii;
|
var i, ii;
|
||||||
for (i = 0, ii = geoJSONFeatures.length; i < ii; ++i) {
|
for (i = 0, ii = geoJSONFeatures.length; i < ii; ++i) {
|
||||||
features.push(this.readFeatureFromObject(geoJSONFeatures[i],
|
features.push(this.readFeatureFromObject(geoJSONFeatures[i],
|
||||||
opt_targetProjection, opt_sourceProjection));
|
opt_options));
|
||||||
}
|
}
|
||||||
return features;
|
return features;
|
||||||
} else {
|
} else {
|
||||||
@@ -431,8 +426,7 @@ ol.format.GeoJSON.prototype.readFeaturesFromObject = function(
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_targetProjection Target projection.
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_sourceProjection Source projection.
|
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -443,15 +437,9 @@ ol.format.GeoJSON.prototype.readGeometry;
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.prototype.readGeometryFromObject = function(
|
ol.format.GeoJSON.prototype.readGeometryFromObject = function(
|
||||||
object, opt_targetProjection, opt_sourceProjection) {
|
object, opt_options) {
|
||||||
var targetProjection = goog.isDef(opt_targetProjection) ?
|
|
||||||
ol.proj.get(opt_targetProjection) : null;
|
|
||||||
var sourceProjection = goog.isDef(opt_sourceProjection) ?
|
|
||||||
ol.proj.get(opt_sourceProjection) :
|
|
||||||
this.readProjectionFromObject(object);
|
|
||||||
return ol.format.GeoJSON.readGeometry_(
|
return ol.format.GeoJSON.readGeometry_(
|
||||||
/** @type {GeoJSONGeometry} */ (object),
|
/** @type {GeoJSONGeometry} */ (object), opt_options);
|
||||||
targetProjection, sourceProjection);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -72,8 +72,7 @@ ol.format.JSONFeature.prototype.readFeatures = function(source) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} object Object.
|
* @param {Object} object Object.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_targetProjection Target projection.
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_sourceProjection Source projection.
|
|
||||||
* @protected
|
* @protected
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
*/
|
*/
|
||||||
@@ -82,8 +81,7 @@ ol.format.JSONFeature.prototype.readFeatureFromObject = goog.abstractMethod;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} object Object.
|
* @param {Object} object Object.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_targetProjection Target projection.
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_sourceProjection Source projection.
|
|
||||||
* @protected
|
* @protected
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
*/
|
*/
|
||||||
@@ -100,8 +98,7 @@ ol.format.JSONFeature.prototype.readGeometry = function(source) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} object Object.
|
* @param {Object} object Object.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_targetProjection Target projection.
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @param {ol.proj.ProjectionLike=} opt_sourceProjection Source projection.
|
|
||||||
* @protected
|
* @protected
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user