Colored layers

This commit is contained in:
lukasmartinelli 2016-09-09 18:53:57 +02:00
parent f0e61fd0be
commit bbf75876f3
9 changed files with 71 additions and 16 deletions

View file

@ -20,6 +20,7 @@
"mapbox-gl": "^0.23.0", "mapbox-gl": "^0.23.0",
"mapbox-gl-style-spec": "^8.8.0", "mapbox-gl-style-spec": "^8.8.0",
"node-sass": "^3.9.2", "node-sass": "^3.9.2",
"randomcolor": "^0.4.4",
"react": "^15.3.0", "react": "^15.3.0",
"react-collapse": "^2.3.3", "react-collapse": "^2.3.3",
"react-dom": "15.3.0", "react-dom": "15.3.0",

View file

@ -57,7 +57,7 @@ export default class App extends React.Component {
} }
render() { render() {
return <div style={{ fontFamily: theme.fontFamily, color: theme.color }}> return <div style={{ fontFamily: theme.fontFamily, color: theme.color, fontWeight: 300 }}>
<Toolbar <Toolbar
onStyleUpload={this.onStyleUpload.bind(this)} onStyleUpload={this.onStyleUpload.bind(this)}
onStyleDownload={this.onStyleDownload.bind(this)} onStyleDownload={this.onStyleDownload.bind(this)}

View file

@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import randomColor from 'randomcolor'
import { Block, ButtonCircle, Heading, Checkbox, Slider, Switch, Input, Panel, PanelHeader, Toolbar, NavItem, Tooltip, Container, Space} from 'rebass' import { Block, ButtonCircle, Heading, Checkbox, Slider, Switch, Input, Panel, PanelHeader, Toolbar, NavItem, Tooltip, Container, Space} from 'rebass'
import { Button, Text } from 'rebass' import { Button, Text } from 'rebass'
import {MdArrowDropDown, MdArrowDropUp, MdAddToPhotos, MdDelete, MdVisibilityOff} from 'react-icons/lib/md'; import {MdArrowDropDown, MdArrowDropUp, MdAddToPhotos, MdDelete, MdVisibilityOff} from 'react-icons/lib/md';
@ -146,13 +146,14 @@ export class LayerPanel extends React.Component {
padding: theme.scale[0], padding: theme.scale[0],
borderBottom: 1, borderBottom: 1,
borderTop: 1, borderTop: 1,
borderLeft: 0, borderLeft: 2,
borderRight: 0, borderRight: 0,
borderStyle: "solid", borderStyle: "solid",
borderColor: theme.borderColor, borderColor: theme.borderColor,
borderLeftColor: this.state.layer.metadata["mapolo:color"],
}}> }}>
<Toolbar onClick={this.toggleLayer.bind(this)}> <Toolbar onClick={this.toggleLayer.bind(this)}>
<NavItem> <NavItem style={{fontWeight: 400}}>
#{this.state.layer.id} #{this.state.layer.id}
</NavItem> </NavItem>
<Space auto x={1} /> <Space auto x={1} />
@ -164,7 +165,7 @@ export class LayerPanel extends React.Component {
</NavItem> </NavItem>
</Toolbar> </Toolbar>
<Collapse isOpened={this.state.isOpened}> <Collapse isOpened={this.state.isOpened}>
<div style={{padding: theme.scale[2], paddingRight: 0}}> <div style={{padding: theme.scale[2], paddingRight: 0, backgroundColor: theme.colors.black}}>
{this.layerFromType(this.state.layer.type)} {this.layerFromType(this.state.layer.type)}
</div> </div>
</Collapse> </Collapse>
@ -186,7 +187,7 @@ export class LayerEditor extends React.Component {
return <div> return <div>
<Toolbar style={{marginRight: 20}}> <Toolbar style={{marginRight: 20}}>
<NavItem> <NavItem>
Layers <Heading>Layers</Heading>
</NavItem> </NavItem>
<Space auto x={1} /> <Space auto x={1} />
<Button> <Button>

View file

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import theme from './theme.js' import theme from './theme.js'
import { Container, Input, Toolbar, NavItem, Space } from 'rebass' import { Heading, Container, Input, Toolbar, NavItem, Space } from 'rebass'
/** Edit global settings within a style such as the name */ /** Edit global settings within a style such as the name */
export class SettingsEditor extends React.Component { export class SettingsEditor extends React.Component {
@ -26,9 +26,8 @@ export class SettingsEditor extends React.Component {
return <div> return <div>
<Toolbar style={{marginRight: 20}}> <Toolbar style={{marginRight: 20}}>
<NavItem> <NavItem>
Settings <Heading>Settings</Heading>
</NavItem> </NavItem>
<Space auto x={1} />
</Toolbar> </Toolbar>
<Container> <Container>
<Input <Input

View file

@ -1,4 +1,17 @@
import React from 'react'; import React from 'react';
import randomColor from 'randomcolor'
function assignColorsToLayers(layers) {
return layers.map(layer => {
if(!layer.metadata) {
layer.metadata = {}
}
if(!"mapolo:color" in layer.metadata) {
layer.metadata["mapolo:color"] = randomColor()
}
return layer
})
}
// A wrapper around Mapbox GL style to publish // A wrapper around Mapbox GL style to publish
// and subscribe to map changes // and subscribe to map changes
@ -7,24 +20,56 @@ export class StyleManager {
this.commandHistory = []; this.commandHistory = [];
this.subscribers = []; this.subscribers = [];
this.mapStyle = mapStyle; this.mapStyle = mapStyle;
if(this.mapStyle) {
this.mapStyle.layers = assignColorsToLayers(this.mapStyle.layers)
}
} }
onStyleChange(cb) { onStyleChange(cb) {
this.subscribers.push(cb); this.subscribers.push(cb);
} }
changeStyle(command) { changeStyle(change) {
this.commandHistory.push(command) this.commandHistory.push(change)
this.subscribers.forEach(f => f(command)) this.subscribers.forEach(f => f(change))
console.log(command) console.log(change)
} }
exportStyle() { exportStyle() {
return JSON.stringify(this.mapStyle, null, 4) return JSON.stringify(this.mapStyle, null, 4)
} }
settings() {
const { name, sprite, glyphs, owner } = this.mapStyle
return { name, sprite, glyphs, owner }
}
set name(val) {
this.mapStyle.name = val
}
set owner(val) {
this.mapStyle.owner = val
}
set glyphs(val) {
this.mapStyle.glyphs = val
this.changeStyle({
command: 'setStyle',
args: [this.mapStyle]
})
}
set sprite(val) {
this.mapStyle.sprite = val
this.changeStyle({
command: 'setStyle',
args: [this.mapStyle]
})
}
layer(layerId) { layer(layerId) {
console.log(this.mapStyle)
return this.mapStyle.layers[layerId] return this.mapStyle.layers[layerId]
} }

View file

@ -4,6 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title><%= htmlWebpackPlugin.options.title %></title> <title><%= htmlWebpackPlugin.options.title %></title>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,700" rel="stylesheet">
</head> </head>
<body> <body>
<div id="app">Loading...</div> <div id="app">Loading...</div>

View file

@ -41,7 +41,7 @@ const border = {
const dark = { const dark = {
name: 'Dark', name: 'Dark',
color: colors.white, color: colors.white,
fontFamily: 'Open Sans Bold, sans-serif', fontFamily: 'Roboto, sans-serif',
scale, scale,
fontSizes, fontSizes,
colors, colors,
@ -83,7 +83,11 @@ const dark = {
fontWeight: 400, fontWeight: 400,
minHeight: scale[3] minHeight: scale[3]
}, },
Label: {
fontWeight: 300,
},
Input: { Input: {
fontWeight: 300,
fontSize: fontSizes[5], fontSize: fontSizes[5],
}, },
} }

View file

@ -49,7 +49,6 @@ export class Toolbar extends React.Component {
</Block> </Block>
} }
console.log(this.state)
return <Container style={{ return <Container style={{
zIndex: 100, zIndex: 100,
position: "fixed", position: "fixed",

View file

@ -1,5 +1,6 @@
import React from 'react' import React from 'react'
import { LayerEditor } from './layers.jsx' import { LayerEditor } from './layers.jsx'
import { SettingsEditor } from './settings.jsx'
import theme from './theme.js' import theme from './theme.js'
/** The workspace drawer contains the editor components depending on the context /** The workspace drawer contains the editor components depending on the context
@ -17,6 +18,10 @@ export class WorkspaceDrawer extends React.Component {
workspaceContent = <LayerEditor styleManager={this.props.styleManager}/> workspaceContent = <LayerEditor styleManager={this.props.styleManager}/>
} }
if(this.props.workContext === "settings" && this.props.styleManager.mapStyle) {
workspaceContent = <SettingsEditor styleManager={this.props.styleManager}/>
}
return <div style={{ return <div style={{
zIndex: 100, zIndex: 100,
position: "fixed", position: "fixed",