Skip to content

Commit

Permalink
fix: dashboard maps (#441)
Browse files Browse the repository at this point in the history
* fix: disable scroll wheel zoom for plugin maps

* fix: dashboard maps
  • Loading branch information
turban authored Feb 7, 2020
1 parent efe8faa commit 83b1dc6
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 136 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"@dhis2/d2-ui-interpretations": "6.2.1",
"@dhis2/d2-ui-org-unit-dialog": "5.2.10",
"@dhis2/d2-ui-org-unit-tree": "5.2.10",
"@dhis2/gis-api": "^34.0.10",
"@dhis2/maps-gl": "1.0.0",
"@dhis2/gis-api": "^34.0.11",
"@dhis2/maps-gl": "1.0.2",
"@dhis2/ui-core": "^4.1.1",
"@dhis2/ui-widgets": "^2.0.5",
"@material-ui/core": "^3.9.3",
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Map extends Component {
const { isPlugin } = props;

const map = mapApi({
scrollWheelZoom: !isPlugin,
scrollZoom: !isPlugin,
});

if (isPlugin) {
Expand Down
44 changes: 44 additions & 0 deletions src/components/plugin/Legend.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.dhis2-map-legend {
position: absolute;
right: 10px;
top: 74px;
z-index: 999;
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.65);
background-color: #fff;
font-size: 14px;
max-height: calc(100% - 95px);
overflow-y: auto;
}

.dhis2-map-legend-button {
width: 26px;
height: 26px;
background-position: 50% 50%;
background-repeat: no-repeat;
background-size: 16px 16px;
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAy5pVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME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8+A2WYgQRE+7+YaAFYGIYYMBCqgZGRsb/wyoEhl4U2FhbDawDjhw9xkhVB0Cz2sCFgAArI14fkepAmofAgCfCw0eODrNsmKX2D2ccPP/JBK8LRgui0bpgtC6gWV0AzWoDFwKS7P/w+ohUB9I8BEbrAqqHgK2PJc6S7ePnr6N1wWhdMFoX0L4ugGa1AQsBgAADAHQ1NZdoV4oTAAAAAElFTkSuQmCC');
}

.dhis2-map-legend-content {
overflow-y: auto;
min-width: 150px;
max-width: 200px;
padding: 10px;
color: #333;
}

.dhis2-map-legend-title {
margin: 0;
font-size: 14px;
line-height: 18px;
padding-bottom: 10px;
}

.dhis2-map-legend-period {
display: block;
font-weight: normal;
}

.dhis2-map-legend-alert {
padding-bottom: 8px;
}
159 changes: 39 additions & 120 deletions src/components/plugin/Legend.js
Original file line number Diff line number Diff line change
@@ -1,122 +1,41 @@
import React, { PureComponent, Fragment } from 'react';
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import i18n from '@dhis2/d2-i18n';
import LayerLegend from '../layers/legend/Legend';

const styles = theme => ({
root: {
position: 'absolute',
right: 10,
top: 74,
zIndex: 999,
boxShadow: '0 1px 5px rgba(0, 0, 0, 0.65)',
backgroundColor: '#fff',
fontSize: 14,
},
toggle: {
width: 26,
height: 26,
backgroundPosition: '50% 50%',
backgroundRepeat: 'no-repeat',
backgroundSize: '16px 16px',
backgroundImage:
'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAy5pVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlI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gtC6gWV0AzWoDFwKS7P/w+ohUB9I8BEbrAqqHgK2PJc6S7ePnr6N1wWhdMFoX0L4ugGa1AQsBgAADAHQ1NZdoV4oTAAAAAElFTkSuQmCC")',
},
content: {
overflowY: 'auto',
minWidth: 150,
maxWidth: 200,
minHeight: 80,
maxHeight: 260,
padding: '6px 10px 6px 6px',
color: '#333',
},
title: {
margin: 0,
fontSize: 14,
lineHeight: '18px',
paddingBottom: theme.spacing.unit,
},
period: {
display: 'block',
fontWeight: 'normal',
},
alert: {
paddingBottom: 8,
},
});

class Legend extends PureComponent {
static propTypes = {
layers: PropTypes.array.isRequired,
classes: PropTypes.object.isRequired,
};

state = {
isOpen: false,
};

render() {
const { layers, classes } = this.props;
const { isOpen } = this.state;
const legendLayers = layers
.filter(layer => layer.legend || layer.alerts)
.reverse(); // Show top layer first

return (
<div className={`dhis2-map-legend ${classes.root}`}>
{isOpen ? (
<div
className={classes.content}
onMouseLeave={this.onMouseLeave}
>
{legendLayers.map(this.getLayerLegend)}
</div>
) : (
<div
className={classes.toggle}
title={i18n.t('Legend')}
onMouseEnter={this.onMouseEnter}
/>
)}
</div>
);
}

getLayerLegend = mapView => {
const { id, layer, legend, serverCluster, data, alerts = [] } = mapView;
const { classes } = this.props;
const hasData =
(Array.isArray(data) && data.length > 0) ||
serverCluster ||
layer === 'earthEngine';

return (
<div key={id}>
{legend && (
<Fragment>
<h2 className={classes.title}>
{legend.title}{' '}
<span className={classes.period}>
{legend.period}
</span>
</h2>
{hasData && <LayerLegend {...legend} />}
</Fragment>
)}
{alerts.map(alert => (
<div key={alert.id} className={classes.alert}>
{alert.description}
</div>
))}
</div>
);
};

onMouseEnter = () => this.setState({ isOpen: true });

onMouseLeave = () => this.setState({ isOpen: false });
}

export default withStyles(styles)(Legend);
import LegendLayer from './LegendLayer';
import './Legend.css';

// Renders a legend for all map layers
const Legend = ({ layers }) => {
const [isOpen, toggleOpen] = useState(false);

const legendLayers = layers
.filter(layer => layer.legend || layer.alerts)
.reverse(); // Show top layer first

return (
<div className="dhis2-map-legend">
{isOpen ? (
<div
className="dhis2-map-legend-content"
onMouseLeave={() => toggleOpen(false)}
>
{legendLayers.map(layer => (
<LegendLayer key={layer.id} {...layer} />
))}
</div>
) : (
<div
className="dhis2-map-legend-button"
title={i18n.t('Legend')}
onMouseEnter={() => toggleOpen(true)}
/>
)}
</div>
);
};

Legend.propTypes = {
layers: PropTypes.array.isRequired,
};

export default Legend;
45 changes: 45 additions & 0 deletions src/components/plugin/LegendLayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import LayerLegend from '../layers/legend/Legend';

// Renders a legend with alerts for one map layer
const LegendLayer = props => {
const { id, layer, legend, serverCluster, data, alerts = [] } = props;

const hasData =
(Array.isArray(data) && data.length > 0) ||
serverCluster ||
layer === 'earthEngine';

return (
<div key={id}>
{legend && (
<Fragment>
<h2 className="dhis2-map-legend-title">
{legend.title}
<span className="dhis2-map-legend-period">
{legend.period}
</span>
</h2>
{hasData && <LayerLegend {...legend} />}
</Fragment>
)}
{alerts.map(alert => (
<div key={alert.id} className="dhis2-map-legend-alert">
{alert.description}
</div>
))}
</div>
);
};

LegendLayer.propTypes = {
id: PropTypes.string.isRequired,
layer: PropTypes.string,
legend: PropTypes.object,
serverCluster: PropTypes.bool,
data: PropTypes.array,
alerts: PropTypes.array,
};

export default LegendLayer;
10 changes: 6 additions & 4 deletions src/components/plugin/MapName.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ const styles = theme => ({
justifyContent: 'center',
pointerEvents: 'none',
position: 'absolute',
top: 10,
left: 10,
right: 10,
top: 8,
left: 50,
right: 50,
zIndex: 998,
'& div': {
backgroundColor: 'rgba(255,255,255,0.9)',
boxShadow: theme.shadows[1],
borderRadius: theme.shape.borderRadius,
padding: '3px 5px',
padding: '5px 8px 3px',
fontSize: 12,
textAlign: 'center',
lineHeight: '18px',
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/plugin/Plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { fetchLayer } from '../../loaders/layers';

const styles = {
root: {
height: '100%',
position: 'relative',
height: '100%',
fontFamily: 'Roboto, Helvetica, Arial, sans-serif',
},
};
Expand Down
1 change: 1 addition & 0 deletions src/constants/mapControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ export const pluginControls = [
{
type: 'fullscreen',
position: 'top-right',
isPlugin: true,
},
];
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,10 @@
recompose "^0.26.0"
rxjs "^5.5.7"

"@dhis2/gis-api@^34.0.10":
version "34.0.10"
resolved "https://registry.yarnpkg.com/@dhis2/gis-api/-/gis-api-34.0.10.tgz#9982bda935ecb7280d4323b9ead3b00f33aac65c"
integrity sha512-fODt9My+j7ef0PSHj+IsqpZp3G6j773fG3heMMLKeyIsp1y+I9H7iE0Ds0DHe65eul1dAcrOO6SsbxqzpiGCYw==
"@dhis2/gis-api@^34.0.11":
version "34.0.11"
resolved "https://registry.yarnpkg.com/@dhis2/gis-api/-/gis-api-34.0.11.tgz#5583039ff71f266f0ac1cc2a2b61d0be82225b19"
integrity sha512-lVtiiiFP+Gcq9AE5IP6W8Kb8AO8veTuOi/xdleuzi8XBmPICV7G6a9xBm98fypKisrl+WSmqrKjLEGzpFVItKg==
dependencies:
"@google/earthengine" "^0.1.172"
"@mapbox/geojson-area" "^0.2.2"
Expand All @@ -447,10 +447,10 @@
leaflet.markercluster "^1.4.1"
whatwg-fetch "^3.0.0"

"@dhis2/maps-gl@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@dhis2/maps-gl/-/maps-gl-1.0.0.tgz#e09b9cede7eaed74a9897f38d89a814083aa9609"
integrity sha512-HMkosfTuPMHz603ep+OyTvjyYGi/SHq87Lvj9rNrRbEvtkPp+0wkbBbYq/UNMNie5ntLBLSC3bnx62MsuByToA==
"@dhis2/maps-gl@1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@dhis2/maps-gl/-/maps-gl-1.0.2.tgz#af49519d3e5ff96bbe478f7de545c108b85d4de6"
integrity sha512-9mQuYYvL5VD6tKVoUyE1lRmAO8om5aXHvau/nIA/aQt+XA6zoVJJ1OLyVRKUlQiLRxxXyvKym0x+LcW1F+QPUw==
dependencies:
"@mapbox/sphericalmercator" "^1.1.0"
"@turf/area" "^6.0.1"
Expand Down

0 comments on commit 83b1dc6

Please sign in to comment.