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
Add Subbasin NHD+ Table #2794
Add Subbasin NHD+ Table #2794
Conversation
Add an endpoint similar to the subbasin huc12s endpoint to fetch the id, area, shape, and streams for a set of catchment ids. GET /mmw/modeling/subbasins/catchments/?catchment_comids=%255B%25224780661%2522%252C%25224780663%2522%252C%25224780665%2522%252C%25224780751%2522%252C%25224782293%2522%252C%25224782295%2522%252C%25224782297%2522%252C%25224782307%2522%255D -- where `catchment_comids` is a urlencoded json array Response: [ { "id": 423312 // comid "shape": { "type": "MultiPolygon", ...}, // catchment geojson "stream": { "type": "MultiLineString", ...}, // stream geojson "area": 4.3111 // area in hectares }, ... ]
4f4fdb1
to
a65679a
Compare
Hm, I noticed that intermittently before I moved that bootstrap init call to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 great work. This works really well on the whole.
Sending the list of catchments as a URL encoded JSON array is an interesting choice, but it works so I'm not going to challenge it right now 🚀 🐦 .
Code comments are minor suggestions, all optional. The only thing we should fix before merging is the .bootstrapTable()
calls so that they always work.
src/mmw/js/src/modeling/models.js
Outdated
|
||
fetchCatchmentsIfNeeded: function(comids) { | ||
var catchments = this.get('catchments'); | ||
if (!catchments.isEmpty() || this.fetchCatchmentsPromise) { return; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer returning an immediately resolved promise rather than nothing:
return $.when();
src/mmw/js/src/modeling/models.js
Outdated
if (!catchments.isEmpty() || this.fetchCatchmentsPromise) { return; } | ||
|
||
var encodedComids = encodeURIComponent(JSON.stringify(comids)); | ||
this.fetchCatchmentsPromise = catchments.fetch({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, prefer returning this promise rather than losing the reference. This allows the possibility of usage like:
subbasins.fetchCatchmentsIfNeeded.then(function() { ... });
if (this.catchmentDetails.isEmpty()) { | ||
self.listenToOnce(self.catchmentDetails, 'add', this.setupCatchmentDetails, this); | ||
} else { | ||
this.setupCatchmentDetails(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling render
within initialize
feels like a mistake ... but I'm not seeing any errors in the console. It is possible that this is the cause of the broken bootstrap table. Consider moving it to a custom function and calling that directly here, and also from within onRender
.
Great suggestions re: promises. I've pushed one fixup to address the fetching, and another for the table renders (I believe the issue is fixed now though it doesn't look all that pretty).
Definitely with you on this — I wanted it to stay a GET request like its HUC-12 sibling, and for some reason didn't want to consider how the list should come in. Encoding a JSON array happens easily and predictably so it seems okay for now! 🚀 🐦 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 this works great! The bootstrapTable is rendered correctly every time. I did add comment for a slight adjustment to the promises, but after that this should be ready to merge. Nice work!
src/mmw/js/src/modeling/models.js
Outdated
@@ -825,14 +825,17 @@ var SubbasinDetailModel = Backbone.Model.extend({ | |||
|
|||
fetchCatchmentsIfNeeded: function(comids) { | |||
var catchments = this.get('catchments'); | |||
if (!catchments.isEmpty() || this.fetchCatchmentsPromise) { return; } | |||
if (!catchments.isEmpty() || this.fetchCatchmentsPromise) { | |||
return $.when(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I missed this earlier, but if this.fetchCatchmentsPromise
exists, we should probably return that instead of $.when()
:
if (!catchments.isEmpty() || this.fetchCatchmentsPromise) {
return this.fetchCatchmentsPromise || $.when();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's my bad. I'll fix before merging.
When entering the HUC-12-level view, fetch the catchment details if they have not already been fetched. This provides us the catchment area to eventually calculate the rates, as well as the geometries.
Add template and view to display catchment loads for an active HUC-12 in subbasin view.
The huc-12 totals table re-renders after the huc12 details change. After every re-render the bootstrap table must be reinitialized.
Fix a bug where if you switched to Analyze or Model views while you were viewing a HUC-12 in subbasin mode, the shapes would not get re-added to the map after coming back to the subbasin view.
Use the helper function to clear the subbasin shapes when exiting subbasin mode instead of clearing the collection. The helper function removes the map listeners, which would otherwise try to fire on removed layers.
The huc12 view should only be rendered if there's an active huc12 to populate it with.
92b270b
to
a1d3403
Compare
@azavea-bot rebuild |
Overview
Similar to #2781 where we got HUC-12 details — get catchment details and geometries and display them in the new catchment table. Also clean up some map-timing bugs.
Connects #2730
Connects #2791
Demo
Testing Instructions
bundle