Remove goog.isDef from drawinteraction

This commit is contained in:
Marc Jansen
2015-09-22 09:14:14 +02:00
committed by Tim Schaub
parent ceb39b0d07
commit eeba5f4d10

View File

@@ -112,22 +112,21 @@ ol.interaction.Draw = function(options) {
* @type {ol.source.Vector} * @type {ol.source.Vector}
* @private * @private
*/ */
this.source_ = goog.isDef(options.source) ? options.source : null; this.source_ = options.source ? options.source : null;
/** /**
* Target collection for drawn features. * Target collection for drawn features.
* @type {ol.Collection.<ol.Feature>} * @type {ol.Collection.<ol.Feature>}
* @private * @private
*/ */
this.features_ = goog.isDef(options.features) ? options.features : null; this.features_ = options.features ? options.features : null;
/** /**
* Pixel distance for snapping. * Pixel distance for snapping.
* @type {number} * @type {number}
* @private * @private
*/ */
this.snapTolerance_ = goog.isDef(options.snapTolerance) ? this.snapTolerance_ = options.snapTolerance ? options.snapTolerance : 12;
options.snapTolerance : 12;
/** /**
* Geometry type. * Geometry type.
@@ -150,7 +149,7 @@ ol.interaction.Draw = function(options) {
* @type {number} * @type {number}
* @private * @private
*/ */
this.minPoints_ = goog.isDef(options.minPoints) ? this.minPoints_ = options.minPoints ?
options.minPoints : options.minPoints :
(this.mode_ === ol.interaction.DrawMode.POLYGON ? 3 : 2); (this.mode_ === ol.interaction.DrawMode.POLYGON ? 3 : 2);
@@ -160,11 +159,10 @@ ol.interaction.Draw = function(options) {
* @type {number} * @type {number}
* @private * @private
*/ */
this.maxPoints_ = goog.isDef(options.maxPoints) ? this.maxPoints_ = options.maxPoints ? options.maxPoints : Infinity;
options.maxPoints : Infinity;
var geometryFunction = options.geometryFunction; var geometryFunction = options.geometryFunction;
if (!goog.isDef(geometryFunction)) { if (!geometryFunction) {
if (this.type_ === ol.geom.GeometryType.CIRCLE) { if (this.type_ === ol.geom.GeometryType.CIRCLE) {
/** /**
* @param {ol.Coordinate|Array.<ol.Coordinate>|Array.<Array.<ol.Coordinate>>} coordinates * @param {ol.Coordinate|Array.<ol.Coordinate>|Array.<Array.<ol.Coordinate>>} coordinates
@@ -172,7 +170,7 @@ ol.interaction.Draw = function(options) {
* @return {ol.geom.SimpleGeometry} * @return {ol.geom.SimpleGeometry}
*/ */
geometryFunction = function(coordinates, opt_geometry) { geometryFunction = function(coordinates, opt_geometry) {
var circle = goog.isDef(opt_geometry) ? opt_geometry : var circle = opt_geometry ? opt_geometry :
new ol.geom.Circle([NaN, NaN]); new ol.geom.Circle([NaN, NaN]);
goog.asserts.assertInstanceof(circle, ol.geom.Circle, goog.asserts.assertInstanceof(circle, ol.geom.Circle,
'geometry must be an ol.geom.Circle'); 'geometry must be an ol.geom.Circle');
@@ -198,7 +196,7 @@ ol.interaction.Draw = function(options) {
*/ */
geometryFunction = function(coordinates, opt_geometry) { geometryFunction = function(coordinates, opt_geometry) {
var geometry = opt_geometry; var geometry = opt_geometry;
if (goog.isDef(geometry)) { if (geometry) {
geometry.setCoordinates(coordinates); geometry.setCoordinates(coordinates);
} else { } else {
geometry = new Constructor(coordinates); geometry = new Constructor(coordinates);
@@ -264,7 +262,7 @@ ol.interaction.Draw = function(options) {
* @type {number} * @type {number}
* @private * @private
*/ */
this.squaredClickTolerance_ = goog.isDef(options.clickTolerance) ? this.squaredClickTolerance_ = options.clickTolerance ?
options.clickTolerance * options.clickTolerance : 36; options.clickTolerance * options.clickTolerance : 36;
/** /**
@@ -275,10 +273,10 @@ ol.interaction.Draw = function(options) {
this.overlay_ = new ol.layer.Vector({ this.overlay_ = new ol.layer.Vector({
source: new ol.source.Vector({ source: new ol.source.Vector({
useSpatialIndex: false, useSpatialIndex: false,
wrapX: goog.isDef(options.wrapX) ? options.wrapX : false wrapX: options.wrapX ? options.wrapX : false
}), }),
style: goog.isDef(options.style) ? style: options.style ? options.style :
options.style : ol.interaction.Draw.getDefaultStyleFunction() ol.interaction.Draw.getDefaultStyleFunction()
}); });
/** /**
@@ -292,14 +290,14 @@ ol.interaction.Draw = function(options) {
* @private * @private
* @type {ol.events.ConditionType} * @type {ol.events.ConditionType}
*/ */
this.condition_ = goog.isDef(options.condition) ? this.condition_ = options.condition ?
options.condition : ol.events.condition.noModifierKeys; options.condition : ol.events.condition.noModifierKeys;
/** /**
* @private * @private
* @type {ol.events.ConditionType} * @type {ol.events.ConditionType}
*/ */
this.freehandCondition_ = goog.isDef(options.freehandCondition) ? this.freehandCondition_ = options.freehandCondition ?
options.freehandCondition : ol.events.condition.shiftKeyOnly; options.freehandCondition : ol.events.condition.shiftKeyOnly;
goog.events.listen(this, goog.events.listen(this,
@@ -512,9 +510,9 @@ ol.interaction.Draw.prototype.startDrawing_ = function(event) {
new ol.geom.LineString(this.sketchLineCoords_)); new ol.geom.LineString(this.sketchLineCoords_));
} }
var geometry = this.geometryFunction_(this.sketchCoords_); var geometry = this.geometryFunction_(this.sketchCoords_);
goog.asserts.assert(goog.isDef(geometry), 'geometry should be defined'); goog.asserts.assert(geometry !== undefined, 'geometry should be defined');
this.sketchFeature_ = new ol.Feature(); this.sketchFeature_ = new ol.Feature();
if (goog.isDef(this.geometryName_)) { if (this.geometryName_) {
this.sketchFeature_.setGeometryName(this.geometryName_); this.sketchFeature_.setGeometryName(this.geometryName_);
} }
this.sketchFeature_.setGeometry(geometry); this.sketchFeature_.setGeometry(geometry);
@@ -806,11 +804,11 @@ ol.interaction.Draw.createRegularPolygon = function(opt_sides, opt_angle) {
var end = coordinates[1]; var end = coordinates[1];
var radius = Math.sqrt( var radius = Math.sqrt(
ol.coordinate.squaredDistance(center, end)); ol.coordinate.squaredDistance(center, end));
var geometry = goog.isDef(opt_geometry) ? opt_geometry : var geometry = opt_geometry ? opt_geometry :
ol.geom.Polygon.fromCircle(new ol.geom.Circle(center), opt_sides); ol.geom.Polygon.fromCircle(new ol.geom.Circle(center), opt_sides);
goog.asserts.assertInstanceof(geometry, ol.geom.Polygon, goog.asserts.assertInstanceof(geometry, ol.geom.Polygon,
'geometry must be a polygon'); 'geometry must be a polygon');
var angle = goog.isDef(opt_angle) ? opt_angle : var angle = opt_angle ? opt_angle :
Math.atan((end[1] - center[1]) / (end[0] - center[0])); Math.atan((end[1] - center[1]) / (end[0] - center[0]));
ol.geom.Polygon.makeRegular(geometry, center, radius, angle); ol.geom.Polygon.makeRegular(geometry, center, radius, angle);
return geometry; return geometry;
@@ -840,7 +838,7 @@ ol.interaction.Draw.getMode_ = function(type) {
} else if (type === ol.geom.GeometryType.CIRCLE) { } else if (type === ol.geom.GeometryType.CIRCLE) {
mode = ol.interaction.DrawMode.CIRCLE; mode = ol.interaction.DrawMode.CIRCLE;
} }
goog.asserts.assert(goog.isDef(mode), 'mode should be defined'); goog.asserts.assert(mode !== undefined, 'mode should be defined');
return mode; return mode;
}; };