Remove goog.isNull in interaction classes

This commit is contained in:
Marc Jansen
2015-09-29 15:19:11 +02:00
parent 3c4e663224
commit be2e4a33ae
11 changed files with 52 additions and 56 deletions

View File

@@ -56,7 +56,7 @@ ol.interaction.DoubleClickZoom.handleEvent = function(mapBrowserEvent) {
var anchor = mapBrowserEvent.coordinate;
var delta = browserEvent.shiftKey ? -this.delta_ : this.delta_;
var view = map.getView();
goog.asserts.assert(!goog.isNull(view), 'view should not be null');
goog.asserts.assert(view, 'map must have a view');
ol.interaction.Interaction.zoomByDelta(
map, view, delta, anchor, this.duration_);
mapBrowserEvent.preventDefault();

View File

@@ -98,11 +98,11 @@ ol.interaction.DragAndDrop.prototype.handleDrop_ = function(event) {
*/
ol.interaction.DragAndDrop.prototype.handleResult_ = function(file, result) {
var map = this.getMap();
goog.asserts.assert(!goog.isNull(map), 'map should not be null');
goog.asserts.assert(map, 'map must be set');
var projection = this.projection_;
if (goog.isNull(projection)) {
if (!projection) {
var view = map.getView();
goog.asserts.assert(!goog.isNull(view), 'view should not be null');
goog.asserts.assert(view, 'map must have view');
projection = view.getProjection();
goog.asserts.assert(projection !== undefined,
'projection should be defined');
@@ -114,7 +114,7 @@ ol.interaction.DragAndDrop.prototype.handleResult_ = function(file, result) {
var formatConstructor = formatConstructors[i];
var format = new formatConstructor();
var readFeatures = this.tryReadFeatures_(format, result);
if (!goog.isNull(readFeatures)) {
if (readFeatures) {
var featureProjection = format.readProjection(result);
var transform = ol.proj.getTransform(featureProjection, projection);
var j, jj;
@@ -154,14 +154,14 @@ ol.interaction.DragAndDrop.prototype.setMap = function(map) {
goog.events.unlistenByKey(this.dropListenKey_);
this.dropListenKey_ = undefined;
}
if (!goog.isNull(this.fileDropHandler_)) {
if (this.fileDropHandler_) {
goog.dispose(this.fileDropHandler_);
this.fileDropHandler_ = null;
}
goog.asserts.assert(this.dropListenKey_ === undefined,
'this.dropListenKey_ should be undefined');
goog.base(this, 'setMap', map);
if (!goog.isNull(map)) {
if (map) {
this.fileDropHandler_ = new goog.events.FileDropHandler(map.getViewport());
this.dropListenKey_ = goog.events.listen(
this.fileDropHandler_, goog.events.FileDropHandler.EventType.DROP,

View File

@@ -77,7 +77,7 @@ ol.interaction.DragPan.handleDragEvent_ = function(mapBrowserEvent) {
if (this.kinetic_) {
this.kinetic_.update(centroid[0], centroid[1]);
}
if (!goog.isNull(this.lastCentroid)) {
if (this.lastCentroid) {
var deltaX = this.lastCentroid[0] - centroid[0];
var deltaY = centroid[1] - this.lastCentroid[1];
var map = mapBrowserEvent.map;
@@ -145,7 +145,7 @@ ol.interaction.DragPan.handleDownEvent_ = function(mapBrowserEvent) {
view.setHint(ol.ViewHint.INTERACTING, 1);
}
map.render();
if (!goog.isNull(this.kineticPreRenderFn_) &&
if (this.kineticPreRenderFn_ &&
map.removePreRenderFunction(this.kineticPreRenderFn_)) {
view.setCenter(mapBrowserEvent.frameState.viewState.center);
this.kineticPreRenderFn_ = null;

View File

@@ -61,7 +61,7 @@ ol.interaction.DragZoom.prototype.onBoxEnd = function() {
var map = this.getMap();
var view = map.getView();
goog.asserts.assert(!goog.isNull(view), 'view should not be null');
goog.asserts.assert(view, 'map must have view');
var size = map.getSize();
goog.asserts.assert(size !== undefined, 'size should be defined');

View File

@@ -367,7 +367,7 @@ ol.interaction.Draw.handleDownEvent_ = function(event) {
this.freehandCondition_(event)) {
this.downPx_ = event.pixel;
this.freehand_ = true;
if (goog.isNull(this.finishCoordinate_)) {
if (!this.finishCoordinate_) {
this.startDrawing_(event);
}
return true;
@@ -393,7 +393,7 @@ ol.interaction.Draw.handleUpEvent_ = function(event) {
var pass = true;
if (squaredDistance <= this.squaredClickTolerance_) {
this.handlePointerMove_(event);
if (goog.isNull(this.finishCoordinate_)) {
if (!this.finishCoordinate_) {
this.startDrawing_(event);
if (this.mode_ === ol.interaction.DrawMode.POINT) {
this.finishDrawing();
@@ -418,7 +418,7 @@ ol.interaction.Draw.handleUpEvent_ = function(event) {
* @private
*/
ol.interaction.Draw.prototype.handlePointerMove_ = function(event) {
if (!goog.isNull(this.finishCoordinate_)) {
if (this.finishCoordinate_) {
this.modifyDrawing_(event);
} else {
this.createOrUpdateSketchPoint_(event);
@@ -435,7 +435,7 @@ ol.interaction.Draw.prototype.handlePointerMove_ = function(event) {
*/
ol.interaction.Draw.prototype.atFinish_ = function(event) {
var at = false;
if (!goog.isNull(this.sketchFeature_)) {
if (this.sketchFeature_) {
var potentiallyDone = false;
var potentiallyFinishCoordinates = [this.finishCoordinate_];
if (this.mode_ === ol.interaction.DrawMode.LINE_STRING) {
@@ -474,7 +474,7 @@ ol.interaction.Draw.prototype.atFinish_ = function(event) {
*/
ol.interaction.Draw.prototype.createOrUpdateSketchPoint_ = function(event) {
var coordinates = event.coordinate.slice();
if (goog.isNull(this.sketchPoint_)) {
if (!this.sketchPoint_) {
this.sketchPoint_ = new ol.Feature(new ol.geom.Point(coordinates));
this.updateSketchFeatures_();
} else {
@@ -505,7 +505,7 @@ ol.interaction.Draw.prototype.startDrawing_ = function(event) {
this.sketchLineCoords_ = this.sketchCoords_;
}
}
if (!goog.isNull(this.sketchLineCoords_)) {
if (this.sketchLineCoords_) {
this.sketchLine_ = new ol.Feature(
new ol.geom.LineString(this.sketchLineCoords_));
}
@@ -548,10 +548,9 @@ ol.interaction.Draw.prototype.modifyDrawing_ = function(event) {
}
last[0] = coordinate[0];
last[1] = coordinate[1];
goog.asserts.assert(!goog.isNull(this.sketchCoords_),
'sketchCoords_ must not be null');
goog.asserts.assert(this.sketchCoords_, 'sketchCoords_ expected');
this.geometryFunction_(this.sketchCoords_, geometry);
if (!goog.isNull(this.sketchPoint_)) {
if (this.sketchPoint_) {
var sketchPointGeom = this.sketchPoint_.getGeometry();
goog.asserts.assertInstanceof(sketchPointGeom, ol.geom.Point,
'sketchPointGeom should be an ol.geom.Point');
@@ -560,7 +559,7 @@ ol.interaction.Draw.prototype.modifyDrawing_ = function(event) {
var sketchLineGeom;
if (geometry instanceof ol.geom.Polygon &&
this.mode_ !== ol.interaction.DrawMode.POLYGON) {
if (goog.isNull(this.sketchLine_)) {
if (!this.sketchLine_) {
this.sketchLine_ = new ol.Feature(new ol.geom.LineString(null));
}
var ring = geometry.getLinearRing(0);
@@ -569,7 +568,7 @@ ol.interaction.Draw.prototype.modifyDrawing_ = function(event) {
'sketchLineGeom must be an ol.geom.LineString');
sketchLineGeom.setFlatCoordinates(
ring.getLayout(), ring.getFlatCoordinates());
} else if (!goog.isNull(this.sketchLineCoords_)) {
} else if (this.sketchLineCoords_) {
sketchLineGeom = this.sketchLine_.getGeometry();
goog.asserts.assertInstanceof(sketchLineGeom, ol.geom.LineString,
'sketchLineGeom must be an ol.geom.LineString');
@@ -652,8 +651,7 @@ ol.interaction.Draw.prototype.removeLastPoint = function() {
*/
ol.interaction.Draw.prototype.finishDrawing = function() {
var sketchFeature = this.abortDrawing_();
goog.asserts.assert(!goog.isNull(sketchFeature),
'sketchFeature should not be null');
goog.asserts.assert(sketchFeature, 'sketchFeature expected to be truthy');
var coordinates = this.sketchCoords_;
var geometry = sketchFeature.getGeometry();
goog.asserts.assertInstanceof(geometry, ol.geom.SimpleGeometry,
@@ -685,10 +683,10 @@ ol.interaction.Draw.prototype.finishDrawing = function() {
ol.interaction.DrawEventType.DRAWEND, sketchFeature));
// Then insert feature
if (!goog.isNull(this.features_)) {
if (this.features_) {
this.features_.push(sketchFeature);
}
if (!goog.isNull(this.source_)) {
if (this.source_) {
this.source_.addFeature(sketchFeature);
}
};
@@ -702,7 +700,7 @@ ol.interaction.Draw.prototype.finishDrawing = function() {
ol.interaction.Draw.prototype.abortDrawing_ = function() {
this.finishCoordinate_ = null;
var sketchFeature = this.sketchFeature_;
if (!goog.isNull(sketchFeature)) {
if (sketchFeature) {
this.sketchFeature_ = null;
this.sketchPoint_ = null;
this.sketchLine_ = null;
@@ -750,13 +748,13 @@ ol.interaction.Draw.prototype.shouldStopEvent = goog.functions.FALSE;
*/
ol.interaction.Draw.prototype.updateSketchFeatures_ = function() {
var sketchFeatures = [];
if (!goog.isNull(this.sketchFeature_)) {
if (this.sketchFeature_) {
sketchFeatures.push(this.sketchFeature_);
}
if (!goog.isNull(this.sketchLine_)) {
if (this.sketchLine_) {
sketchFeatures.push(this.sketchLine_);
}
if (!goog.isNull(this.sketchPoint_)) {
if (this.sketchPoint_) {
sketchFeatures.push(this.sketchPoint_);
}
var overlaySource = this.overlay_.getSource();
@@ -771,7 +769,7 @@ ol.interaction.Draw.prototype.updateSketchFeatures_ = function() {
ol.interaction.Draw.prototype.updateState_ = function() {
var map = this.getMap();
var active = this.getActive();
if (goog.isNull(map) || !active) {
if (!map || !active) {
this.abortDrawing_();
}
this.overlay_.setMap(active ? map : null);

View File

@@ -85,7 +85,7 @@ ol.interaction.KeyboardPan.handleEvent = function(mapBrowserEvent) {
keyCode == goog.events.KeyCodes.UP)) {
var map = mapBrowserEvent.map;
var view = map.getView();
goog.asserts.assert(!goog.isNull(view), 'view should not be null');
goog.asserts.assert(view, 'map must have view');
var mapUnitsDelta = view.getResolution() * this.pixelDelta_;
var deltaX = 0, deltaY = 0;
if (keyCode == goog.events.KeyCodes.DOWN) {

View File

@@ -77,7 +77,7 @@ ol.interaction.KeyboardZoom.handleEvent = function(mapBrowserEvent) {
var delta = (charCode == '+'.charCodeAt(0)) ? this.delta_ : -this.delta_;
map.render();
var view = map.getView();
goog.asserts.assert(!goog.isNull(view), 'view should not be null');
goog.asserts.assert(view, 'map must have view');
ol.interaction.Interaction.zoomByDelta(
map, view, delta, undefined, this.duration_);
mapBrowserEvent.preventDefault();

View File

@@ -243,7 +243,7 @@ ol.interaction.Modify.prototype.addFeature_ = function(feature) {
this.SEGMENT_WRITERS_[geometry.getType()].call(this, feature, geometry);
}
var map = this.getMap();
if (!goog.isNull(map)) {
if (map) {
this.handlePointerAtPixel_(this.lastPixel_, map);
}
goog.events.listen(feature, goog.events.EventType.CHANGE,
@@ -259,8 +259,7 @@ ol.interaction.Modify.prototype.removeFeature_ = function(feature) {
this.removeFeatureSegmentData_(feature);
// Remove the vertex feature if the collection of canditate features
// is empty.
if (!goog.isNull(this.vertexFeature_) &&
this.features_.getLength() === 0) {
if (this.vertexFeature_ && this.features_.getLength() === 0) {
this.overlay_.getSource().removeFeature(this.vertexFeature_);
this.vertexFeature_ = null;
}
@@ -501,7 +500,7 @@ ol.interaction.Modify.prototype.writeGeometryCollectionGeometry_ =
ol.interaction.Modify.prototype.createOrUpdateVertexFeature_ =
function(coordinates) {
var vertexFeature = this.vertexFeature_;
if (goog.isNull(vertexFeature)) {
if (!vertexFeature) {
vertexFeature = new ol.Feature(new ol.geom.Point(coordinates));
this.vertexFeature_ = vertexFeature;
this.overlay_.getSource().addFeature(vertexFeature);
@@ -534,7 +533,7 @@ ol.interaction.Modify.handleDownEvent_ = function(evt) {
this.handlePointerAtPixel_(evt.pixel, evt.map);
this.dragSegments_ = [];
var vertexFeature = this.vertexFeature_;
if (!goog.isNull(vertexFeature)) {
if (vertexFeature) {
var insertVertices = [];
var geometry = /** @type {ol.geom.Point} */ (vertexFeature.getGeometry());
var vertex = geometry.getCoordinates();
@@ -584,7 +583,7 @@ ol.interaction.Modify.handleDownEvent_ = function(evt) {
new ol.interaction.ModifyEvent(ol.ModifyEventType.MODIFYSTART,
this.features_, evt));
}
return !goog.isNull(this.vertexFeature_);
return this.vertexFeature_ !== null;
};
@@ -678,8 +677,7 @@ ol.interaction.Modify.handleEvent = function(mapBrowserEvent) {
!this.handlingDownUpSequence) {
this.handlePointerMove_(mapBrowserEvent);
}
if (!goog.isNull(this.vertexFeature_) &&
this.deleteCondition_(mapBrowserEvent)) {
if (this.vertexFeature_ && this.deleteCondition_(mapBrowserEvent)) {
if (mapBrowserEvent.type != ol.MapBrowserEvent.EventType.SINGLECLICK ||
!this.ignoreNextSingleClick_) {
var geometry = this.vertexFeature_.getGeometry();
@@ -768,7 +766,7 @@ ol.interaction.Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
return;
}
}
if (!goog.isNull(this.vertexFeature_)) {
if (this.vertexFeature_) {
this.overlay_.getSource().removeFeature(this.vertexFeature_);
this.vertexFeature_ = null;
}
@@ -940,7 +938,7 @@ ol.interaction.Modify.prototype.removeVertex_ = function() {
newSegmentData);
this.updateSegmentIndices_(geometry, index, segmentData.depth, -1);
if (!goog.isNull(this.vertexFeature_)) {
if (this.vertexFeature_) {
this.overlay_.getSource().removeFeature(this.vertexFeature_);
this.vertexFeature_ = null;
}

View File

@@ -117,7 +117,7 @@ ol.interaction.MouseWheelZoom.prototype.doZoom_ = function(map) {
var delta = ol.math.clamp(this.delta_, -maxDelta, maxDelta);
var view = map.getView();
goog.asserts.assert(!goog.isNull(view), 'view should not be null');
goog.asserts.assert(view, 'map must have view');
map.render();
ol.interaction.Interaction.zoomByDelta(map, view, -delta, this.lastAnchor_,

View File

@@ -205,9 +205,9 @@ ol.interaction.Snap.prototype.forEachFeatureRemove_ = function(feature) {
*/
ol.interaction.Snap.prototype.getFeatures_ = function() {
var features;
if (!goog.isNull(this.features_)) {
if (this.features_) {
features = this.features_;
} else if (!goog.isNull(this.source_)) {
} else if (this.source_) {
features = this.source_.getFeatures();
}
goog.asserts.assert(features !== undefined, 'features should be defined');
@@ -328,12 +328,12 @@ ol.interaction.Snap.prototype.setMap = function(map) {
goog.base(this, 'setMap', map);
if (map) {
if (!goog.isNull(this.features_)) {
if (this.features_) {
keys.push(this.features_.on(ol.CollectionEventType.ADD,
this.handleFeatureAdd_, this));
keys.push(this.features_.on(ol.CollectionEventType.REMOVE,
this.handleFeatureRemove_, this));
} else if (!goog.isNull(this.source_)) {
} else if (this.source_) {
keys.push(this.source_.on(ol.source.VectorEventType.ADDFEATURE,
this.handleFeatureAdd_, this));
keys.push(this.source_.on(ol.source.VectorEventType.REMOVEFEATURE,

View File

@@ -61,7 +61,7 @@ goog.inherits(ol.interaction.Translate, ol.interaction.Pointer);
*/
ol.interaction.Translate.handleDownEvent_ = function(event) {
this.lastFeature_ = this.featuresAtPixel_(event.pixel, event.map);
if (goog.isNull(this.lastCoordinate_) && !goog.isNull(this.lastFeature_)) {
if (!this.lastCoordinate_ && this.lastFeature_) {
this.lastCoordinate_ = event.coordinate;
ol.interaction.Translate.handleMoveEvent_.call(this, event);
return true;
@@ -77,7 +77,7 @@ ol.interaction.Translate.handleDownEvent_ = function(event) {
* @private
*/
ol.interaction.Translate.handleUpEvent_ = function(event) {
if (!goog.isNull(this.lastCoordinate_)) {
if (this.lastCoordinate_) {
this.lastCoordinate_ = null;
ol.interaction.Translate.handleMoveEvent_.call(this, event);
return true;
@@ -92,18 +92,18 @@ ol.interaction.Translate.handleUpEvent_ = function(event) {
* @private
*/
ol.interaction.Translate.handleDragEvent_ = function(event) {
if (!goog.isNull(this.lastCoordinate_)) {
if (this.lastCoordinate_) {
var newCoordinate = event.coordinate;
var deltaX = newCoordinate[0] - this.lastCoordinate_[0];
var deltaY = newCoordinate[1] - this.lastCoordinate_[1];
if (!goog.isNull(this.features_)) {
if (this.features_) {
this.features_.forEach(function(feature) {
var geom = feature.getGeometry();
geom.translate(deltaX, deltaY);
feature.setGeometry(geom);
});
} else if (goog.isNull(this.lastFeature_)) {
} else if (this.lastFeature_) {
var geom = this.lastFeature_.getGeometry();
geom.translate(deltaX, deltaY);
this.lastFeature_.setGeometry(geom);
@@ -130,7 +130,7 @@ ol.interaction.Translate.handleMoveEvent_ = function(event)
if (intersectingFeature) {
var isSelected = false;
if (!goog.isNull(this.features_) &&
if (this.features_ &&
ol.array.includes(this.features_.getArray(), intersectingFeature)) {
isSelected = true;
}
@@ -138,12 +138,12 @@ ol.interaction.Translate.handleMoveEvent_ = function(event)
this.previousCursor_ = elem.style.cursor;
// WebKit browsers don't support the grab icons without a prefix
elem.style.cursor = !goog.isNull(this.lastCoordinate_) ?
elem.style.cursor = this.lastCoordinate_ ?
'-webkit-grabbing' : (isSelected ? '-webkit-grab' : 'pointer');
// Thankfully, attempting to set the standard ones will silently fail,
// keeping the prefixed icons
elem.style.cursor = goog.isNull(this.lastCoordinate_) ?
elem.style.cursor = !this.lastCoordinate_ ?
'grabbing' : (isSelected ? 'grab' : 'pointer');
} else {
@@ -171,7 +171,7 @@ ol.interaction.Translate.prototype.featuresAtPixel_ = function(pixel, map) {
return feature;
});
if (!goog.isNull(this.features_) &&
if (this.features_ &&
ol.array.includes(this.features_.getArray(), intersectingFeature)) {
found = intersectingFeature;
}