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

Add asychronous loading to map views #948

Merged
merged 2 commits into from
Dec 2, 2016
Merged

Conversation

oliverroick
Copy link
Member

Proposed changes in this pull request

  • Resolves Asynchronous loading of geographic features #931: Improves responsiveness of map views by asynchronoulsy loading geographic features.
  • Introduces spatial.views.asyc.SpatialUnitList, which provides paginated access to spatial units on a project. The page size is set to 1000. The view uses a custom Paginator based on GeoJsonPagination
  • Removes synchronous loading of project locations from all map views. Views affected include:
    • organization.views.default.ProjectDashboard
    • spatial.views.default.LocationList
    • spatial.views.default.LocationAdd
    • spatial.views.default.LocationDetail
    • spatial.views.default.LocationEdit
    • party.views.default.PartyRelationshipDetail
    • party.views.default.PartyRelationshipEdit
    • party.views.default.PartyRelationshipDelete
    • party.views.default.PartyRelationshipResourceAdd
    • party.views.default.PartyRelationshipResourceNew
  • Add asynchrousnoues loading of geographic feature from aforementioned spatial.views.asyc.SpatialUnitList. renderfeatures() inside core/static/js/map_utils.js has been adapted accordingly.
  • Adds a loading alert. The alert is added to templates/core/base.html and hidden by default. renderfeatures() shows and hides the alert.

When should this PR be merged

Anytime for sprint 11.

Risks

Low.

Follow up actions

While this PR should improve the responsiveness of map views, it will likely be only a stop-gap solution until we have implemented a more sustainable solution. Research into a sustainable solution should start now, and we should coordinate this with work towards improving map interactions.

@seav
Copy link
Contributor

seav commented Nov 29, 2016

I'd like to confirm that this PR still loads everything regardless of the state of the map's location and zoom level, right? The difference is that before there is a blank space while the data is being processed, but now there is an initial map with a "Loading..." alert.

@oliverroick
Copy link
Member Author

Yes, that is correct. The main difference is that the page loads first and then the features are loaded onto the map in batches of 1,000.

@oliverroick oliverroick force-pushed the feature/#931-async-loading branch 3 times, most recently from 44dbb5b to 44655b8 Compare December 1, 2016 19:25
@oliverroick
Copy link
Member Author

@seav Any news on this? Does it need more work or is it good to go?

@seav
Copy link
Contributor

seav commented Dec 2, 2016

Still reviewing the actual code. It is a pretty big update. But I will finish this today so that it can go into QA/code freeze.

Copy link
Contributor

@seav seav left a comment

Choose a reason for hiding this comment

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

I have a couple of clarifications and 1 clean-up request. Otherwise, this looks good!


var trans = {open: "{% trans 'Open location' %}"}
renderFeatures(detail.map, null, data, trans);
renderFeatures(detail.map,
Copy link
Contributor

Choose a reason for hiding this comment

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

Before, trans was created but it was now removed. But in other templates, trans was still retained. Which should it be?

Copy link
Member Author

Choose a reason for hiding this comment

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

When you edit a feature, you don't want to open other locations from the map. Popups are not provided on the edit, hence the translation is not needed. This condition checks whether to display to popup or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay.

else:
self._queryset = self.proj.spatial_units.all().only(
'id', 'type', 'geometry', 'project')
self._queryset = self.proj.spatial_units.all().only(
Copy link
Contributor

Choose a reason for hiding this comment

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

Since self.queryset_excludes_object was removed here, then the reference to it at SpatialUnitObjectMixin should also be removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Reference removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay.

geoJson.addData(response);

if (response.next) {
loadFeatures(response.next, map, options.trans);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to have some interval between loading pages?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why? The next request never starts before the previous one is finished.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking that maybe there should be a pause between processing so the JS engine is not executing all the time. But I saw that there is a pause anyway because there is a network call. So this should be okay.

- Paginated spatial unit list views
- Remove spatial units from template context
- Add async loading to templates
- Add loading indicator
@oliverroick oliverroick force-pushed the feature/#931-async-loading branch from 44655b8 to bcf2881 Compare December 2, 2016 11:23
@seav seav merged commit fdf4a84 into master Dec 2, 2016
@seav seav deleted the feature/#931-async-loading branch December 2, 2016 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants