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

79 center zoom hash #187

Merged
merged 18 commits into from
Sep 28, 2017
Merged

79 center zoom hash #187

merged 18 commits into from
Sep 28, 2017

Conversation

chriswhong
Copy link
Contributor

This PR adds the mapboxGL map hash, allowing us to persist map views on page reload.

It also changes the fitbounds behavior

  • Transitioning from sub-routes to index no longer zooms out
  • Highlighted features are cleared when transitioning back to index
  • Fitbounds adds an offset option so the fit is correct even though the map is obscured behind the details pane.

TODO: Add logic to fitBoundsOptions to make sure it works on mobile

@ghost ghost assigned chriswhong Sep 27, 2017
@ghost ghost added the in progress label Sep 27, 2017
@ghost ghost assigned allthesignals Sep 27, 2017
@andycochran
Copy link
Contributor

andycochran commented Sep 27, 2017

The © info and map scale are hidden behind the content on ≥ large screens

@andycochran
Copy link
Contributor

Seems like the map pan/zooms on route change on very large screens but not on smaller screens.

@andycochran
Copy link
Contributor

This needs to account for the large and xxlarge CSS media queries:

$breakpoints: (
  small: 0,
  medium: 640px,
  large: 1024px,
  xlarge: 1200px,
  xxlarge: 1440px,
);

@andycochran
Copy link
Contributor

To keep the media queries in sync with the JS consider using this method to have the CSS tell the JavaScript which media query is being used: http://zerosixthree.se/detecting-media-queries-with-javascript/

@chriswhong
Copy link
Contributor Author

Will tackle tomorrow, not ready to merge yet

# Conflicts:
#	app/styles/layouts/_l-default.scss
@@ -43,8 +43,16 @@ export default Ember.Component.extend({
const height = el.height();
const width = el.width();

const fullWidth = $('.navigation-area').width();
Copy link
Collaborator

Choose a reason for hiding this comment

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

@chriswhong is this the only div where we can get correct information about the width of the screen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's just the closest one. Just need something full width so we can calculate the percentage that the details pane will take up.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it - so I think window width will do.

return {
padding: selected && (type !== 'zoning-district') ? padding : 0,
offset: [offset, 0],
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

@chriswhong what should this computed be doing in terms of the view? Having trouble figuring out how to test / verify. Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

^^ I have some ideas on how to approach this differently

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This offsets the fitbounds, I am not sure how you would test the output, you would need to be able to read the centerpoint of the map vs the center of the highlighted polygon somehow.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I just mean manual testing. Why does zoning-district get padding but not others? Thanks!

@computed('mainMap.shouldFitBounds')
shouldFitBounds(shouldFitBounds) {
return shouldFitBounds;
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll refactor this to a computed alias (shrink 4 lines of code into 1)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Basically, shouldFitBounds: alias('mainMap.shouldFitBounds')

didTransition() {
this.get('mainMap').set('selected', null);
this.get('mainMap').set('shouldFitBounds', false);
},
Copy link
Collaborator

@allthesignals allthesignals Sep 27, 2017

Choose a reason for hiding this comment

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

I'll take care of this but if you're setting on a property you don't need to get it, you can just write:
this.set('mainMap.selected',null);

Alternatively, if there are multiple properties, you can just say:

      this.get('mainMap')
        .setProperties({
          selected: null,
          shouldFitBounds: false,
        });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good to know!

@@ -14,5 +14,6 @@ export default Ember.Route.extend({
afterModel(model) {
const mainMap = this.get('mainMap');
mainMap.set('selected', model);
mainMap.set('shouldFitBounds', true);
Copy link
Collaborator

@allthesignals allthesignals Sep 27, 2017

Choose a reason for hiding this comment

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

Same as above, I'll take care of it tonight:

      this.get('mainMap')
        .setProperties({
          selected: null,
          shouldFitBounds: false,
        });

const application = this.controllerFor('application');
application.resetQueryParams();
didTransition() {
this.get('mainMap').set('shouldFitBounds', true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this.set('mainMap.shouldFitBounds', true);


actions: {
didTransition() {
this.get('mainMap').set('shouldFitBounds', true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

@ghost ghost assigned andycochran Sep 28, 2017
@andycochran
Copy link
Contributor

I pulled down the latest on this and got a weird merge conflict. I fixed the _l-default.scss file, but GitHub says my commit touched other files. Please confirm I didn't break anything. 😬

Resize was being called before a route transition finished (and actually affected the DOM) and after a fitBounds animation finished, meaning it never had the correct DOM context to resize properly. Two things had to happen:

 - ember-mapbox-gl’s call needed to be wrapped in an afterRender callback in the Run cycle so that things were synchronous
 - resize() must be called before fitBounds, but after a render has completed

Fix is now in place globally, but resize is commented out for now pending some other decision.
Also don’t use private variables
In favor of 2 commits ago
@allthesignals
Copy link
Collaborator

allthesignals commented Sep 28, 2017

@chriswhong @andycochran
I finally successfully solved the resize issue which is described in the commit
(4284b18). However, it seems like the strategy of this PR was to solve it by working around it, and making the map absolutely positioned so that .content-area would float over it. That means that even though the original behavior works (resize map when a new div is inserted), the map center still jumps to adjust for the container's new width, moving layers and content along with it.

There is a long discussion thread on this related issue here: mapbox/mapbox-gl-js#1740. Basically, MapboxGL does not yet provide a way to globally offset the map's internal concept of a "center", although it does provide an "around" option (https://www.mapbox.com/mapbox-gl-js/api/#cameraoptions) for a select few panning/zoom methods.

I think this will have to be the working solution for now but we'll need to find a more organized way to deal with the layout widths to calculate offsets since that will cause issues for mobile and other views.

@allthesignals allthesignals merged commit 22222f6 into develop Sep 28, 2017
@ghost ghost removed the in progress label Sep 28, 2017
@chriswhong chriswhong mentioned this pull request Sep 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants