# all files / ol/format/ jsonfeatureformat.js

92.11% Statements 35/38
66.67% Branches 4/6
90% Functions 9/10
92.11% Lines 35/38

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    1651×

    1×
    1×
    1×

    1×
    114×

    1×

    1×
    123×
    32×
    91×
    91×
    91×

    1×
    8×

    1×
    13×

    1×
    30×

    1×

    1×

    1×
    62×

    1×

    1×
    18×

    1×

    1×

    1×

    1×
    2×

    1×

    1×
    45×

    1×
     goog.provide('ol.format.JSONFeature');

    goog.require('goog.asserts');
    goog.require('ol.format.Feature');
    goog.require('ol.format.FormatType');

    /**
     * @classdesc
     * Abstract base class; normally only used for creating subclasses and not
     * instantiated in apps.
     * Base class for JSON feature formats.
     *
     * @constructor
     * @extends {ol.format.Feature}
     */
    ol.format.JSONFeature = function() {
      goog.base(this);
    };
    goog.inherits(ol.format.JSONFeature, ol.format.Feature);

    /**
     * @param {Document|Node|Object|string} source Source.
     * @private
     * @return {Object} Object.
     */
    ol.format.JSONFeature.prototype.getObject_ = function(source) {
      if (goog.isObject(source)) {
        return source;
      } else Eif (typeof source === 'string') {
        var object = JSON.parse(source);
        return object ? /** @type {Object} */ (object) : null;
      } else {
        goog.asserts.fail();
        return null;
      }
    };

    /**
     * @inheritDoc
     */
    ol.format.JSONFeature.prototype.getType = function() {
      return ol.format.FormatType.JSON;
    };

    /**
     * @inheritDoc
     */
    ol.format.JSONFeature.prototype.readFeature = function(source, opt_options) {
      return this.readFeatureFromObject(
          this.getObject_(source), this.getReadOptions(source, opt_options));
    };

    /**
     * @inheritDoc
     */
    ol.format.JSONFeature.prototype.readFeatures = function(source, opt_options) {
      return this.readFeaturesFromObject(
          this.getObject_(source), this.getReadOptions(source, opt_options));
    };

    /**
     * @param {Object} object Object.
     * @param {olx.format.ReadOptions=} opt_options Read options.
     * @protected
     * @return {ol.Feature} Feature.
     */
    ol.format.JSONFeature.prototype.readFeatureFromObject = goog.abstractMethod;

    /**
     * @param {Object} object Object.
     * @param {olx.format.ReadOptions=} opt_options Read options.
     * @protected
     * @return {Array.<ol.Feature>} Features.
     */
    ol.format.JSONFeature.prototype.readFeaturesFromObject = goog.abstractMethod;

    /**
     * @inheritDoc
     */
    ol.format.JSONFeature.prototype.readGeometry = function(source, opt_options) {
      return this.readGeometryFromObject(
          this.getObject_(source), this.getReadOptions(source, opt_options));
    };

    /**
     * @param {Object} object Object.
     * @param {olx.format.ReadOptions=} opt_options Read options.
     * @protected
     * @return {ol.geom.Geometry} Geometry.
     */
    ol.format.JSONFeature.prototype.readGeometryFromObject = goog.abstractMethod;

    /**
     * @inheritDoc
     */
    ol.format.JSONFeature.prototype.readProjection = function(source) {
      return this.readProjectionFromObject(this.getObject_(source));
    };

    /**
     * @param {Object} object Object.
     * @protected
     * @return {ol.proj.Projection} Projection.
     */
    ol.format.JSONFeature.prototype.readProjectionFromObject = goog.abstractMethod;

    /**
     * @inheritDoc
     */
    ol.format.JSONFeature.prototype.writeFeature = function(feature, opt_options) {
      return JSON.stringify(this.writeFeatureObject(feature, opt_options));
    };

    /**
     * @param {ol.Feature} feature Feature.
     * @param {olx.format.WriteOptions=} opt_options Write options.
     * @return {Object} Object.
     */
    ol.format.JSONFeature.prototype.writeFeatureObject = goog.abstractMethod;

    /**
     * @inheritDoc
     */
    ol.format.JSONFeature.prototype.writeFeatures = function(features, opt_options) {
      return JSON.stringify(this.writeFeaturesObject(features, opt_options));
    };

    /**
     * @param {Array.<ol.Feature>} features Features.
     * @param {olx.format.WriteOptions=} opt_options Write options.
     * @return {Object} Object.
     */
    ol.format.JSONFeature.prototype.writeFeaturesObject = goog.abstractMethod;

    /**
     * @inheritDoc
     */
    ol.format.JSONFeature.prototype.writeGeometry = function(geometry, opt_options) {
      return JSON.stringify(this.writeGeometryObject(geometry, opt_options));
    };

    /**
     * @param {ol.geom.Geometry} geometry Geometry.
     * @param {olx.format.WriteOptions=} opt_options Write options.
     * @return {Object} Object.
     */
    ol.format.JSONFeature.prototype.writeGeometryObject = goog.abstractMethod;