forked from geosolutions-it/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Legend plugin to dataset page (#611)
- Loading branch information
1 parent
a7c70b3
commit 3824ba5
Showing
6 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2021, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React, { useState, Fragment } from 'react'; | ||
import { createPlugin } from '@mapstore/framework/utils/PluginsUtils'; | ||
import { connect } from 'react-redux'; | ||
import { createSelector } from 'reselect'; | ||
import LegendImage from '@mapstore/framework/components/TOC/fragments/legend/Legend'; | ||
import { layersSelector } from '@mapstore/framework/selectors/layers'; | ||
|
||
function Legend({ | ||
layers, | ||
hideLayerTitle | ||
}) { | ||
|
||
const [expandLegend, setExpandLegend] = useState(false); | ||
|
||
const expand = () => { | ||
setExpandLegend(ex => !ex); | ||
}; | ||
|
||
return layers.length > 0 && <div className="shadow gn-legend-wrapper" style={{width: expandLegend ? 'auto' : '80px'}}> | ||
<div onClick={expand}> | ||
<span role="button" className={`identify-icon glyphicon glyphicon-chevron-${expandLegend ? 'down' : 'right'}`} title="Expand layer legend" /> | ||
<span className="gn-legend-list-item">Legend</span> | ||
</div> | ||
<ul className="gn-legend-list" style={{height: expandLegend ? 'fit-content' : 0, overflowY: expandLegend ? 'auto' : 'hidden'}}> | ||
{layers.map((layer, ind) => <Fragment key={ind}> | ||
{!hideLayerTitle && | ||
<li className="gn-legend-list-item"><p>{layer.title}</p></li> | ||
} | ||
<li> | ||
<LegendImage layer={layer} /> | ||
</li> | ||
</Fragment> | ||
)} | ||
</ul> | ||
</div>; | ||
} | ||
|
||
const ConnectedLegend = connect( | ||
createSelector([layersSelector], (layers) => ({layers: layers.filter(layer => layer.group !== 'background' && layer.type === 'wms')})), | ||
{} | ||
)(Legend); | ||
|
||
export default createPlugin('Legend', { | ||
component: ConnectedLegend, | ||
containers: {}, | ||
epics: {}, | ||
reducers: {} | ||
}); |
42 changes: 42 additions & 0 deletions
42
geonode_mapstore_client/client/js/plugins/__tests__/legend-test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2021, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import expect from 'expect'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { getPluginForTest } from '@mapstore/framework/plugins/__tests__/pluginsTestUtils'; | ||
import Legend from '../Legend'; | ||
|
||
|
||
describe('Share Plugin', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
window.__DEVTOOLS__ = true; | ||
setTimeout(done); | ||
}); | ||
|
||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById('container')); | ||
document.body.innerHTML = ''; | ||
window.__DEVTOOLS__ = undefined; | ||
setTimeout(done); | ||
}); | ||
|
||
const testState = { | ||
layers: { | ||
flat: [{name: 'test', id: 1, title: 'test layer', type: 'wms', url: 'https://gs-stable.geo-solutions.it/geoserver/wms' }] | ||
} | ||
}; | ||
|
||
it('render Legend plugin', () => { | ||
const { Plugin } = getPluginForTest(Legend, testState); | ||
ReactDOM.render(<Plugin />, document.getElementById('container')); | ||
const container = document.querySelector('.gn-legend-wrapper'); | ||
expect(container).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
geonode_mapstore_client/client/themes/geonode/less/_legend.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// ************** | ||
// Theme | ||
// ************** | ||
|
||
#gn-components-theme(@theme-vars) { | ||
.gn-legend-wrapper { | ||
.color-var(@theme-vars[main-color]); | ||
.background-color-var(@theme-vars[main-bg]); | ||
} | ||
} | ||
|
||
// ************** | ||
// Layout | ||
// ************** | ||
|
||
.gn-legend-wrapper { | ||
position: absolute; | ||
left: 10px; | ||
top: 10px; | ||
z-index: 9999; | ||
padding: .5rem; | ||
min-width: 120px; | ||
max-height: 180px; | ||
border-radius: 2px; | ||
|
||
.gn-legend-list { | ||
list-style: none; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
.gn-legend-list-item { | ||
margin: 0; | ||
margin-bottom: .5rem; | ||
font-weight: bold; | ||
p { | ||
margin: 0; | ||
font-weight: normal; | ||
} | ||
} | ||
|
||
span { | ||
margin: 0; | ||
} | ||
|
||
span.gn-legend-list-item { | ||
margin-left: .5rem; | ||
} | ||
|
||
.identify-icon { | ||
font-size: small; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters