Implement read/write transforms for ol.format.WKT
This commit is contained in:
@@ -3,6 +3,7 @@ goog.provide('ol.format.WKT');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.format.Feature');
|
||||
goog.require('ol.format.TextFeature');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryCollection');
|
||||
@@ -208,6 +209,7 @@ ol.format.WKT.prototype.parse_ = function(wkt) {
|
||||
*
|
||||
* @function
|
||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||
* @return {ol.Feature} Feature.
|
||||
* @api
|
||||
*/
|
||||
@@ -217,8 +219,8 @@ ol.format.WKT.prototype.readFeature;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.WKT.prototype.readFeatureFromText = function(text) {
|
||||
var geom = this.readGeometryFromText(text);
|
||||
ol.format.WKT.prototype.readFeatureFromText = function(text, opt_options) {
|
||||
var geom = this.readGeometryFromText(text, opt_options);
|
||||
if (goog.isDef(geom)) {
|
||||
var feature = new ol.Feature();
|
||||
feature.setGeometry(geom);
|
||||
@@ -233,6 +235,7 @@ ol.format.WKT.prototype.readFeatureFromText = function(text) {
|
||||
*
|
||||
* @function
|
||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||
* @return {Array.<ol.Feature>} Features.
|
||||
* @api
|
||||
*/
|
||||
@@ -242,9 +245,9 @@ ol.format.WKT.prototype.readFeatures;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.WKT.prototype.readFeaturesFromText = function(text) {
|
||||
ol.format.WKT.prototype.readFeaturesFromText = function(text, opt_options) {
|
||||
var geometries = [];
|
||||
var geometry = this.readGeometryFromText(text);
|
||||
var geometry = this.readGeometryFromText(text, opt_options);
|
||||
if (this.splitCollection_ &&
|
||||
geometry.getType() == ol.geom.GeometryType.GEOMETRY_COLLECTION) {
|
||||
geometries = (/** @type {ol.geom.GeometryCollection} */ (geometry))
|
||||
@@ -267,6 +270,7 @@ ol.format.WKT.prototype.readFeaturesFromText = function(text) {
|
||||
*
|
||||
* @function
|
||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||
* @return {ol.geom.Geometry} Geometry.
|
||||
* @api
|
||||
*/
|
||||
@@ -276,8 +280,14 @@ ol.format.WKT.prototype.readGeometry;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.WKT.prototype.readGeometryFromText = function(text) {
|
||||
return this.parse_(text) || null;
|
||||
ol.format.WKT.prototype.readGeometryFromText = function(text, opt_options) {
|
||||
var geometry = this.parse_(text);
|
||||
if (goog.isDef(geometry)) {
|
||||
return ol.format.Feature.transformWithOptions(
|
||||
geometry, false, false, opt_options);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -294,6 +304,7 @@ ol.format.WKT.prototype.readProjectionFromText = function(text) {
|
||||
*
|
||||
* @function
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||
* @return {string} WKT string.
|
||||
* @api
|
||||
*/
|
||||
@@ -303,10 +314,10 @@ ol.format.WKT.prototype.writeFeature;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.WKT.prototype.writeFeatureText = function(feature) {
|
||||
ol.format.WKT.prototype.writeFeatureText = function(feature, opt_options) {
|
||||
var geometry = feature.getGeometry();
|
||||
if (goog.isDef(geometry)) {
|
||||
return this.writeGeometryText(geometry);
|
||||
return this.writeGeometryText(geometry, opt_options);
|
||||
}
|
||||
return '';
|
||||
};
|
||||
@@ -317,6 +328,7 @@ ol.format.WKT.prototype.writeFeatureText = function(feature) {
|
||||
*
|
||||
* @function
|
||||
* @param {Array.<ol.Feature>} features Features.
|
||||
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||
* @return {string} WKT string.
|
||||
* @api
|
||||
*/
|
||||
@@ -326,16 +338,16 @@ ol.format.WKT.prototype.writeFeatures;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.WKT.prototype.writeFeaturesText = function(features) {
|
||||
ol.format.WKT.prototype.writeFeaturesText = function(features, opt_options) {
|
||||
if (features.length == 1) {
|
||||
return this.writeFeatureText(features[0]);
|
||||
return this.writeFeatureText(features[0], opt_options);
|
||||
}
|
||||
var geometries = [];
|
||||
for (var i = 0, ii = features.length; i < ii; ++i) {
|
||||
geometries.push(features[i].getGeometry());
|
||||
}
|
||||
var collection = new ol.geom.GeometryCollection(geometries);
|
||||
return this.writeGeometryText(collection);
|
||||
return this.writeGeometryText(collection, opt_options);
|
||||
};
|
||||
|
||||
|
||||
@@ -353,8 +365,9 @@ ol.format.WKT.prototype.writeGeometry;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.WKT.prototype.writeGeometryText = function(geometry) {
|
||||
return ol.format.WKT.encode_(geometry);
|
||||
ol.format.WKT.prototype.writeGeometryText = function(geometry, opt_options) {
|
||||
return ol.format.WKT.encode_(ol.format.Feature.transformWithOptions(
|
||||
geometry, true, true, opt_options));
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user