maputnik/src/components/map/FeatureLayerPopup.jsx

63 lines
1.6 KiB
React
Raw Normal View History

2016-12-24 15:24:22 +01:00
import React from 'react'
2016-12-24 17:24:24 +01:00
import InputBlock from '../inputs/InputBlock'
import StringInput from '../inputs/StringInput'
2016-12-25 17:46:18 +01:00
import LayerIcon from '../icons/LayerIcon'
import input from '../../config/input'
2016-12-24 17:24:24 +01:00
import colors from '../../config/colors'
import { margins, fontSizes } from '../../config/scales'
const Panel = (props) => {
return <div style={{
backgroundColor: colors.gray,
padding: margins[0],
fontSize: fontSizes[5],
lineHeight: 1.2,
}}>{props.children}</div>
}
2016-12-25 17:46:18 +01:00
function groupFeaturesBySourceLayer(features) {
const sources = {}
features.forEach(feature => {
sources[feature.layer['source-layer']] = sources[feature.layer['source-layer']] || []
sources[feature.layer['source-layer']].push(feature)
})
return sources
}
2016-12-24 17:24:24 +01:00
2017-01-09 23:04:08 +01:00
class FeatureLayerPopup extends React.Component {
2016-12-24 15:24:22 +01:00
render() {
2016-12-25 17:46:18 +01:00
const sources = groupFeaturesBySourceLayer(this.props.features)
const items = Object.keys(sources).map(vectorLayerId => {
2017-01-09 23:04:08 +01:00
const layers = sources[vectorLayerId].map((feature, idx) => {
return <label
key={idx}
style={{
2016-12-25 17:46:18 +01:00
...input.label,
display: 'block',
width: 'auto',
}}>
<LayerIcon type={feature.layer.type} style={{
width: fontSizes[4],
height: fontSizes[4],
paddingRight: margins[0],
}}/>
{feature.layer.id}
</label>
})
2017-01-10 09:38:27 +01:00
return <div key={vectorLayerId}>
2016-12-25 17:46:18 +01:00
<Panel>{vectorLayerId}</Panel>
{layers}
</div>
})
2016-12-24 17:24:24 +01:00
return <div>
2016-12-25 17:46:18 +01:00
{items}
2016-12-24 17:24:24 +01:00
</div>
2016-12-24 15:24:22 +01:00
}
}
2017-01-09 23:04:08 +01:00
export default FeatureLayerPopup