# all files / ol/proj/ projection.js

71.19% Statements 42/59
63.33% Branches 19/30
18.75% Functions 3/16
71.19% Lines 42/59

    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
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    2841×

    1×
    1×
    1×

    1×

    17×

    17×

    17×

    17×

    17×

    17×

    17×

    17×

    17×

    17×

    17×
    17×
    17×
    17×
    2×
    2×
    1×

    1×
    1×

    1×

    1×

    1×
    469×

    1×
    4×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

     goog.provide('ol.proj.Projection');

    goog.require('ol');
    goog.require('ol.proj.Units');
    goog.require('ol.proj.proj4');

    /**
     * @classdesc
     * Projection definition class. One of these is created for each projection
     * supported in the application and stored in the {@link ol.proj} namespace.
     * You can use these in applications, but this is not required, as API params
     * and options use {@link ol.ProjectionLike} which means the simple string
     * code will suffice.
     *
     * You can use {@link ol.proj.get} to retrieve the object for a particular
     * projection.
     *
     * The library includes definitions for `EPSG:4326` and `EPSG:3857`, together
     * with the following aliases:
     * * `EPSG:4326`: CRS:84, urn:ogc:def:crs:EPSG:6.6:4326,
     *     urn:ogc:def:crs:OGC:1.3:CRS84, urn:ogc:def:crs:OGC:2:84,
     *     http://www.opengis.net/gml/srs/epsg.xml#4326,
     *     urn:x-ogc:def:crs:EPSG:4326
     * * `EPSG:3857`: EPSG:102100, EPSG:102113, EPSG:900913,
     *     urn:ogc:def:crs:EPSG:6.18:3:3857,
     *     http://www.opengis.net/gml/srs/epsg.xml#3857
     *
     * If you use proj4js, aliases can be added using `proj4.defs()`; see
     * [documentation](https://github.com/proj4js/proj4js). To set an alternative
     * namespace for proj4, use {@link ol.proj.setProj4}.
     *
     * @constructor
     * @param {olx.ProjectionOptions} options Projection options.
     * @struct
     * @api
     */
    ol.proj.Projection = function(options) {
      /**
       * @private
       * @type {string}
       */
      this.code_ = options.code;

      /**
       * Units of projected coordinates. When set to `ol.proj.Units.TILE_PIXELS`, a
       * `this.extent_` and `this.worldExtent_` must be configured properly for each
       * tile.
       * @private
       * @type {ol.proj.Units}
       */
      this.units_ = /** @type {ol.proj.Units} */ (options.units);

      /**
       * Validity extent of the projection in projected coordinates. For projections
       * with `ol.proj.Units.TILE_PIXELS` units, this is the extent of the tile in
       * tile pixel space.
       * @private
       * @type {ol.Extent}
       */
      this.extent_ = options.extent !== undefined ? options.extent : null;

      /**
       * Extent of the world in EPSG:4326. For projections with
       * `ol.proj.Units.TILE_PIXELS` units, this is the extent of the tile in
       * projected coordinate space.
       * @private
       * @type {ol.Extent}
       */
      this.worldExtent_ = options.worldExtent !== undefined ?
        options.worldExtent : null;

      /**
       * @private
       * @type {string}
       */
      this.axisOrientation_ = options.axisOrientation !== undefined ?
        options.axisOrientation : 'enu';

      /**
       * @private
       * @type {boolean}
       */
      this.global_ = options.global !== undefined ? options.global : false;

      /**
       * @private
       * @type {boolean}
       */
      this.canWrapX_ = !!(this.global_ && this.extent_);

      /**
       * @private
       * @type {function(number, ol.Coordinate):number|undefined}
       */
      this.getPointResolutionFunc_ = options.getPointResolution;

      /**
       * @private
       * @type {ol.tilegrid.TileGrid}
       */
      this.defaultTileGrid_ = null;

      /**
       * @private
       * @type {number|undefined}
       */
      this.metersPerUnit_ = options.metersPerUnit;

      var code = options.code;
      Eif (ol.ENABLE_PROJ4JS) {
        var proj4js = ol.proj.proj4.get();
        if (typeof proj4js == 'function') {
          var def = proj4js.defs(code);
          if (def !== undefined) {
            Iif (def.axis !== undefined && options.axisOrientation === undefined) {
              this.axisOrientation_ = def.axis;
            }
            Eif (options.metersPerUnit === undefined) {
              this.metersPerUnit_ = def.to_meter;
            }
            Iif (options.units === undefined) {
              this.units_ = def.units;
            }
          }
        }
      }
    };

    /**
     * @return {boolean} The projection is suitable for wrapping the x-axis
     */
    ol.proj.Projection.prototype.canWrapX = function() {
      return this.canWrapX_;
    };

    /**
     * Get the code for this projection, e.g. 'EPSG:4326'.
     * @return {string} Code.
     * @api
     */
    ol.proj.Projection.prototype.getCode = function() {
      return this.code_;
    };

    /**
     * Get the validity extent for this projection.
     * @return {ol.Extent} Extent.
     * @api
     */
    ol.proj.Projection.prototype.getExtent = function() {
      return this.extent_;
    };

    /**
     * Get the units of this projection.
     * @return {ol.proj.Units} Units.
     * @api
     */
    ol.proj.Projection.prototype.getUnits = function() {
      return this.units_;
    };

    /**
     * Get the amount of meters per unit of this projection.  If the projection is
     * not configured with `metersPerUnit` or a units identifier, the return is
     * `undefined`.
     * @return {number|undefined} Meters.
     * @api
     */
    ol.proj.Projection.prototype.getMetersPerUnit = function() {
      return this.metersPerUnit_ || ol.proj.Units.METERS_PER_UNIT[this.units_];
    };

    /**
     * Get the world extent for this projection.
     * @return {ol.Extent} Extent.
     * @api
     */
    ol.proj.Projection.prototype.getWorldExtent = function() {
      return this.worldExtent_;
    };

    /**
     * Get the axis orientation of this projection.
     * Example values are:
     * enu - the default easting, northing, elevation.
     * neu - northing, easting, up - useful for "lat/long" geographic coordinates,
     *     or south orientated transverse mercator.
     * wnu - westing, northing, up - some planetary coordinate systems have
     *     "west positive" coordinate systems
     * @return {string} Axis orientation.
     */
    ol.proj.Projection.prototype.getAxisOrientation = function() {
      return this.axisOrientation_;
    };

    /**
     * Is this projection a global projection which spans the whole world?
     * @return {boolean} Whether the projection is global.
     * @api
     */
    ol.proj.Projection.prototype.isGlobal = function() {
      return this.global_;
    };

    /**
    * Set if the projection is a global projection which spans the whole world
    * @param {boolean} global Whether the projection is global.
    * @api
    */
    ol.proj.Projection.prototype.setGlobal = function(global) {
      this.global_ = global;
      this.canWrapX_ = !!(global && this.extent_);
    };

    /**
     * @return {ol.tilegrid.TileGrid} The default tile grid.
     */
    ol.proj.Projection.prototype.getDefaultTileGrid = function() {
      return this.defaultTileGrid_;
    };

    /**
     * @param {ol.tilegrid.TileGrid} tileGrid The default tile grid.
     */
    ol.proj.Projection.prototype.setDefaultTileGrid = function(tileGrid) {
      this.defaultTileGrid_ = tileGrid;
    };

    /**
     * Set the validity extent for this projection.
     * @param {ol.Extent} extent Extent.
     * @api
     */
    ol.proj.Projection.prototype.setExtent = function(extent) {
      this.extent_ = extent;
      this.canWrapX_ = !!(this.global_ && extent);
    };

    /**
     * Set the world extent for this projection.
     * @param {ol.Extent} worldExtent World extent
     *     [minlon, minlat, maxlon, maxlat].
     * @api
     */
    ol.proj.Projection.prototype.setWorldExtent = function(worldExtent) {
      this.worldExtent_ = worldExtent;
    };

    /**
     * Set the getPointResolution function (see {@link ol.proj#getPointResolution}
     * for this projection.
     * @param {function(number, ol.Coordinate):number} func Function
     * @api
     */
    ol.proj.Projection.prototype.setGetPointResolution = function(func) {
      this.getPointResolutionFunc_ = func;
    };

    /**
     * Get the custom point resolution function for this projection (if set).
     * @return {function(number, ol.Coordinate):number|undefined} The custom point
     * resolution function (if set).
     */
    ol.proj.Projection.prototype.getPointResolutionFunc = function() {
      return this.getPointResolutionFunc_;
    };