Skip to content

Commit 6c6f4f7

Browse files
committed
allows for configurable custom styles - #103
fixed nested router bug - #104
1 parent a3f3543 commit 6c6f4f7

File tree

8 files changed

+86
-19
lines changed

8 files changed

+86
-19
lines changed

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,46 @@ Fresco is built on top of React. To run Fresco from source use the following ste
4848
Fresco is able to be hosted from a subdirectory of a domain (i.e. https://yourhost.com/fresco/). To enable this functionality, modify the `package.json` file
4949

5050

51-
```
51+
``` json
5252
{
53-
"name": "fresco-app",
54-
"version": "0.1.0",
53+
"name": "fresco",
54+
"version": "0.0.1",
5555
"private": true,
5656
"homepage": "/fresco",
5757
...
5858

5959
```
6060

61+
Also, you'll need to modify the config inside `/src/config/index.json`.
62+
63+
``` json
64+
{
65+
"homepage": "/fresco"
66+
}
67+
```
68+
6169
Then use `npm run build` to build Fresco for deployment.
6270

71+
## Change default Fresco styles
72+
73+
You are able to change the default styles that Fresco loads up with. Update `/src/config/stylesDefault.json` with any number of Mapbox style JSONs. To load multiple styles in use an array structure like shown below:
74+
75+
``` json
76+
[
77+
{
78+
"id": "style1",
79+
...
80+
},{
81+
"id": "style2",
82+
...
83+
}
84+
]
85+
```
86+
87+
For a single style, just replace the contents of `/src/config/stylesDefault.json` with the style JSON.
88+
89+
When testing default styles, you'll have to clear out your localStorage `frescoStylesStore` or use an incognito window.
90+
6391
## Contributing
6492

6593
Contributions are welcome! Fork the repo and send in a PR with any bug fixes or features.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
2-
"name": "fresco-new",
2+
"name": "fresco",
33
"version": "0.1.0",
44
"private": true,
5+
"homepage": "",
56
"dependencies": {
67
"@mapbox/mapbox-gl-style-spec": "^13.13.1",
78
"@testing-library/jest-dom": "^4.2.4",

src/component/Page/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Loader from './Loader'
88
import Nav from './Nav'
99
import Route from './Route'
1010

11+
import config from '../../config'
1112
import modelApp from '../../model/app'
1213
import modelPreference from '../../model/preference'
1314
import modelSource from '../../model/source'
@@ -35,7 +36,7 @@ class Page extends React.Component {
3536
render(){
3637
return (
3738
<React.Fragment>
38-
<Router>
39+
<Router basename={config.homepage}>
3940
{this.renderFrame()}
4041
</Router>
4142
</React.Fragment>

src/config/index.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"homepage": ""
3+
}

src/model/style/starterStyle.js renamed to src/config/stylesDefault.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default {
1+
{
22
"version": 8,
33
"name": "hot-osm-starter",
44
"metadata": {
@@ -3241,4 +3241,4 @@ export default {
32413241
],
32423242
"id": "hot-osm-starter",
32433243
"owner": ""
3244-
}
3244+
}

src/model/style/actions.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {fromJS, Map} from 'immutable'
55
import fileDownload from 'js-file-download'
66

77
import actions from '../actions'
8+
import stylesDefault from '../../config/stylesDefault'
89

10+
import utilType from '../../utility/utilType'
911
import utilFile from '../../utility/utilFile'
1012
import utilLocalStorage from '../../utility/utilLocalStorage'
1113
import utilMapboxErr from '../../utility/utilMapboxErr'
@@ -178,12 +180,39 @@ const init = async ()=>{
178180
return
179181
}
180182

181-
const stylesDefault = fromJS(constants.defaultStyles)
183+
// get all config styles
184+
185+
// check if it's an array or obj
186+
187+
188+
const type = utilType.get(stylesDefault)
189+
let styles = {}
190+
if (type === 'ary'){
191+
stylesDefault.forEach(style => {
192+
const id = style.id? style.id: utilUid.make()
193+
styles[id] = {
194+
current:{
195+
...style,
196+
id
197+
}
198+
}
199+
})
200+
} else if (type === 'obj'){
201+
const id = stylesDefault.id? stylesDefault.id: utilUid.make()
202+
styles[id] = {
203+
current:{
204+
...stylesDefault,
205+
id
206+
}
207+
}
208+
} else {
209+
throw new Error(`style.init: defaultStyles (${type}) is not an array or object`)
210+
}
182211

183212
Store.dispatch({
184213
type:'STYLES_SET',
185214
payload:{
186-
styles: stylesDefault,
215+
styles: fromJS(styles),
187216
}
188217
})
189218
}

src/model/style/constants.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import starter from './starterStyle'
2-
31
const localStoragePath = 'frescoStylesStore'
42

53
const defaultLayers = [
@@ -15,20 +13,12 @@ const defaultLayers = [
1513
}
1614
]
1715

18-
const defaultStyles = {
19-
'hot-osm-starter':{
20-
current:{
21-
...starter
22-
}
23-
}
24-
}
2516
// source: https://osm-lambda.tegola.io/v1/capabilities/osm.json
2617

2718
const defaultMapboxVersion = 8
2819

2920
export default {
3021
defaultLayers,
3122
defaultMapboxVersion,
32-
defaultStyles,
3323
localStoragePath,
3424
}

src/utility/utilType.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const get = (val)=>{
2+
if (val === undefined) return 'und'
3+
if (val === null) return 'nul'
4+
if (val === true || val === false) return 'bool'
5+
var type = typeof val
6+
if (type === 'string') return 'str'
7+
if (type === 'number') return 'num'
8+
if (type === 'function') return 'fun'
9+
if (Object.prototype.toString.call(val) === '[object Array]') return 'ary'
10+
return 'obj'
11+
}
12+
13+
export default {
14+
get,
15+
}

0 commit comments

Comments
 (0)