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
+7 -9
View File
@@ -97,13 +97,12 @@ ol.style.AtlasManager.prototype.getInfo = function(id) {
/** @type {?ol.style.AtlasInfo} */ /** @type {?ol.style.AtlasInfo} */
var info = this.getInfo_(this.atlases_, id); var info = this.getInfo_(this.atlases_, id);
if (goog.isNull(info)) { if (!info) {
return null; return null;
} }
/** @type {?ol.style.AtlasInfo} */ /** @type {?ol.style.AtlasInfo} */
var hitInfo = this.getInfo_(this.hitAtlases_, id); var hitInfo = this.getInfo_(this.hitAtlases_, id);
goog.asserts.assert(!goog.isNull(hitInfo), goog.asserts.assert(hitInfo, 'hitInfo must not be null');
'hitInfo must not be null');
return this.mergeInfos_(info, hitInfo); 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) { for (i = 0, ii = atlases.length; i < ii; ++i) {
atlas = atlases[i]; atlas = atlases[i];
info = atlas.get(id); info = atlas.get(id);
if (!goog.isNull(info)) { if (info) {
return info; return info;
} }
} }
@@ -184,7 +183,7 @@ ol.style.AtlasManager.prototype.add =
/** @type {?ol.style.AtlasInfo} */ /** @type {?ol.style.AtlasInfo} */
var info = this.add_(false, var info = this.add_(false,
id, width, height, renderCallback, opt_this); id, width, height, renderCallback, opt_this);
if (goog.isNull(info)) { if (!info) {
return null; return null;
} }
@@ -197,8 +196,7 @@ ol.style.AtlasManager.prototype.add =
/** @type {?ol.style.AtlasInfo} */ /** @type {?ol.style.AtlasInfo} */
var hitInfo = this.add_(true, var hitInfo = this.add_(true,
id, width, height, renderHitCallback, opt_this); id, width, height, renderHitCallback, opt_this);
goog.asserts.assert(!goog.isNull(hitInfo), goog.asserts.assert(hitInfo, 'hitInfo must not be null');
'hitInfo must not be null');
return this.mergeInfos_(info, hitInfo); return this.mergeInfos_(info, hitInfo);
}; };
@@ -225,9 +223,9 @@ ol.style.AtlasManager.prototype.add_ =
for (i = 0, ii = atlases.length; i < ii; ++i) { for (i = 0, ii = atlases.length; i < ii; ++i) {
atlas = atlases[i]; atlas = atlases[i];
info = atlas.add(id, width, height, renderCallback, opt_this); info = atlas.add(id, width, height, renderCallback, opt_this);
if (!goog.isNull(info)) { if (info) {
return 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, // 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. // create a new atlas that is twice as big and try to add to this one.
var size; var size;
+12 -12
View File
@@ -247,7 +247,7 @@ ol.style.Circle.prototype.render_ = function(atlasManager) {
var strokeStyle; var strokeStyle;
var strokeWidth = 0; var strokeWidth = 0;
if (!goog.isNull(this.stroke_)) { if (this.stroke_) {
strokeStyle = ol.color.asString(this.stroke_.getColor()); strokeStyle = ol.color.asString(this.stroke_.getColor());
strokeWidth = this.stroke_.getWidth(); strokeWidth = this.stroke_.getWidth();
if (strokeWidth === undefined) { 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 // an atlas manager is used, add the symbol to an atlas
size = Math.round(size); size = Math.round(size);
var hasCustomHitDetectionImage = goog.isNull(this.fill_); var hasCustomHitDetectionImage = !this.fill_;
var renderHitDetectionCallback; var renderHitDetectionCallback;
if (hasCustomHitDetectionImage) { if (hasCustomHitDetectionImage) {
// render the hit-detection image into a separate atlas image // 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( var info = atlasManager.add(
id, size, size, goog.bind(this.draw_, this, renderOptions), id, size, size, goog.bind(this.draw_, this, renderOptions),
renderHitDetectionCallback); 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.canvas_ = info.image;
this.origin_ = [info.offsetX, info.offsetY]; 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, renderOptions.size / 2, renderOptions.size / 2,
this.radius_, 0, 2 * Math.PI, true); this.radius_, 0, 2 * Math.PI, true);
if (!goog.isNull(this.fill_)) { if (this.fill_) {
context.fillStyle = ol.color.asString(this.fill_.getColor()); context.fillStyle = ol.color.asString(this.fill_.getColor());
context.fill(); context.fill();
} }
if (!goog.isNull(this.stroke_)) { if (this.stroke_) {
context.strokeStyle = renderOptions.strokeStyle; context.strokeStyle = renderOptions.strokeStyle;
context.lineWidth = renderOptions.strokeWidth; context.lineWidth = renderOptions.strokeWidth;
if (!goog.isNull(renderOptions.lineDash)) { if (renderOptions.lineDash) {
context.setLineDash(renderOptions.lineDash); context.setLineDash(renderOptions.lineDash);
} }
context.stroke(); context.stroke();
@@ -366,7 +366,7 @@ ol.style.Circle.prototype.draw_ = function(renderOptions, context, x, y) {
*/ */
ol.style.Circle.prototype.createHitDetectionCanvas_ = function(renderOptions) { ol.style.Circle.prototype.createHitDetectionCanvas_ = function(renderOptions) {
this.hitDetectionImageSize_ = [renderOptions.size, renderOptions.size]; this.hitDetectionImageSize_ = [renderOptions.size, renderOptions.size];
if (!goog.isNull(this.fill_)) { if (this.fill_) {
this.hitDetectionCanvas_ = this.canvas_; this.hitDetectionCanvas_ = this.canvas_;
return; return;
} }
@@ -408,10 +408,10 @@ ol.style.Circle.prototype.drawHitDetectionCanvas_ =
context.fillStyle = ol.color.asString(ol.render.canvas.defaultFillStyle); context.fillStyle = ol.color.asString(ol.render.canvas.defaultFillStyle);
context.fill(); context.fill();
if (!goog.isNull(this.stroke_)) { if (this.stroke_) {
context.strokeStyle = renderOptions.strokeStyle; context.strokeStyle = renderOptions.strokeStyle;
context.lineWidth = renderOptions.strokeWidth; context.lineWidth = renderOptions.strokeWidth;
if (!goog.isNull(renderOptions.lineDash)) { if (renderOptions.lineDash) {
context.setLineDash(renderOptions.lineDash); context.setLineDash(renderOptions.lineDash);
} }
context.stroke(); context.stroke();
@@ -424,12 +424,12 @@ ol.style.Circle.prototype.drawHitDetectionCanvas_ =
* @inheritDoc * @inheritDoc
*/ */
ol.style.Circle.prototype.getChecksum = function() { ol.style.Circle.prototype.getChecksum = function() {
var strokeChecksum = !goog.isNull(this.stroke_) ? var strokeChecksum = this.stroke_ ?
this.stroke_.getChecksum() : '-'; this.stroke_.getChecksum() : '-';
var fillChecksum = !goog.isNull(this.fill_) ? var fillChecksum = this.fill_ ?
this.fill_.getChecksum() : '-'; this.fill_.getChecksum() : '-';
var recalculate = goog.isNull(this.checksums_) || var recalculate = !this.checksums_ ||
(strokeChecksum != this.checksums_[1] || (strokeChecksum != this.checksums_[1] ||
fillChecksum != this.checksums_[2] || fillChecksum != this.checksums_[2] ||
this.radius_ != this.checksums_[3]); this.radius_ != this.checksums_[3]);
+1 -1
View File
@@ -59,7 +59,7 @@ ol.style.Fill.prototype.setColor = function(color) {
*/ */
ol.style.Fill.prototype.getChecksum = function() { ol.style.Fill.prototype.getChecksum = function() {
if (this.checksum_ === undefined) { if (this.checksum_ === undefined) {
this.checksum_ = 'f' + (!goog.isNull(this.color_) ? this.checksum_ = 'f' + (this.color_ ?
ol.color.asString(this.color_) : '-'); ol.color.asString(this.color_) : '-');
} }
+16 -16
View File
@@ -104,16 +104,16 @@ ol.style.Icon = function(opt_options) {
*/ */
var src = options.src; 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'); 'image and src can not provided at the same time');
goog.asserts.assert( goog.asserts.assert(
src === undefined || (src !== undefined && goog.isNull(imgSize)), src === undefined || (src !== undefined && !imgSize),
'imgSize should not be set when src is provided'); 'imgSize should not be set when src is provided');
goog.asserts.assert( goog.asserts.assert(
goog.isNull(image) || (!goog.isNull(image) && !goog.isNull(imgSize)), !image || (image && imgSize),
'imgSize must be set when image is provided'); '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; src = image.src;
} }
goog.asserts.assert(src !== undefined && src.length > 0, goog.asserts.assert(src !== undefined && src.length > 0,
@@ -201,14 +201,14 @@ goog.inherits(ol.style.Icon, ol.style.Image);
* @api * @api
*/ */
ol.style.Icon.prototype.getAnchor = function() { ol.style.Icon.prototype.getAnchor = function() {
if (!goog.isNull(this.normalizedAnchor_)) { if (this.normalizedAnchor_) {
return this.normalizedAnchor_; return this.normalizedAnchor_;
} }
var anchor = this.anchor_; var anchor = this.anchor_;
var size = this.getSize(); var size = this.getSize();
if (this.anchorXUnits_ == ol.style.IconAnchorUnits.FRACTION || if (this.anchorXUnits_ == ol.style.IconAnchorUnits.FRACTION ||
this.anchorYUnits_ == ol.style.IconAnchorUnits.FRACTION) { this.anchorYUnits_ == ol.style.IconAnchorUnits.FRACTION) {
if (goog.isNull(size)) { if (!size) {
return null; return null;
} }
anchor = this.anchor_.slice(); anchor = this.anchor_.slice();
@@ -221,7 +221,7 @@ ol.style.Icon.prototype.getAnchor = function() {
} }
if (this.anchorOrigin_ != ol.style.IconOrigin.TOP_LEFT) { if (this.anchorOrigin_ != ol.style.IconOrigin.TOP_LEFT) {
if (goog.isNull(size)) { if (!size) {
return null; return null;
} }
if (anchor === this.anchor_) { if (anchor === this.anchor_) {
@@ -290,7 +290,7 @@ ol.style.Icon.prototype.getHitDetectionImage = function(pixelRatio) {
* @api * @api
*/ */
ol.style.Icon.prototype.getOrigin = function() { ol.style.Icon.prototype.getOrigin = function() {
if (!goog.isNull(this.origin_)) { if (this.origin_) {
return this.origin_; return this.origin_;
} }
var offset = this.offset_; var offset = this.offset_;
@@ -298,7 +298,7 @@ ol.style.Icon.prototype.getOrigin = function() {
if (this.offsetOrigin_ != ol.style.IconOrigin.TOP_LEFT) { if (this.offsetOrigin_ != ol.style.IconOrigin.TOP_LEFT) {
var size = this.getSize(); var size = this.getSize();
var iconImageSize = this.iconImage_.getSize(); var iconImageSize = this.iconImage_.getSize();
if (goog.isNull(size) || goog.isNull(iconImageSize)) { if (!size || !iconImageSize) {
return null; return null;
} }
offset = offset.slice(); offset = offset.slice();
@@ -331,7 +331,7 @@ ol.style.Icon.prototype.getSrc = function() {
* @api * @api
*/ */
ol.style.Icon.prototype.getSize = function() { 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 * @private
* @type {Image} * @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; 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) { ol.style.IconImage_.get = function(image, src, size, crossOrigin, imageState) {
var iconImageCache = ol.style.IconImageCache.getInstance(); var iconImageCache = ol.style.IconImageCache.getInstance();
var iconImage = iconImageCache.get(src, crossOrigin); var iconImage = iconImageCache.get(src, crossOrigin);
if (goog.isNull(iconImage)) { if (!iconImage) {
iconImage = new ol.style.IconImage_( iconImage = new ol.style.IconImage_(
image, src, size, crossOrigin, imageState); image, src, size, crossOrigin, imageState);
iconImageCache.set(src, crossOrigin, iconImage); iconImageCache.set(src, crossOrigin, iconImage);
@@ -516,7 +516,7 @@ ol.style.IconImage_.prototype.getImageState = function() {
* @return {Image|HTMLCanvasElement} Image element. * @return {Image|HTMLCanvasElement} Image element.
*/ */
ol.style.IconImage_.prototype.getHitDetectionImage = function(pixelRatio) { ol.style.IconImage_.prototype.getHitDetectionImage = function(pixelRatio) {
if (goog.isNull(this.hitDetectionImage_)) { if (!this.hitDetectionImage_) {
if (this.tainting_) { if (this.tainting_) {
var width = this.size_[0]; var width = this.size_[0];
var height = this.size_[1]; var height = this.size_[1];
@@ -554,7 +554,7 @@ ol.style.IconImage_.prototype.load = function() {
if (this.imageState_ == ol.style.ImageState.IDLE) { if (this.imageState_ == ol.style.ImageState.IDLE) {
goog.asserts.assert(this.src_ !== undefined, goog.asserts.assert(this.src_ !== undefined,
'this.src_ must not be undefined'); 'this.src_ must not be undefined');
goog.asserts.assert(goog.isNull(this.imageListenerKeys_), goog.asserts.assert(!this.imageListenerKeys_,
'no listener keys existing'); 'no listener keys existing');
this.imageState_ = ol.style.ImageState.LOADING; this.imageState_ = ol.style.ImageState.LOADING;
this.imageListenerKeys_ = [ this.imageListenerKeys_ = [
@@ -578,7 +578,7 @@ ol.style.IconImage_.prototype.load = function() {
* @private * @private
*/ */
ol.style.IconImage_.prototype.unlistenImage_ = function() { ol.style.IconImage_.prototype.unlistenImage_ = function() {
goog.asserts.assert(!goog.isNull(this.imageListenerKeys_), goog.asserts.assert(this.imageListenerKeys_,
'we must have listeners registered'); 'we must have listeners registered');
this.imageListenerKeys_.forEach(goog.events.unlistenByKey); this.imageListenerKeys_.forEach(goog.events.unlistenByKey);
this.imageListenerKeys_ = null; this.imageListenerKeys_ = null;
+12 -12
View File
@@ -313,7 +313,7 @@ ol.style.RegularShape.prototype.render_ = function(atlasManager) {
var strokeStyle; var strokeStyle;
var strokeWidth = 0; var strokeWidth = 0;
if (!goog.isNull(this.stroke_)) { if (this.stroke_) {
strokeStyle = ol.color.asString(this.stroke_.getColor()); strokeStyle = ol.color.asString(this.stroke_.getColor());
strokeWidth = this.stroke_.getWidth(); strokeWidth = this.stroke_.getWidth();
if (strokeWidth === undefined) { 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 // an atlas manager is used, add the symbol to an atlas
size = Math.round(size); size = Math.round(size);
var hasCustomHitDetectionImage = goog.isNull(this.fill_); var hasCustomHitDetectionImage = !this.fill_;
var renderHitDetectionCallback; var renderHitDetectionCallback;
if (hasCustomHitDetectionImage) { if (hasCustomHitDetectionImage) {
// render the hit-detection image into a separate atlas image // 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( var info = atlasManager.add(
id, size, size, goog.bind(this.draw_, this, renderOptions), id, size, size, goog.bind(this.draw_, this, renderOptions),
renderHitDetectionCallback); 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.canvas_ = info.image;
this.origin_ = [info.offsetX, info.offsetY]; 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)); renderOptions.size / 2 + radiusC * Math.sin(angle0));
} }
if (!goog.isNull(this.fill_)) { if (this.fill_) {
context.fillStyle = ol.color.asString(this.fill_.getColor()); context.fillStyle = ol.color.asString(this.fill_.getColor());
context.fill(); context.fill();
} }
if (!goog.isNull(this.stroke_)) { if (this.stroke_) {
context.strokeStyle = renderOptions.strokeStyle; context.strokeStyle = renderOptions.strokeStyle;
context.lineWidth = renderOptions.strokeWidth; context.lineWidth = renderOptions.strokeWidth;
if (!goog.isNull(renderOptions.lineDash)) { if (renderOptions.lineDash) {
context.setLineDash(renderOptions.lineDash); context.setLineDash(renderOptions.lineDash);
} }
context.lineCap = renderOptions.lineCap; context.lineCap = renderOptions.lineCap;
@@ -457,7 +457,7 @@ ol.style.RegularShape.prototype.draw_ = function(renderOptions, context, x, y) {
ol.style.RegularShape.prototype.createHitDetectionCanvas_ = ol.style.RegularShape.prototype.createHitDetectionCanvas_ =
function(renderOptions) { function(renderOptions) {
this.hitDetectionImageSize_ = [renderOptions.size, renderOptions.size]; this.hitDetectionImageSize_ = [renderOptions.size, renderOptions.size];
if (!goog.isNull(this.fill_)) { if (this.fill_) {
this.hitDetectionCanvas_ = this.canvas_; this.hitDetectionCanvas_ = this.canvas_;
return; return;
} }
@@ -506,10 +506,10 @@ ol.style.RegularShape.prototype.drawHitDetectionCanvas_ =
context.fillStyle = ol.render.canvas.defaultFillStyle; context.fillStyle = ol.render.canvas.defaultFillStyle;
context.fill(); context.fill();
if (!goog.isNull(this.stroke_)) { if (this.stroke_) {
context.strokeStyle = renderOptions.strokeStyle; context.strokeStyle = renderOptions.strokeStyle;
context.lineWidth = renderOptions.strokeWidth; context.lineWidth = renderOptions.strokeWidth;
if (!goog.isNull(renderOptions.lineDash)) { if (renderOptions.lineDash) {
context.setLineDash(renderOptions.lineDash); context.setLineDash(renderOptions.lineDash);
} }
context.stroke(); context.stroke();
@@ -522,12 +522,12 @@ ol.style.RegularShape.prototype.drawHitDetectionCanvas_ =
* @inheritDoc * @inheritDoc
*/ */
ol.style.RegularShape.prototype.getChecksum = function() { ol.style.RegularShape.prototype.getChecksum = function() {
var strokeChecksum = !goog.isNull(this.stroke_) ? var strokeChecksum = this.stroke_ ?
this.stroke_.getChecksum() : '-'; this.stroke_.getChecksum() : '-';
var fillChecksum = !goog.isNull(this.fill_) ? var fillChecksum = this.fill_ ?
this.fill_.getChecksum() : '-'; this.fill_.getChecksum() : '-';
var recalculate = goog.isNull(this.checksums_) || var recalculate = !this.checksums_ ||
(strokeChecksum != this.checksums_[1] || (strokeChecksum != this.checksums_[1] ||
fillChecksum != this.checksums_[2] || fillChecksum != this.checksums_[2] ||
this.radius_ != this.checksums_[3] || this.radius_ != this.checksums_[3] ||
+2 -2
View File
@@ -205,11 +205,11 @@ ol.style.Stroke.prototype.setWidth = function(width) {
ol.style.Stroke.prototype.getChecksum = function() { ol.style.Stroke.prototype.getChecksum = function() {
if (this.checksum_ === undefined) { if (this.checksum_ === undefined) {
var raw = 's' + var raw = 's' +
(!goog.isNull(this.color_) ? (this.color_ ?
ol.color.asString(this.color_) : '-') + ',' + ol.color.asString(this.color_) : '-') + ',' +
(this.lineCap_ !== undefined ? (this.lineCap_ !== undefined ?
this.lineCap_.toString() : '-') + ',' + this.lineCap_.toString() : '-') + ',' +
(!goog.isNull(this.lineDash_) ? (this.lineDash_ ?
this.lineDash_.toString() : '-') + ',' + this.lineDash_.toString() : '-') + ',' +
(this.lineJoin_ !== undefined ? (this.lineJoin_ !== undefined ?
this.lineJoin_ : '-') + ',' + this.lineJoin_ : '-') + ',' +
+3 -4
View File
@@ -169,7 +169,7 @@ ol.style.Style.prototype.setGeometry = function(geometry) {
} }
return result; return result;
}; };
} else if (goog.isNull(geometry)) { } else if (!geometry) {
this.geometryFunction_ = ol.style.defaultGeometryFunction; this.geometryFunction_ = ol.style.defaultGeometryFunction;
} else if (geometry !== undefined) { } else if (geometry !== undefined) {
goog.asserts.assertInstanceof(geometry, ol.geom.Geometry, 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 // browsers that do not support Canvas. (ol.style.Circle does
// canvas.getContext('2d') at construction time, which will cause an.error // canvas.getContext('2d') at construction time, which will cause an.error
// in such browsers.) // in such browsers.)
if (goog.isNull(ol.style.defaultStyle_)) { if (!ol.style.defaultStyle_) {
var fill = new ol.style.Fill({ var fill = new ol.style.Fill({
color: 'rgba(255,255,255,0.4)' color: 'rgba(255,255,255,0.4)'
}); });
@@ -366,7 +366,6 @@ ol.style.GeometryFunction;
* @return {ol.geom.Geometry|undefined} Geometry to render. * @return {ol.geom.Geometry|undefined} Geometry to render.
*/ */
ol.style.defaultGeometryFunction = function(feature) { ol.style.defaultGeometryFunction = function(feature) {
goog.asserts.assert(!goog.isNull(feature), goog.asserts.assert(feature, 'feature must not be null');
'feature must not be null');
return feature.getGeometry(); return feature.getGeometry();
}; };