# all files / ol/style/ stroke.js

80% Statements 48/60
90.63% Branches 29/32
70.59% Functions 12/17
80% Lines 48/60

    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
    2821×

    1×

    1×

    483×

    483×

    483×

    483×

    483×

    483×

    483×

    483×

    483×

    1×
    13×
    13×

    1×
    8224×

    1×
    8185×

    1×
    8205×

    1×
    8198×

    1×
    8185×

    1×
    8185×

    1×
    8202×

    1×
    4×
    4×

    1×

    1×

    1×

    1×

    1×

    1×
    2×
    2×

    1×
    26×
    20×
    20×
    20×
    20×

    20×

    26×

     goog.provide('ol.style.Stroke');

    goog.require('ol');

    /**
     * @classdesc
     * Set stroke style for vector features.
     * Note that the defaults given are the Canvas defaults, which will be used if
     * option is not defined. The `get` functions return whatever was entered in
     * the options; they will not return the default.
     *
     * @constructor
     * @param {olx.style.StrokeOptions=} opt_options Options.
     * @api
     */
    ol.style.Stroke = function(opt_options) {

      var options = opt_options || {};

      /**
       * @private
       * @type {ol.Color|ol.ColorLike}
       */
      this.color_ = options.color !== undefined ? options.color : null;

      /**
       * @private
       * @type {string|undefined}
       */
      this.lineCap_ = options.lineCap;

      /**
       * @private
       * @type {Array.<number>}
       */
      this.lineDash_ = options.lineDash !== undefined ? options.lineDash : null;

      /**
       * @private
       * @type {number|undefined}
       */
      this.lineDashOffset_ = options.lineDashOffset;

      /**
       * @private
       * @type {string|undefined}
       */
      this.lineJoin_ = options.lineJoin;

      /**
       * @private
       * @type {number|undefined}
       */
      this.miterLimit_ = options.miterLimit;

      /**
       * @private
       * @type {number|undefined}
       */
      this.width_ = options.width;

      /**
       * @private
       * @type {string|undefined}
       */
      this.checksum_ = undefined;
    };

    /**
     * Clones the style.
     * @return {ol.style.Stroke} The cloned style.
     * @api
     */
    ol.style.Stroke.prototype.clone = function() {
      var color = this.getColor();
      return new ol.style.Stroke({
        color: (color && color.slice) ? color.slice() : color || undefined,
        lineCap: this.getLineCap(),
        lineDash: this.getLineDash() ? this.getLineDash().slice() : undefined,
        lineDashOffset: this.getLineDashOffset(),
        lineJoin: this.getLineJoin(),
        miterLimit: this.getMiterLimit(),
        width: this.getWidth()
      });
    };

    /**
     * Get the stroke color.
     * @return {ol.Color|ol.ColorLike} Color.
     * @api
     */
    ol.style.Stroke.prototype.getColor = function() {
      return this.color_;
    };

    /**
     * Get the line cap type for the stroke.
     * @return {string|undefined} Line cap.
     * @api
     */
    ol.style.Stroke.prototype.getLineCap = function() {
      return this.lineCap_;
    };

    /**
     * Get the line dash style for the stroke.
     * @return {Array.<number>} Line dash.
     * @api
     */
    ol.style.Stroke.prototype.getLineDash = function() {
      return this.lineDash_;
    };

    /**
     * Get the line dash offset for the stroke.
     * @return {number|undefined} Line dash offset.
     * @api
     */
    ol.style.Stroke.prototype.getLineDashOffset = function() {
      return this.lineDashOffset_;
    };

    /**
     * Get the line join type for the stroke.
     * @return {string|undefined} Line join.
     * @api
     */
    ol.style.Stroke.prototype.getLineJoin = function() {
      return this.lineJoin_;
    };

    /**
     * Get the miter limit for the stroke.
     * @return {number|undefined} Miter limit.
     * @api
     */
    ol.style.Stroke.prototype.getMiterLimit = function() {
      return this.miterLimit_;
    };

    /**
     * Get the stroke width.
     * @return {number|undefined} Width.
     * @api
     */
    ol.style.Stroke.prototype.getWidth = function() {
      return this.width_;
    };

    /**
     * Set the color.
     *
     * @param {ol.Color|ol.ColorLike} color Color.
     * @api
     */
    ol.style.Stroke.prototype.setColor = function(color) {
      this.color_ = color;
      this.checksum_ = undefined;
    };

    /**
     * Set the line cap.
     *
     * @param {string|undefined} lineCap Line cap.
     * @api
     */
    ol.style.Stroke.prototype.setLineCap = function(lineCap) {
      this.lineCap_ = lineCap;
      this.checksum_ = undefined;
    };

    /**
     * Set the line dash.
     *
     * Please note that Internet Explorer 10 and lower [do not support][mdn] the
     * `setLineDash` method on the `CanvasRenderingContext2D` and therefore this
     * property will have no visual effect in these browsers.
     *
     * [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash#Browser_compatibility
     *
     * @param {Array.<number>} lineDash Line dash.
     * @api
     */
    ol.style.Stroke.prototype.setLineDash = function(lineDash) {
      this.lineDash_ = lineDash;
      this.checksum_ = undefined;
    };

    /**
     * Set the line dash offset.
     *
     * @param {number|undefined} lineDashOffset Line dash offset.
     * @api
     */
    ol.style.Stroke.prototype.setLineDashOffset = function(lineDashOffset) {
      this.lineDashOffset_ = lineDashOffset;
      this.checksum_ = undefined;
    };

    /**
     * Set the line join.
     *
     * @param {string|undefined} lineJoin Line join.
     * @api
     */
    ol.style.Stroke.prototype.setLineJoin = function(lineJoin) {
      this.lineJoin_ = lineJoin;
      this.checksum_ = undefined;
    };

    /**
     * Set the miter limit.
     *
     * @param {number|undefined} miterLimit Miter limit.
     * @api
     */
    ol.style.Stroke.prototype.setMiterLimit = function(miterLimit) {
      this.miterLimit_ = miterLimit;
      this.checksum_ = undefined;
    };

    /**
     * Set the width.
     *
     * @param {number|undefined} width Width.
     * @api
     */
    ol.style.Stroke.prototype.setWidth = function(width) {
      this.width_ = width;
      this.checksum_ = undefined;
    };

    /**
     * @return {string} The checksum.
     */
    ol.style.Stroke.prototype.getChecksum = function() {
      if (this.checksum_ === undefined) {
        this.checksum_ = 's';
        Eif (this.color_) {
          Eif (typeof this.color_ === 'string') {
            this.checksum_ += this.color_;
          } else {
            this.checksum_ += ol.getUid(this.color_).toString();
          }
        } else {
          this.checksum_ += '-';
        }
        this.checksum_ += ',' +
            (this.lineCap_ !== undefined ?
              this.lineCap_.toString() : '-') + ',' +
            (this.lineDash_ ?
              this.lineDash_.toString() : '-') + ',' +
            (this.lineDashOffset_ !== undefined ?
              this.lineDashOffset_ : '-') + ',' +
            (this.lineJoin_ !== undefined ?
              this.lineJoin_ : '-') + ',' +
            (this.miterLimit_ !== undefined ?
              this.miterLimit_.toString() : '-') + ',' +
            (this.width_ !== undefined ?
              this.width_.toString() : '-');
      }

      return this.checksum_;
    };