Skip to content

Commit

Permalink
Display alert when RWD does not yield a valid watershed
Browse files Browse the repository at this point in the history
There are certain conditions where the RWD job completes successfully,
but does not yield a valid watershed. Without this alert, there is no
indication that the job completed or not.

The reason this is a plain alert box instead of something nicer, is
because we intend to address the cause behind the null watersheds soon.

Ref: WikiWatershed/rapid-watershed-delineation#27

Fixes WikiWatershed#1166
  • Loading branch information
Kevin DeLoach committed Mar 10, 2016
1 parent b6167ed commit 48151a6
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions src/mmw/js/src/draw/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,22 @@ function actOnLayer(datum) {
}
}

// Takes a GeoJSON shape, or if a key is specified, a dict
// with a GeoJSON object found at shape[shapeKey]
function validateShape(shape, shapeKey) {
var polygon = shapeKey ? shape[shapeKey] : shape,
area = coreUtils.changeOfAreaUnits(turfArea(shape), 'm<sup>2</sup>', 'km<sup>2</sup>'),
function validateRwdShape(result) {
var d = new $.Deferred();
if (result.watershed) {
validateShape(result.watershed)
.done(function() {
d.resolve(result);
})
.fail(d.reject);
} else {
d.reject(result);
}
return d.promise();
}

function validateShape(polygon) {
var area = coreUtils.changeOfAreaUnits(turfArea(polygon), 'm<sup>2</sup>', 'km<sup>2</sup>'),
d = new $.Deferred();

if (area > MAX_AREA) {
Expand Down Expand Up @@ -412,35 +423,34 @@ var WatershedDelineationView= Marionette.ItemView.extend({
self.rwdTaskModel.start(taskHelper);
return deferred;
})
.done(_.partialRight(validateShape, 'watershed'))
.then(validateRwdShape)
.done(function(result) {
if (result.watershed) {
var inputPoints = result.input_pt;
// add additional aoi points:w
if (inputPoints) {
var properties = inputPoints.features[0].properties;

// If the point was snapped, there will be the original
// point as attributes
if (properties.Dist_moved) {
inputPoints.features.push(
makePointGeoJson([properties.Lon, properties.Lat], {
original: true
})
);
}
App.map.set({
'areaOfInterestAdditionals': inputPoints
});
var inputPoints = result.input_pt;
// add additional aoi points:w
if (inputPoints) {
var properties = inputPoints.features[0].properties;

// If the point was snapped, there will be the original
// point as attributes
if (properties.Dist_moved) {
inputPoints.features.push(
makePointGeoJson([properties.Lon, properties.Lat], {
original: true
})
);
}

// Add Watershed AoI layer
addLayer(result.watershed, itemName);
navigateToAnalyze();
App.map.set({
'areaOfInterestAdditionals': inputPoints
});
}

// Add Watershed AoI layer
addLayer(result.watershed, itemName);
navigateToAnalyze();
})
.fail(function() {
revertLayer();
window.alert('Unable to delineate watershed at this location');
})
.always(function() {
self.model.enableTools();
Expand Down

0 comments on commit 48151a6

Please sign in to comment.