|
@@ -3,7 +3,8 @@ import { RouteComponentProps } from 'react-router'
|
|
|
import { reducer, initialState, getLayersAction, updateLayerAction, saveLayersAction, Item } from './reducer'
|
|
|
import VectorShow from '../components/VectorShow'
|
|
|
|
|
|
-type Attr = 'lineColor' | 'lineWidth' | 'fillColor'
|
|
|
+type Attr = 'lineColor' | 'lineWidth' | 'fillColor' | 'show'
|
|
|
+type EvAttr = 'value' | 'checked'
|
|
|
|
|
|
function StyleEdit(props: RouteComponentProps) {
|
|
|
let [state, dispatch] = useReducer(reducer, initialState)
|
|
@@ -15,8 +16,8 @@ function StyleEdit(props: RouteComponentProps) {
|
|
|
useEffect(() => { getLayersAction(dispatch, params.id) }, [params.id])
|
|
|
useEffect(() => { layer || setLayer(layers[0]) }, [layer, layers])
|
|
|
|
|
|
- const changeHandle = (attr: Attr) => (ev: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
- updateLayerAction(dispatch, layer, { ...style, [attr]: ev.target.value })
|
|
|
+ const changeHandle = (attr: Attr, evAttr: EvAttr = 'value') => (ev: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
+ updateLayerAction(dispatch, layer, { ...style, [attr]: ev.target[evAttr] })
|
|
|
}
|
|
|
const saveHandle = () => { saveLayersAction(style, params.id) }
|
|
|
const verctorInfo = style && { ...style, url: style.getUrl }
|
|
@@ -28,9 +29,22 @@ function StyleEdit(props: RouteComponentProps) {
|
|
|
</select>
|
|
|
{style && (
|
|
|
<Fragment>
|
|
|
- <input type="color" value={style.fillColor} onChange={changeHandle('fillColor')} />
|
|
|
- <input type="color" value={style.lineColor} onChange={changeHandle('lineColor')} />
|
|
|
- <input type="number" value={style.lineWidth} onChange={changeHandle('lineWidth')} />
|
|
|
+ <div>
|
|
|
+ <label>填充颜色</label>
|
|
|
+ <input type="color" value={style.fillColor} onChange={changeHandle('fillColor')} />
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label>线条颜色</label>
|
|
|
+ <input type="color" value={style.lineColor} onChange={changeHandle('lineColor')} />
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label>线条厚度</label>
|
|
|
+ <input type="number" value={style.lineWidth} onChange={changeHandle('lineWidth')} />
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label>是否显示</label>
|
|
|
+ <input type="checkbox" checked={style.show} onChange={changeHandle('show', 'checked')} />
|
|
|
+ </div>
|
|
|
<button onClick={saveHandle}>保存</button>
|
|
|
</Fragment>
|
|
|
)}
|