2016-12-25 17:46:18 +01:00
|
|
|
import React from 'react'
|
|
|
|
import InputBlock from '../inputs/InputBlock'
|
|
|
|
import StringInput from '../inputs/StringInput'
|
|
|
|
|
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-11 11:35:33 +01:00
|
|
|
return <InputBlock key={propertyName} label={propertyName}>
|
2017-01-10 09:38:27 +01:00
|
|
|
<StringInput value={displayValue(property)} style={{backgroundColor: 'transparent'}}/>
|
2016-12-25 17:46:18 +01:00
|
|
|
</InputBlock>
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderFeature(feature) {
|
2017-01-10 09:38:27 +01:00
|
|
|
return <div key={feature.id}>
|
2017-01-11 11:35:33 +01:00
|
|
|
<div className="maputnik-popup-layer-id">{feature.layer['source-layer']}</div>
|
2017-01-18 10:03:15 +01:00
|
|
|
<InputBlock key={"property-type"} label={"$type"}>
|
|
|
|
<StringInput value={feature.geometry.type} style={{backgroundColor: 'transparent'}} />
|
|
|
|
</InputBlock>
|
2016-12-25 17:46:18 +01:00
|
|
|
{renderProperties(feature)}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
|
2016-12-29 17:30:01 +01:00
|
|
|
class FeaturePropertyPopup extends React.Component {
|
2016-12-25 17:46:18 +01:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const features = this.props.features
|
2017-01-11 11:35:33 +01:00
|
|
|
return <div className="maputnik-feature-property-popup">
|
2016-12-25 17:46:18 +01:00
|
|
|
{features.map(renderFeature)}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-29 17:30:01 +01:00
|
|
|
export default FeaturePropertyPopup
|