Skip to content

Commit

Permalink
LayeredMap: Calculate default bounds if undefined or changed uirevisi…
Browse files Browse the repository at this point in the history
…on (equinor#76)
  • Loading branch information
HansKallekleiv authored Nov 11, 2019
1 parent 6178d1c commit 8b66384
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/lib/components/LayeredMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class LayeredMap extends Component {
calculateBounds() {
const x_arr = [];
const y_arr = [];

if (this.props.layers.length === 0) {
return [[0, 0], [1, 1]];
}
this.props.layers.map(layer => {
layer.data.map(item => {
if (["polyline", "polygon"].includes(item.type)) {
Expand Down Expand Up @@ -63,7 +65,6 @@ class LayeredMap extends Component {
resetView() {
const [[xmin, ymin], [xmax, ymax]] = this.calculateBounds();
const center = [0.5 * (xmin + xmax), 0.5 * (ymin + ymax)];

const width = this.mapRef.current.container.offsetWidth;
const height = this.mapRef.current.container.offsetHeight;

Expand Down Expand Up @@ -116,7 +117,10 @@ class LayeredMap extends Component {
}

componentDidUpdate(prevProps) {
if (this.props.uirevision !== prevProps.uirevision) {
if (
this.props.uirevision === "" ||
this.props.uirevision !== prevProps.uirevision
) {
this.resetView();
}
}
Expand Down Expand Up @@ -346,8 +350,9 @@ LayeredMap.propTypes = {
hillShading: PropTypes.bool,

/**
* Following the same approach as Plotly Dash:
* If the string uireivision changes, reset the viewport.
* A string to control if map bounds should be recalculated on prop change.
Recalculation will occur if the string is set to empty or is different than the
last prop change.
*/
uirevision: PropTypes.string,
};
Expand Down

0 comments on commit 8b66384

Please sign in to comment.