mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-11-10 08:47:46 +01:00
Move storing access token into style metadata
This commit is contained in:
parent
604be38b7c
commit
ccc39b87db
3 changed files with 14 additions and 25 deletions
|
@ -11,7 +11,7 @@ import Toolbar from './Toolbar'
|
||||||
import AppLayout from './AppLayout'
|
import AppLayout from './AppLayout'
|
||||||
|
|
||||||
import style from '../libs/style.js'
|
import style from '../libs/style.js'
|
||||||
import { loadDefaultStyle, SettingsStore, StyleStore } from '../libs/stylestore'
|
import { loadDefaultStyle, StyleStore } from '../libs/stylestore'
|
||||||
import { ApiStyleStore } from '../libs/apistore'
|
import { ApiStyleStore } from '../libs/apistore'
|
||||||
import { RevisionStore } from '../libs/revisions'
|
import { RevisionStore } from '../libs/revisions'
|
||||||
import LayerWatcher from '../libs/layerwatcher'
|
import LayerWatcher from '../libs/layerwatcher'
|
||||||
|
@ -31,9 +31,7 @@ export default class App extends React.Component {
|
||||||
this.styleStore.latestStyle(mapStyle => this.onStyleChanged(mapStyle))
|
this.styleStore.latestStyle(mapStyle => this.onStyleChanged(mapStyle))
|
||||||
})
|
})
|
||||||
|
|
||||||
this.settingsStore = new SettingsStore()
|
|
||||||
this.state = {
|
this.state = {
|
||||||
accessToken: this.settingsStore.accessToken,
|
|
||||||
mapStyle: style.emptyStyle,
|
mapStyle: style.emptyStyle,
|
||||||
selectedLayerIndex: 0,
|
selectedLayerIndex: 0,
|
||||||
}
|
}
|
||||||
|
@ -85,11 +83,6 @@ export default class App extends React.Component {
|
||||||
this.setState({ mapStyle: activeStyle })
|
this.setState({ mapStyle: activeStyle })
|
||||||
}
|
}
|
||||||
|
|
||||||
onAccessTokenChanged(newToken) {
|
|
||||||
this.settingsStore.accessToken = newToken
|
|
||||||
this.setState({ accessToken: newToken })
|
|
||||||
}
|
|
||||||
|
|
||||||
onLayersChange(changedLayers) {
|
onLayersChange(changedLayers) {
|
||||||
const changedStyle = {
|
const changedStyle = {
|
||||||
...this.state.mapStyle,
|
...this.state.mapStyle,
|
||||||
|
@ -133,9 +126,10 @@ export default class App extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
mapRenderer() {
|
mapRenderer() {
|
||||||
|
const metadata = this.state.mapStyle.metadata || {}
|
||||||
const mapProps = {
|
const mapProps = {
|
||||||
mapStyle: this.state.mapStyle,
|
mapStyle: this.state.mapStyle,
|
||||||
accessToken: this.state.accessToken,
|
accessToken: metadata['maputnik:access_token'],
|
||||||
onDataChange: (e) => {
|
onDataChange: (e) => {
|
||||||
this.layerWatcher.analyzeMap(e.map)
|
this.layerWatcher.analyzeMap(e.map)
|
||||||
},
|
},
|
||||||
|
@ -146,7 +140,6 @@ export default class App extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const metadata = this.state.mapStyle.metadata || {}
|
|
||||||
const renderer = metadata['maputnik:renderer'] || 'mbgljs'
|
const renderer = metadata['maputnik:renderer'] || 'mbgljs'
|
||||||
|
|
||||||
// Check if OL3 code has been loaded?
|
// Check if OL3 code has been loaded?
|
||||||
|
|
|
@ -23,18 +23,19 @@ class SettingsModal extends React.Component {
|
||||||
this.props.onStyleChanged(changedStyle)
|
this.props.onStyleChanged(changedStyle)
|
||||||
}
|
}
|
||||||
|
|
||||||
onRendererChange(renderer) {
|
onMetadataChange(key, value) {
|
||||||
const changedStyle = {
|
const changedStyle = {
|
||||||
...this.props.mapStyle,
|
...this.props.mapStyle,
|
||||||
metadata: {
|
metadata: {
|
||||||
...this.props.mapStyle.metadata,
|
...this.props.mapStyle.metadata,
|
||||||
'maputnik:renderer': renderer,
|
[key]: value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.props.onStyleChanged(changedStyle)
|
this.props.onStyleChanged(changedStyle)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const metadata = this.props.mapStyle.metadata || {}
|
||||||
const inputProps = { }
|
const inputProps = { }
|
||||||
return <Modal
|
return <Modal
|
||||||
isOpen={this.props.isOpen}
|
isOpen={this.props.isOpen}
|
||||||
|
@ -67,6 +68,12 @@ class SettingsModal extends React.Component {
|
||||||
/>
|
/>
|
||||||
</InputBlock>
|
</InputBlock>
|
||||||
|
|
||||||
|
<InputBlock label={"Access Token"}>
|
||||||
|
<StringInput {...inputProps}
|
||||||
|
value={metadata['maputnik:access_token']}
|
||||||
|
onChange={this.onMetadataChange.bind(this, "maputnik:access_token")}
|
||||||
|
/>
|
||||||
|
</InputBlock>
|
||||||
|
|
||||||
<InputBlock label={"Style Renderer"}>
|
<InputBlock label={"Style Renderer"}>
|
||||||
<SelectInput {...inputProps}
|
<SelectInput {...inputProps}
|
||||||
|
@ -75,8 +82,8 @@ class SettingsModal extends React.Component {
|
||||||
['ol3', 'Open Layers 3'],
|
['ol3', 'Open Layers 3'],
|
||||||
['inspection', 'Inspection Mode'],
|
['inspection', 'Inspection Mode'],
|
||||||
]}
|
]}
|
||||||
value={(this.props.mapStyle.metadata || {})['maputnik:renderer'] || 'mbgljs'}
|
value={metadata['maputnik:renderer'] || 'mbgljs'}
|
||||||
onChange={this.onRendererChange.bind(this)}
|
onChange={this.onMetadataChange.bind(this, 'maputnik:renderer')}
|
||||||
/>
|
/>
|
||||||
</InputBlock>
|
</InputBlock>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
|
@ -61,17 +61,6 @@ function styleKey(styleId) {
|
||||||
return [storagePrefix, stylePrefix, styleId].join(":")
|
return [storagePrefix, stylePrefix, styleId].join(":")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store style independent settings
|
|
||||||
export class SettingsStore {
|
|
||||||
get accessToken() {
|
|
||||||
const token = window.localStorage.getItem(storageKeys.accessToken)
|
|
||||||
return token ? token : ""
|
|
||||||
}
|
|
||||||
set accessToken(val) {
|
|
||||||
window.localStorage.setItem(storageKeys.accessToken, val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Manages many possible styles that are stored in the local storage
|
// Manages many possible styles that are stored in the local storage
|
||||||
export class StyleStore {
|
export class StyleStore {
|
||||||
// Tile store will load all items from local storage and
|
// Tile store will load all items from local storage and
|
||||||
|
|
Loading…
Reference in a new issue