Remove goog.isNull in style classes

This commit is contained in:
Marc Jansen
2015-09-29 15:21:02 +02:00
parent e1f477ad8c
commit f9b07991e1
7 changed files with 53 additions and 56 deletions

View File

@@ -97,13 +97,12 @@ ol.style.AtlasManager.prototype.getInfo = function(id) {
/** @type {?ol.style.AtlasInfo} */
var info = this.getInfo_(this.atlases_, id);
if (goog.isNull(info)) {
if (!info) {
return null;
}
/** @type {?ol.style.AtlasInfo} */
var hitInfo = this.getInfo_(this.hitAtlases_, id);
goog.asserts.assert(!goog.isNull(hitInfo),
'hitInfo must not be null');
goog.asserts.assert(hitInfo, 'hitInfo must not be null');
return this.mergeInfos_(info, hitInfo);
};
@@ -121,7 +120,7 @@ ol.style.AtlasManager.prototype.getInfo_ = function(atlases, id) {
for (i = 0, ii = atlases.length; i < ii; ++i) {
atlas = atlases[i];
info = atlas.get(id);
if (!goog.isNull(info)) {
if (info) {
return info;
}
}
@@ -184,7 +183,7 @@ ol.style.AtlasManager.prototype.add =
/** @type {?ol.style.AtlasInfo} */
var info = this.add_(false,
id, width, height, renderCallback, opt_this);
if (goog.isNull(info)) {
if (!info) {
return null;
}
@@ -197,8 +196,7 @@ ol.style.AtlasManager.prototype.add =
/** @type {?ol.style.AtlasInfo} */
var hitInfo = this.add_(true,
id, width, height, renderHitCallback, opt_this);
goog.asserts.assert(!goog.isNull(hitInfo),
'hitInfo must not be null');
goog.asserts.assert(hitInfo, 'hitInfo must not be null');
return this.mergeInfos_(info, hitInfo);
};
@@ -225,9 +223,9 @@ ol.style.AtlasManager.prototype.add_ =
for (i = 0, ii = atlases.length; i < ii; ++i) {
atlas = atlases[i];
info = atlas.add(id, width, height, renderCallback, opt_this);
if (!goog.isNull(info)) {
if (info) {
return info;
} else if (goog.isNull(info) && i === ii - 1) {
} else if (!info && i === ii - 1) {
// the entry could not be added to one of the existing atlases,
// create a new atlas that is twice as big and try to add to this one.
var size;

View File

@@ -247,7 +247,7 @@ ol.style.Circle.prototype.render_ = function(atlasManager) {
var strokeStyle;
var strokeWidth = 0;
if (!goog.isNull(this.stroke_)) {
if (this.stroke_) {
strokeStyle = ol.color.asString(this.stroke_.getColor());
strokeWidth = this.stroke_.getWidth();
if (strokeWidth === undefined) {
@@ -291,7 +291,7 @@ ol.style.Circle.prototype.render_ = function(atlasManager) {
// an atlas manager is used, add the symbol to an atlas
size = Math.round(size);
var hasCustomHitDetectionImage = goog.isNull(this.fill_);
var hasCustomHitDetectionImage = !this.fill_;
var renderHitDetectionCallback;
if (hasCustomHitDetectionImage) {
// render the hit-detection image into a separate atlas image
@@ -303,7 +303,7 @@ ol.style.Circle.prototype.render_ = function(atlasManager) {
var info = atlasManager.add(
id, size, size, goog.bind(this.draw_, this, renderOptions),
renderHitDetectionCallback);
goog.asserts.assert(info !== null, 'circle radius is too large');
goog.asserts.assert(info, 'circle radius is too large');
this.canvas_ = info.image;
this.origin_ = [info.offsetX, info.offsetY];
@@ -344,14 +344,14 @@ ol.style.Circle.prototype.draw_ = function(renderOptions, context, x, y) {
renderOptions.size / 2, renderOptions.size / 2,
this.radius_, 0, 2 * Math.PI, true);
if (!goog.isNull(this.fill_)) {
if (this.fill_) {
context.fillStyle = ol.color.asString(this.fill_.getColor());
context.fill();
}
if (!goog.isNull(this.stroke_)) {
if (this.stroke_) {
context.strokeStyle = renderOptions.strokeStyle;
context.lineWidth = renderOptions.strokeWidth;
if (!goog.isNull(renderOptions.lineDash)) {
if (renderOptions.lineDash) {
context.setLineDash(renderOptions.lineDash);
}
context.stroke();
@@ -366,7 +366,7 @@ ol.style.Circle.prototype.draw_ = function(renderOptions, context, x, y) {
*/
ol.style.Circle.prototype.createHitDetectionCanvas_ = function(renderOptions) {
this.hitDetectionImageSize_ = [renderOptions.size, renderOptions.size];
if (!goog.isNull(this.fill_)) {
if (this.fill_) {
this.hitDetectionCanvas_ = this.canvas_;
return;
}
@@ -408,10 +408,10 @@ ol.style.Circle.prototype.drawHitDetectionCanvas_ =
context.fillStyle = ol.color.asString(ol.render.canvas.defaultFillStyle);
context.fill();
if (!goog.isNull(this.stroke_)) {
if (this.stroke_) {
context.strokeStyle = renderOptions.strokeStyle;
context.lineWidth = renderOptions.strokeWidth;
if (!goog.isNull(renderOptions.lineDash)) {
if (renderOptions.lineDash) {
context.setLineDash(renderOptions.lineDash);
}
context.stroke();
@@ -424,12 +424,12 @@ ol.style.Circle.prototype.drawHitDetectionCanvas_ =
* @inheritDoc
*/
ol.style.Circle.prototype.getChecksum = function() {
var strokeChecksum = !goog.isNull(this.stroke_) ?
var strokeChecksum = this.stroke_ ?
this.stroke_.getChecksum() : '-';
var fillChecksum = !goog.isNull(this.fill_) ?
var fillChecksum = this.fill_ ?
this.fill_.getChecksum() : '-';
var recalculate = goog.isNull(this.checksums_) ||
var recalculate = !this.checksums_ ||
(strokeChecksum != this.checksums_[1] ||
fillChecksum != this.checksums_[2] ||
this.radius_ != this.checksums_[3]);

View File

@@ -59,7 +59,7 @@ ol.style.Fill.prototype.setColor = function(color) {
*/
ol.style.Fill.prototype.getChecksum = function() {
if (this.checksum_ === undefined) {
this.checksum_ = 'f' + (!goog.isNull(this.color_) ?
this.checksum_ = 'f' + (this.color_ ?
ol.color.asString(this.color_) : '-');
}

View File

@@ -104,16 +104,16 @@ ol.style.Icon = function(opt_options) {
*/
var src = options.src;
goog.asserts.assert(!(src !== undefined && !goog.isNull(image)),
goog.asserts.assert(!(src !== undefined && image),
'image and src can not provided at the same time');
goog.asserts.assert(
src === undefined || (src !== undefined && goog.isNull(imgSize)),
src === undefined || (src !== undefined && !imgSize),
'imgSize should not be set when src is provided');
goog.asserts.assert(
goog.isNull(image) || (!goog.isNull(image) && !goog.isNull(imgSize)),
!image || (image && imgSize),
'imgSize must be set when image is provided');
if ((src === undefined || src.length === 0) && !goog.isNull(image)) {
if ((src === undefined || src.length === 0) && image) {
src = image.src;
}
goog.asserts.assert(src !== undefined && src.length > 0,
@@ -201,14 +201,14 @@ goog.inherits(ol.style.Icon, ol.style.Image);
* @api
*/
ol.style.Icon.prototype.getAnchor = function() {
if (!goog.isNull(this.normalizedAnchor_)) {
if (this.normalizedAnchor_) {
return this.normalizedAnchor_;
}
var anchor = this.anchor_;
var size = this.getSize();
if (this.anchorXUnits_ == ol.style.IconAnchorUnits.FRACTION ||
this.anchorYUnits_ == ol.style.IconAnchorUnits.FRACTION) {
if (goog.isNull(size)) {
if (!size) {
return null;
}
anchor = this.anchor_.slice();
@@ -221,7 +221,7 @@ ol.style.Icon.prototype.getAnchor = function() {
}
if (this.anchorOrigin_ != ol.style.IconOrigin.TOP_LEFT) {
if (goog.isNull(size)) {
if (!size) {
return null;
}
if (anchor === this.anchor_) {
@@ -290,7 +290,7 @@ ol.style.Icon.prototype.getHitDetectionImage = function(pixelRatio) {
* @api
*/
ol.style.Icon.prototype.getOrigin = function() {
if (!goog.isNull(this.origin_)) {
if (this.origin_) {
return this.origin_;
}
var offset = this.offset_;
@@ -298,7 +298,7 @@ ol.style.Icon.prototype.getOrigin = function() {
if (this.offsetOrigin_ != ol.style.IconOrigin.TOP_LEFT) {
var size = this.getSize();
var iconImageSize = this.iconImage_.getSize();
if (goog.isNull(size) || goog.isNull(iconImageSize)) {
if (!size || !iconImageSize) {
return null;
}
offset = offset.slice();
@@ -331,7 +331,7 @@ ol.style.Icon.prototype.getSrc = function() {
* @api
*/
ol.style.Icon.prototype.getSize = function() {
return goog.isNull(this.size_) ? this.iconImage_.getSize() : this.size_;
return !this.size_ ? this.iconImage_.getSize() : this.size_;
};
@@ -390,9 +390,9 @@ ol.style.IconImage_ = function(image, src, size, crossOrigin, imageState) {
* @private
* @type {Image}
*/
this.image_ = goog.isNull(image) ? new Image() : image;
this.image_ = !image ? new Image() : image;
if (!goog.isNull(crossOrigin)) {
if (crossOrigin) {
this.image_.crossOrigin = crossOrigin;
}
@@ -441,7 +441,7 @@ goog.inherits(ol.style.IconImage_, goog.events.EventTarget);
ol.style.IconImage_.get = function(image, src, size, crossOrigin, imageState) {
var iconImageCache = ol.style.IconImageCache.getInstance();
var iconImage = iconImageCache.get(src, crossOrigin);
if (goog.isNull(iconImage)) {
if (!iconImage) {
iconImage = new ol.style.IconImage_(
image, src, size, crossOrigin, imageState);
iconImageCache.set(src, crossOrigin, iconImage);
@@ -516,7 +516,7 @@ ol.style.IconImage_.prototype.getImageState = function() {
* @return {Image|HTMLCanvasElement} Image element.
*/
ol.style.IconImage_.prototype.getHitDetectionImage = function(pixelRatio) {
if (goog.isNull(this.hitDetectionImage_)) {
if (!this.hitDetectionImage_) {
if (this.tainting_) {
var width = this.size_[0];
var height = this.size_[1];
@@ -554,7 +554,7 @@ ol.style.IconImage_.prototype.load = function() {
if (this.imageState_ == ol.style.ImageState.IDLE) {
goog.asserts.assert(this.src_ !== undefined,
'this.src_ must not be undefined');
goog.asserts.assert(goog.isNull(this.imageListenerKeys_),
goog.asserts.assert(!this.imageListenerKeys_,
'no listener keys existing');
this.imageState_ = ol.style.ImageState.LOADING;
this.imageListenerKeys_ = [
@@ -578,7 +578,7 @@ ol.style.IconImage_.prototype.load = function() {
* @private
*/
ol.style.IconImage_.prototype.unlistenImage_ = function() {
goog.asserts.assert(!goog.isNull(this.imageListenerKeys_),
goog.asserts.assert(this.imageListenerKeys_,
'we must have listeners registered');
this.imageListenerKeys_.forEach(goog.events.unlistenByKey);
this.imageListenerKeys_ = null;

View File

@@ -313,7 +313,7 @@ ol.style.RegularShape.prototype.render_ = function(atlasManager) {
var strokeStyle;
var strokeWidth = 0;
if (!goog.isNull(this.stroke_)) {
if (this.stroke_) {
strokeStyle = ol.color.asString(this.stroke_.getColor());
strokeWidth = this.stroke_.getWidth();
if (strokeWidth === undefined) {
@@ -371,7 +371,7 @@ ol.style.RegularShape.prototype.render_ = function(atlasManager) {
// an atlas manager is used, add the symbol to an atlas
size = Math.round(size);
var hasCustomHitDetectionImage = goog.isNull(this.fill_);
var hasCustomHitDetectionImage = !this.fill_;
var renderHitDetectionCallback;
if (hasCustomHitDetectionImage) {
// render the hit-detection image into a separate atlas image
@@ -383,7 +383,7 @@ ol.style.RegularShape.prototype.render_ = function(atlasManager) {
var info = atlasManager.add(
id, size, size, goog.bind(this.draw_, this, renderOptions),
renderHitDetectionCallback);
goog.asserts.assert(!goog.isNull(info), 'shape size is too large');
goog.asserts.assert(info, 'shape size is too large');
this.canvas_ = info.image;
this.origin_ = [info.offsetX, info.offsetY];
@@ -431,14 +431,14 @@ ol.style.RegularShape.prototype.draw_ = function(renderOptions, context, x, y) {
renderOptions.size / 2 + radiusC * Math.sin(angle0));
}
if (!goog.isNull(this.fill_)) {
if (this.fill_) {
context.fillStyle = ol.color.asString(this.fill_.getColor());
context.fill();
}
if (!goog.isNull(this.stroke_)) {
if (this.stroke_) {
context.strokeStyle = renderOptions.strokeStyle;
context.lineWidth = renderOptions.strokeWidth;
if (!goog.isNull(renderOptions.lineDash)) {
if (renderOptions.lineDash) {
context.setLineDash(renderOptions.lineDash);
}
context.lineCap = renderOptions.lineCap;
@@ -457,7 +457,7 @@ ol.style.RegularShape.prototype.draw_ = function(renderOptions, context, x, y) {
ol.style.RegularShape.prototype.createHitDetectionCanvas_ =
function(renderOptions) {
this.hitDetectionImageSize_ = [renderOptions.size, renderOptions.size];
if (!goog.isNull(this.fill_)) {
if (this.fill_) {
this.hitDetectionCanvas_ = this.canvas_;
return;
}
@@ -506,10 +506,10 @@ ol.style.RegularShape.prototype.drawHitDetectionCanvas_ =
context.fillStyle = ol.render.canvas.defaultFillStyle;
context.fill();
if (!goog.isNull(this.stroke_)) {
if (this.stroke_) {
context.strokeStyle = renderOptions.strokeStyle;
context.lineWidth = renderOptions.strokeWidth;
if (!goog.isNull(renderOptions.lineDash)) {
if (renderOptions.lineDash) {
context.setLineDash(renderOptions.lineDash);
}
context.stroke();
@@ -522,12 +522,12 @@ ol.style.RegularShape.prototype.drawHitDetectionCanvas_ =
* @inheritDoc
*/
ol.style.RegularShape.prototype.getChecksum = function() {
var strokeChecksum = !goog.isNull(this.stroke_) ?
var strokeChecksum = this.stroke_ ?
this.stroke_.getChecksum() : '-';
var fillChecksum = !goog.isNull(this.fill_) ?
var fillChecksum = this.fill_ ?
this.fill_.getChecksum() : '-';
var recalculate = goog.isNull(this.checksums_) ||
var recalculate = !this.checksums_ ||
(strokeChecksum != this.checksums_[1] ||
fillChecksum != this.checksums_[2] ||
this.radius_ != this.checksums_[3] ||

View File

@@ -205,11 +205,11 @@ ol.style.Stroke.prototype.setWidth = function(width) {
ol.style.Stroke.prototype.getChecksum = function() {
if (this.checksum_ === undefined) {
var raw = 's' +
(!goog.isNull(this.color_) ?
(this.color_ ?
ol.color.asString(this.color_) : '-') + ',' +
(this.lineCap_ !== undefined ?
this.lineCap_.toString() : '-') + ',' +
(!goog.isNull(this.lineDash_) ?
(this.lineDash_ ?
this.lineDash_.toString() : '-') + ',' +
(this.lineJoin_ !== undefined ?
this.lineJoin_ : '-') + ',' +

View File

@@ -169,7 +169,7 @@ ol.style.Style.prototype.setGeometry = function(geometry) {
}
return result;
};
} else if (goog.isNull(geometry)) {
} else if (!geometry) {
this.geometryFunction_ = ol.style.defaultGeometryFunction;
} else if (geometry !== undefined) {
goog.asserts.assertInstanceof(geometry, ol.geom.Geometry,
@@ -255,7 +255,7 @@ ol.style.defaultStyleFunction = function(feature, resolution) {
// browsers that do not support Canvas. (ol.style.Circle does
// canvas.getContext('2d') at construction time, which will cause an.error
// in such browsers.)
if (goog.isNull(ol.style.defaultStyle_)) {
if (!ol.style.defaultStyle_) {
var fill = new ol.style.Fill({
color: 'rgba(255,255,255,0.4)'
});
@@ -366,7 +366,6 @@ ol.style.GeometryFunction;
* @return {ol.geom.Geometry|undefined} Geometry to render.
*/
ol.style.defaultGeometryFunction = function(feature) {
goog.asserts.assert(!goog.isNull(feature),
'feature must not be null');
goog.asserts.assert(feature, 'feature must not be null');
return feature.getGeometry();
};