mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-01 05:28:16 +01:00
Added layer comments via 'metadata.maputnik:comment' (issue #28)
This commit is contained in:
parent
bbf26a3f38
commit
a53d7763ba
5 changed files with 98 additions and 19 deletions
|
@ -20,16 +20,33 @@ class StringInput extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <input
|
let tag;
|
||||||
className="maputnik-string"
|
let classes;
|
||||||
style={this.props.style}
|
|
||||||
value={this.state.value}
|
if(!!this.props.multi) {
|
||||||
placeholder={this.props.default}
|
tag = "textarea"
|
||||||
onChange={e => this.setState({ value: e.target.value })}
|
classes = [
|
||||||
onBlur={() => {
|
"maputnik-string",
|
||||||
|
"maputnik-string--multi"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tag = "input"
|
||||||
|
classes = [
|
||||||
|
"maputnik-string"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
return React.createElement(tag, {
|
||||||
|
className: classes.join(" "),
|
||||||
|
style: this.props.style,
|
||||||
|
value: this.state.value,
|
||||||
|
placeholder: this.props.default,
|
||||||
|
onChange: e => this.setState({ value: e.target.value }),
|
||||||
|
onBlur: () => {
|
||||||
if(this.state.value!==this.props.value) this.props.onChange(this.state.value)
|
if(this.state.value!==this.props.value) this.props.onChange(this.state.value)
|
||||||
}}
|
}
|
||||||
/>
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
src/components/layers/CommentBlock.jsx
Normal file
24
src/components/layers/CommentBlock.jsx
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import InputBlock from '../inputs/InputBlock'
|
||||||
|
import StringInput from '../inputs/StringInput'
|
||||||
|
|
||||||
|
class MetadataBlock extends React.Component {
|
||||||
|
static propTypes = {
|
||||||
|
value: React.PropTypes.string,
|
||||||
|
onChange: React.PropTypes.func.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return <InputBlock label={"Comments"}>
|
||||||
|
<StringInput
|
||||||
|
multi={true}
|
||||||
|
value={this.props.value}
|
||||||
|
onChange={this.props.onChange}
|
||||||
|
default="Comment..."
|
||||||
|
/>
|
||||||
|
</InputBlock>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MetadataBlock
|
|
@ -8,6 +8,7 @@ import LayerTypeBlock from './LayerTypeBlock'
|
||||||
import LayerIdBlock from './LayerIdBlock'
|
import LayerIdBlock from './LayerIdBlock'
|
||||||
import MinZoomBlock from './MinZoomBlock'
|
import MinZoomBlock from './MinZoomBlock'
|
||||||
import MaxZoomBlock from './MaxZoomBlock'
|
import MaxZoomBlock from './MaxZoomBlock'
|
||||||
|
import CommentBlock from './CommentBlock'
|
||||||
import LayerSourceBlock from './LayerSourceBlock'
|
import LayerSourceBlock from './LayerSourceBlock'
|
||||||
import LayerSourceLayerBlock from './LayerSourceLayerBlock'
|
import LayerSourceLayerBlock from './LayerSourceLayerBlock'
|
||||||
|
|
||||||
|
@ -110,6 +111,11 @@ export default class LayerEditor extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
renderGroupType(type, fields) {
|
renderGroupType(type, fields) {
|
||||||
|
let comment = ""
|
||||||
|
if(this.props.layer.metadata) {
|
||||||
|
comment = this.props.layer.metadata['maputnik:comment']
|
||||||
|
}
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case 'layer': return <div>
|
case 'layer': return <div>
|
||||||
<LayerIdBlock
|
<LayerIdBlock
|
||||||
|
@ -140,6 +146,10 @@ export default class LayerEditor extends React.Component {
|
||||||
value={this.props.layer.maxzoom}
|
value={this.props.layer.maxzoom}
|
||||||
onChange={v => this.changeProperty(null, 'maxzoom', v)}
|
onChange={v => this.changeProperty(null, 'maxzoom', v)}
|
||||||
/>
|
/>
|
||||||
|
<CommentBlock
|
||||||
|
value={comment}
|
||||||
|
onChange={v => this.changeProperty('metadata', 'maputnik:comment', v == "" ? undefined : v)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
case 'filter': return <div>
|
case 'filter': return <div>
|
||||||
<div className="maputnik-filter-editor-wrapper">
|
<div className="maputnik-filter-editor-wrapper">
|
||||||
|
|
|
@ -27,6 +27,28 @@ export function changeType(layer, newType) {
|
||||||
* to a {@newValue}.
|
* to a {@newValue}.
|
||||||
*/
|
*/
|
||||||
export function changeProperty(layer, group, property, newValue) {
|
export function changeProperty(layer, group, property, newValue) {
|
||||||
|
// Remove the property if undefined
|
||||||
|
if(newValue === undefined) {
|
||||||
|
if(group) {
|
||||||
|
const newLayer = {
|
||||||
|
...layer
|
||||||
|
};
|
||||||
|
delete newLayer[group][property];
|
||||||
|
|
||||||
|
// Remove the group if it is now empty
|
||||||
|
if(Object.keys(newLayer[group]).length < 1) {
|
||||||
|
delete newLayer[group];
|
||||||
|
}
|
||||||
|
return newLayer;
|
||||||
|
} else {
|
||||||
|
const newLayer = {
|
||||||
|
...layer
|
||||||
|
};
|
||||||
|
delete newLayer[property];
|
||||||
|
return newLayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
if(group) {
|
if(group) {
|
||||||
return {
|
return {
|
||||||
...layer,
|
...layer,
|
||||||
|
@ -41,4 +63,5 @@ export function changeProperty(layer, group, property, newValue) {
|
||||||
[property]: newValue
|
[property]: newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,11 @@
|
||||||
|
|
||||||
.maputnik-string {
|
.maputnik-string {
|
||||||
@extend .maputnik-input;
|
@extend .maputnik-input;
|
||||||
|
|
||||||
|
&--multi {
|
||||||
|
resize: vertical;
|
||||||
|
height: 78px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.maputnik-number {
|
.maputnik-number {
|
||||||
|
|
Loading…
Reference in a new issue