maputnik/src/components/map/FeaturePropertyPopup.jsx

54 lines
1.4 KiB
React
Raw Normal View History

2016-12-25 17:46:18 +01:00
import React from 'react'
import InputBlock from '../inputs/InputBlock'
import StringInput from '../inputs/StringInput'
import colors from '../../config/colors'
import { margins, fontSizes } from '../../config/scales'
2017-01-10 09:38:27 +01:00
function displayValue(value) {
if (typeof value === 'undefined' || value === null) return value;
if (value instanceof Date) return value.toLocaleString();
if (typeof value === 'object' ||
typeof value === 'number' ||
typeof value === 'string') return value.toString();
return value;
}
2016-12-25 17:46:18 +01:00
function renderProperties(feature) {
return Object.keys(feature.properties).map(propertyName => {
const property = feature.properties[propertyName]
2017-01-10 09:38:27 +01:00
return <InputBlock key={propertyName} label={propertyName} style={{marginTop: 0, marginBottom: 0}}>
<StringInput value={displayValue(property)} style={{backgroundColor: 'transparent'}}/>
2016-12-25 17:46:18 +01:00
</InputBlock>
})
}
const Panel = (props) => {
return <div style={{
backgroundColor: colors.gray,
padding: margins[0],
fontSize: fontSizes[5],
lineHeight: 1.2,
}}>{props.children}</div>
}
function renderFeature(feature) {
2017-01-10 09:38:27 +01:00
return <div key={feature.id}>
2016-12-25 17:46:18 +01:00
<Panel>{feature.layer['source-layer']}</Panel>
{renderProperties(feature)}
</div>
}
class FeaturePropertyPopup extends React.Component {
2016-12-25 17:46:18 +01:00
render() {
const features = this.props.features
return <div>
{features.map(renderFeature)}
</div>
}
}
export default FeaturePropertyPopup