Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display alert when RWD does not yield a valid watershed #1175

Merged
merged 1 commit into from
Mar 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this will actually fix a newly reported bug #1166

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