Improve inspect popups

This commit is contained in:
Lukas Martinelli
2016-12-25 17:46:18 +01:00
parent 720c8f108b
commit e1bc2a321a
8 changed files with 133 additions and 55 deletions

View File

@@ -1,19 +1,12 @@
import React from 'react'
import InputBlock from '../inputs/InputBlock'
import StringInput from '../inputs/StringInput'
import LayerIcon from '../icons/LayerIcon'
import input from '../../config/input'
import colors from '../../config/colors'
import { margins, fontSizes } from '../../config/scales'
function renderProperties(feature) {
return Object.keys(feature.properties).map(propertyName => {
const property = feature.properties[propertyName]
return <InputBlock label={propertyName} style={{marginTop: 0, marginBottom: 0}}>
<StringInput value={property} style={{backgroundColor: 'transparent'}}/>
</InputBlock>
})
}
const Panel = (props) => {
return <div style={{
backgroundColor: colors.gray,
@@ -25,23 +18,46 @@ const Panel = (props) => {
function renderFeature(feature) {
return <div>
<Panel>Source</Panel>
<InputBlock label={feature.layer['source-layer']} style={{marginTop: 0, marginBottom: 0}}>
</InputBlock>
<Panel>Layers</Panel>
<InputBlock label={feature.layer.id} style={{marginTop: 0, marginBottom: 0}}>
</InputBlock>
<Panel>Properties</Panel>
{renderProperties(feature)}
<Panel>{feature.layer['source-layer']}</Panel>
</div>
}
class FeatureLayerTable extends React.Component {
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
}
class FeatureLayerTable extends React.Component {
render() {
const features = this.props.features
const sources = groupFeaturesBySourceLayer(this.props.features)
const items = Object.keys(sources).map(vectorLayerId => {
const layers = sources[vectorLayerId].map(feature => {
return <label style={{
...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>
})
return <div>
<Panel>{vectorLayerId}</Panel>
{layers}
</div>
})
return <div>
{features.map(renderFeature)}
{items}
</div>
}
}

View File

@@ -0,0 +1,44 @@
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'
function renderProperties(feature) {
return Object.keys(feature.properties).map(propertyName => {
const property = feature.properties[propertyName]
return <InputBlock label={propertyName} style={{marginTop: 0, marginBottom: 0}}>
<StringInput value={property} style={{backgroundColor: 'transparent'}}/>
</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) {
return <div>
<Panel>{feature.layer['source-layer']}</Panel>
{renderProperties(feature)}
</div>
}
class FeatureLayerTable extends React.Component {
render() {
const features = this.props.features
return <div>
{features.map(renderFeature)}
</div>
}
}
export default FeatureLayerTable

View File

@@ -4,9 +4,10 @@ import MapboxGl from 'mapbox-gl'
import validateColor from 'mapbox-gl-style-spec/lib/validate/validate_color'
import colors from '../../config/colors'
import style from '../../libs/style'
import FeatureLayerTable from './FeatureLayerTable'
import FeaturePropertyPopup from './FeaturePropertyPopup'
import { generateColoredLayers } from '../../libs/stylegen'
import 'mapbox-gl/dist/mapbox-gl.css'
import '../../mapboxgl.css'
function convertInspectStyle(mapStyle, sources) {
const newStyle = {
@@ -27,7 +28,7 @@ function convertInspectStyle(mapStyle, sources) {
function renderPopup(features) {
var mountNode = document.createElement('div');
ReactDOM.render(<FeatureLayerTable features={features} />, mountNode)
ReactDOM.render(<FeaturePropertyPopup features={features} />, mountNode)
return mountNode.innerHTML;
}

View File

@@ -5,6 +5,7 @@ import FeatureLayerTable from './FeatureLayerTable'
import validateColor from 'mapbox-gl-style-spec/lib/validate/validate_color'
import style from '../../libs/style.js'
import 'mapbox-gl/dist/mapbox-gl.css'
import '../../mapboxgl.css'
function renderPopup(features) {
var mountNode = document.createElement('div');
@@ -74,7 +75,7 @@ export default class MapboxGlMap extends React.Component {
layers: this.layers
});
console.log('Click on features', features)
if(features.length < 1) return
const popup = new MapboxGl.Popup()
.setLngLat(e.lngLat)
.setHTML(renderPopup(features))