-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Region map should respect saved center and zoom #12883
Region map should respect saved center and zoom #12883
Conversation
|
||
const saveCurrentLocation = () => { | ||
//to ensure we dirty the state of the viz. (not sure why this is required. Tilemap visualization does not require it) | ||
$scope.vis.params.mapZoom = kibanaMap.getZoomLevel(); |
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.
this should be stored to uiState as it is modified on dashboard (without editor)
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 i see its already stored in uiState ... why do you need this then ?
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.
you're right. I don't know, maybe I got in a weird state....
const uiState = $scope.vis.getUiState(); | ||
const zoomFromUiState = parseInt(uiState.get('mapZoom')); | ||
const centerFromUIState = uiState.get('mapCenter'); | ||
options.zoom = !isNaN(zoomFromUiState) ? zoomFromUiState : $scope.vis.type.visConfig.defaults.mapZoom; |
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.
if you store the center and zoom in ui state this won't be needed
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.
if its not in uiState you should just fallback to a fixed setting, no need to define it on visConfig
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.
const defaultOptions = {
zoom: 2,
mapCenter: [0, 0]
};
const options = _.defaultsDeep({}, {
zoom: parseInt(uiState.get('mapZoom'),
mapCenter: uiState.get('mapCenter'),
...minMaxZoom
}, defaultOptions);
in other visualizations we do something like this ...
selectedJoinField: selectedJoinField | ||
selectedJoinField: selectedJoinField, | ||
mapZoom: 2, | ||
mapCenter: [0, 0] |
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.
if you put it in uiState you'll need to init it when you create your chart there (if its not yet present)
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.
works nice ... some minor comments
you're right, saving in ui-state is sufficient. not sure why I missed it. besides, it struck me that we didn't need it in tilemap either. Removed the crufty statement |
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.
i think you missed my comment regarding storing things that are not configurable in editor in vis.params ...
i think you should not be storing map center and map zoom there, as this are uiState settings (right now they are both present in URL twice for this reason)
above in the comment i also suggested a diff approach (something all the other visualizations are doing)
thx, sorry I missed that improvement. Updated with latest commit. |
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.
LGTM
a98ea85
to
efc2d00
Compare
It looks like one you edit the location in dashboard, it will no longer reset to the new saved map center value from the visualization. I guess this is expected, similar to the issue/"feature" with saved searches and overriding default columns/sort order (#9523) I suppose this is an improvement then the prior implementation, but we may want to think more about how to sync the dashboard panel overridden state back with the original visualization. |
@stacey-gammon, yeah, this PR is not supposed to fix that.This one needs to fix primarily the original issue that Region Map does not save the current zoom/center when pressing the save-button. but agreed that maintaning dashboard-state will need some resolution at some point. Not sure what the right way forward on that one is though... |
Required manual edits to backport.
regarding the dashboard comment above: so in visualization you can define your center (or colors). when you put this viz on dashboard it will show as you set it. however you can now do additional changes (move it, change some colors) on the dashboard and save this. now you share this dashboard with somebody, he is gonna see the version you saved with dashboard. he can still move around and change the colors even. however the last colors and position are only stored for him specifically (until he hard refreshes ...) or does center location behave differently somehow ? |
Kind of - the "until he hard refreshes" part depends. If the dashboard was saved after the map center/color changes were made, then it's stuck with the custom colors and map positions unless the visualization is removed and re-added. That's the only way to sync back to the original visualization. But you are right, map center behaves just like the other overridable panel states, like color. It's just a confusing interaction IMO, that you can override state and never get it back. Especially when some of these actions can happen in view mode, then the user can go into edit mode, make an unrelated change, save, and now they are also stuck with the changes they made in view mode. But this is a whole different can of worms, something the sharing team will have to figure out. :) |
Release Note: The location of the map is now stored correctly when saving a Region Map.
closes #12189.