Implement read/write transforms for ol.format.Polyline
This commit is contained in:
@@ -2,6 +2,7 @@ goog.provide('ol.format.Polyline');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.format.Feature');
|
||||
goog.require('ol.format.TextFeature');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.flat.inflate');
|
||||
@@ -248,6 +249,7 @@ ol.format.Polyline.encodeUnsignedInteger = function(num) {
|
||||
*
|
||||
* @function
|
||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||
* @return {ol.Feature} Feature.
|
||||
* @api
|
||||
*/
|
||||
@@ -257,8 +259,8 @@ ol.format.Polyline.prototype.readFeature;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.Polyline.prototype.readFeatureFromText = function(text) {
|
||||
var geometry = this.readGeometryFromText(text);
|
||||
ol.format.Polyline.prototype.readFeatureFromText = function(text, opt_options) {
|
||||
var geometry = this.readGeometryFromText(text, opt_options);
|
||||
return new ol.Feature(geometry);
|
||||
};
|
||||
|
||||
@@ -269,6 +271,7 @@ ol.format.Polyline.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
|
||||
*/
|
||||
@@ -278,8 +281,9 @@ ol.format.Polyline.prototype.readFeatures;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.Polyline.prototype.readFeaturesFromText = function(text) {
|
||||
var feature = this.readFeatureFromText(text);
|
||||
ol.format.Polyline.prototype.readFeaturesFromText =
|
||||
function(text, opt_options) {
|
||||
var feature = this.readFeatureFromText(text, opt_options);
|
||||
return [feature];
|
||||
};
|
||||
|
||||
@@ -289,6 +293,7 @@ ol.format.Polyline.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
|
||||
*/
|
||||
@@ -298,11 +303,18 @@ ol.format.Polyline.prototype.readGeometry;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.Polyline.prototype.readGeometryFromText = function(text) {
|
||||
ol.format.Polyline.prototype.readGeometryFromText =
|
||||
function(text, opt_options) {
|
||||
var flatCoordinates = ol.format.Polyline.decodeDeltas(text, 2, this.factor_);
|
||||
var coordinates = ol.geom.flat.inflate.coordinates(
|
||||
flatCoordinates, 0, flatCoordinates.length, 2);
|
||||
return new ol.geom.LineString(coordinates);
|
||||
|
||||
// for convenience set a default dataProjection
|
||||
opt_options = ol.format.Feature.setDefaultDataProjection(
|
||||
opt_options, this.readProjectionFromText(null));
|
||||
|
||||
return ol.format.Feature.transformWithOptions(
|
||||
new ol.geom.LineString(coordinates), false, false, opt_options);
|
||||
};
|
||||
|
||||
|
||||
@@ -328,10 +340,10 @@ ol.format.Polyline.prototype.readProjectionFromText = function(text) {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.Polyline.prototype.writeFeatureText = function(feature) {
|
||||
ol.format.Polyline.prototype.writeFeatureText = function(feature, opt_options) {
|
||||
var geometry = feature.getGeometry();
|
||||
if (goog.isDefAndNotNull(geometry)) {
|
||||
return this.writeGeometryText(geometry);
|
||||
return this.writeGeometryText(geometry, opt_options);
|
||||
} else {
|
||||
goog.asserts.fail();
|
||||
return '';
|
||||
@@ -342,9 +354,10 @@ ol.format.Polyline.prototype.writeFeatureText = function(feature) {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.Polyline.prototype.writeFeaturesText = function(features) {
|
||||
ol.format.Polyline.prototype.writeFeaturesText =
|
||||
function(features, opt_options) {
|
||||
goog.asserts.assert(features.length == 1);
|
||||
return this.writeFeatureText(features[0]);
|
||||
return this.writeFeatureText(features[0], opt_options);
|
||||
};
|
||||
|
||||
|
||||
@@ -353,6 +366,7 @@ ol.format.Polyline.prototype.writeFeaturesText = function(features) {
|
||||
*
|
||||
* @function
|
||||
* @param {ol.geom.Geometry} geometry Geometry.
|
||||
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||
* @return {string} Geometry.
|
||||
* @api
|
||||
*/
|
||||
@@ -362,8 +376,14 @@ ol.format.Polyline.prototype.writeGeometry;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.Polyline.prototype.writeGeometryText = function(geometry) {
|
||||
ol.format.Polyline.prototype.writeGeometryText =
|
||||
function(geometry, opt_options) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
|
||||
// for convenience set a default dataProjection
|
||||
opt_options = ol.format.Feature.setDefaultDataProjection(
|
||||
opt_options, this.readProjectionFromText(null));
|
||||
geometry = ol.format.Feature.transformWithOptions(
|
||||
geometry, true, true, opt_options);
|
||||
var flatCoordinates = geometry.getFlatCoordinates();
|
||||
var stride = geometry.getStride();
|
||||
return ol.format.Polyline.encodeDeltas(flatCoordinates, stride, this.factor_);
|
||||
|
||||
Reference in New Issue
Block a user