From 0693dc3d422fdc6a2f3abfd4020b3f52e85f939a Mon Sep 17 00:00:00 2001 From: lukasmartinelli Date: Sat, 10 Sep 2016 16:53:58 +0200 Subject: [PATCH] Fix visibility toggle --- src/layers/editor.jsx | 22 ++++++++++++++++++---- src/stylestore.js | 4 ++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/layers/editor.jsx b/src/layers/editor.jsx index 9a4f27c..8f8b203 100644 --- a/src/layers/editor.jsx +++ b/src/layers/editor.jsx @@ -1,6 +1,8 @@ import React from 'react' +import Immutable from 'immutable' import { Toolbar, NavItem, Space} from 'rebass' import Collapse from 'react-collapse' + import theme from '../theme.js' import FillLayer from './fill.jsx' import LineLayer from './line.jsx' @@ -46,12 +48,24 @@ export class LayerEditor extends React.Component { } onPaintChanged(property, newValue) { - const changedLayer = this.props.layer.setIn(['paint', 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()) + } + + const changedLayer = layer.setIn(['paint', property], newValue) this.props.onLayerChanged(changedLayer) } onLayoutChanged(property, newValue) { - const changedLayer = this.props.layer.setIn(['layout', property], newValue) + let layer = this.props.layer + //TODO: by using immutable records we can avoid this checking if object exists + if(!layer.has('layout')) { + layer = layer.set('layout', Immutable.Map()) + } + + const changedLayer = layer.setIn(['layout', property], newValue) this.props.onLayerChanged(changedLayer) } @@ -86,7 +100,7 @@ export class LayerEditor extends React.Component { } toggleVisibility() { - if(this.props.layer.layout.visibility === 'none') { + if(this.props.layer.has('layout') && this.props.layer.getIn(['layout', 'visibility']) === 'none') { this.onLayoutChanged('visibility', 'visible') } else { this.onLayoutChanged('visibility', 'none') @@ -95,7 +109,7 @@ export class LayerEditor extends React.Component { render() { let visibleIcon = - if(this.props.layer.layout && this.props.layer.layout.visibility === 'none') { + if(this.props.layer.has('layout') && this.props.layer.getIn(['layout', 'visibility']) === 'none') { visibleIcon = } diff --git a/src/stylestore.js b/src/stylestore.js index cf05e48..07f0257 100644 --- a/src/stylestore.js +++ b/src/stylestore.js @@ -72,10 +72,10 @@ function styleKey(styleId) { // Ensure a style has a unique id and a created date function ensureOptionalStyleProps(mapStyle) { - if(!('id' in mapStyle)) { + if(!mapStyle.has('id')) { mapStyle = mapStyle.set('id', Math.random().toString(36).substr(2, 9)) } - if(!("created" in mapStyle)) { + if(!mapStyle.has('created')) { mapStyle = mapStyle.set('created', new Date()) } return mapStyle