mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-14 17:03:31 +01:00
Draft of color picker
This commit is contained in:
parent
362f7ae9a1
commit
a05881a078
4 changed files with 50 additions and 25 deletions
22
src/app.jsx
22
src/app.jsx
|
@ -90,6 +90,17 @@ export default class App extends React.Component {
|
|||
this.onStyleChanged(changedStyle)
|
||||
}
|
||||
|
||||
onLayerChanged(layer) {
|
||||
console.log(layer)
|
||||
const changedStyle = this.state.mapStyle.setIn('layers', layer.get('id'), layer)
|
||||
this.onStyleChanged(changedStyle)
|
||||
}
|
||||
|
||||
onLayerChanged(layer) {
|
||||
const changedStyle = this.state.mapStyle.setIn(['layers', layer.get('id')], layer)
|
||||
this.onStyleChanged(changedStyle)
|
||||
}
|
||||
|
||||
mapRenderer() {
|
||||
const mapProps = {
|
||||
mapStyle: this.state.mapStyle,
|
||||
|
@ -119,7 +130,9 @@ export default class App extends React.Component {
|
|||
onStyleDownload={this.onStyleDownload.bind(this)}
|
||||
/>
|
||||
<div style={{
|
||||
...fullHeight,
|
||||
position: 'absolute',
|
||||
bottom: 0,
|
||||
height: "100%",
|
||||
top: 50,
|
||||
left: 0,
|
||||
zIndex: 100,
|
||||
|
@ -134,15 +147,16 @@ export default class App extends React.Component {
|
|||
/>
|
||||
</div>
|
||||
<div style={{
|
||||
...fullHeight,
|
||||
position: 'absolute',
|
||||
bottom: 0,
|
||||
height: "100%",
|
||||
top: 50,
|
||||
left: 180,
|
||||
zIndex: 100,
|
||||
width: 300,
|
||||
overflow: "hidden",
|
||||
backgroundColor: colors.gray}
|
||||
}>
|
||||
{this.state.selectedLayer && <LayerEditor layer={this.state.selectedLayer} />}
|
||||
{this.state.selectedLayer && <LayerEditor layer={this.state.selectedLayer} onLayerChanged={this.onLayerChanged.bind(this)} />}
|
||||
</div>
|
||||
{this.mapRenderer()}
|
||||
</div>
|
||||
|
|
|
@ -1,33 +1,47 @@
|
|||
import React from 'react'
|
||||
import inputStyle from './input.js'
|
||||
import ColorPicker from 'react-colorpickr'
|
||||
import 'react-colorpickr/dist/colorpickr.css'
|
||||
|
||||
function formatColor(color) {
|
||||
if(color.a !== 1) {
|
||||
return `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a})`
|
||||
}
|
||||
return `rgb(${color.r}, ${color.g}, ${color.b})`
|
||||
}
|
||||
|
||||
/*** Number fields with support for min, max and units and documentation*/
|
||||
class ColorField extends React.Component {
|
||||
static propTypes = {
|
||||
onChange: React.PropTypes.func.isRequired,
|
||||
name: React.PropTypes.string.isRequired,
|
||||
name: React.PropTypes.string.isRequired,
|
||||
value: React.PropTypes.string,
|
||||
default: React.PropTypes.number,
|
||||
doc: React.PropTypes.string,
|
||||
}
|
||||
|
||||
onChange(e) {
|
||||
const value = e.target.value
|
||||
return this.props.onChange(value === "" ? null: value)
|
||||
}
|
||||
render() {
|
||||
return <div style={{...inputStyle.property, position: 'relative'}}>
|
||||
<div style={{
|
||||
position: 'absolute',
|
||||
left: 200
|
||||
}}>
|
||||
<ColorPicker
|
||||
value={this.props.value}
|
||||
onChange={c => this.props.onChange(formatColor(c))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
render() {
|
||||
return <div style={inputStyle.property}>
|
||||
<label style={inputStyle.label}>{this.props.name}</label>
|
||||
<input
|
||||
style={inputStyle.input}
|
||||
name={this.props.name}
|
||||
placeholder={this.props.default}
|
||||
value={this.props.value ? this.props.value : ""}
|
||||
onChange={this.onChange.bind(this)}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
<label style={inputStyle.label}>{this.props.name}</label>
|
||||
<input
|
||||
style={inputStyle.input}
|
||||
name={this.props.name}
|
||||
placeholder={this.props.default}
|
||||
value={this.props.value ? this.props.value : ""}
|
||||
onChange={(e) => this.props.onChange(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
export default ColorField
|
||||
|
|
|
@ -36,10 +36,8 @@ class ZoomSpecField extends React.Component {
|
|||
render() {
|
||||
if(isZoomField(this.props.value)) {
|
||||
const zoomFields = this.props.value.get('stops').map(stop => {
|
||||
console.log(stop)
|
||||
const zoomLevel = stop.get(0)
|
||||
const value = stop.get(1)
|
||||
console.log(zoomLevel, value)
|
||||
|
||||
return <div key={zoomLevel}>
|
||||
<b><span style={inputStyle.label}>Zoom Level {zoomLevel}</span></b>
|
||||
|
|
|
@ -59,6 +59,7 @@ export class LayerEditor extends React.Component {
|
|||
onPaintChanged(property, newValue) {
|
||||
let layer = this.props.layer
|
||||
//TODO: by using immutable records we can avoid this checking if object exists
|
||||
//
|
||||
if(!layer.has('paint')) {
|
||||
layer = layer.set('paint', Immutable.Map())
|
||||
}
|
||||
|
@ -143,11 +144,9 @@ export class LayerEditor extends React.Component {
|
|||
<MdDelete />
|
||||
</NavItem>
|
||||
</Toolbar>
|
||||
<ScrollContainer>
|
||||
<div style={{padding: theme.scale[2], paddingRight: 0, backgroundColor: theme.colors.black}}>
|
||||
{this.layerFromType(this.props.layer.get('type'))}
|
||||
</div>
|
||||
</ScrollContainer>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue