hopefulMapStyle -> dirtyMapStyle

This commit is contained in:
orangemug 2020-02-01 17:55:26 +00:00
parent 3e2927e6a4
commit 5792c632f9

View file

@ -207,7 +207,7 @@ export default class App extends React.Component {
errors: [], errors: [],
infos: [], infos: [],
mapStyle: style.emptyStyle, mapStyle: style.emptyStyle,
hopefulMapStyle: style.emptyStyle, dirtyMapStyle: style.emptyStyle,
selectedLayerIndex: 0, selectedLayerIndex: 0,
sources: {}, sources: {},
vectorLayers: {}, vectorLayers: {},
@ -280,7 +280,7 @@ export default class App extends React.Component {
} }
updateFonts(urlTemplate) { updateFonts(urlTemplate) {
const metadata = this.state.hopefulMapStyle.metadata || {} const metadata = this.state.dirtyMapStyle.metadata || {}
const accessToken = metadata['maputnik:openmaptiles_access_token'] || tokens.openmaptiles const accessToken = metadata['maputnik:openmaptiles_access_token'] || tokens.openmaptiles
let glyphUrl = (typeof urlTemplate === 'string')? urlTemplate.replace('{key}', accessToken): urlTemplate; let glyphUrl = (typeof urlTemplate === 'string')? urlTemplate.replace('{key}', accessToken): urlTemplate;
@ -345,23 +345,23 @@ export default class App extends React.Component {
if(errors.length === 0) { if(errors.length === 0) {
if(newStyle.glyphs !== this.state.hopefulMapStyle.glyphs) { if(newStyle.glyphs !== this.state.dirtyMapStyle.glyphs) {
this.updateFonts(newStyle.glyphs) this.updateFonts(newStyle.glyphs)
} }
if(newStyle.sprite !== this.state.hopefulMapStyle.sprite) { if(newStyle.sprite !== this.state.dirtyMapStyle.sprite) {
this.updateIcons(newStyle.sprite) this.updateIcons(newStyle.sprite)
} }
this.revisionStore.addRevision(newStyle) this.revisionStore.addRevision(newStyle)
if(save) this.saveStyle(newStyle) if(save) this.saveStyle(newStyle)
this.setState({ this.setState({
hopefulMapStyle: newStyle, dirtyMapStyle: newStyle,
mapStyle: newStyle, mapStyle: newStyle,
errors: [], errors: [],
}) })
} else { } else {
this.setState({ this.setState({
hopefulMapStyle: newStyle, dirtyMapStyle: newStyle,
errors: mappedErrors, errors: mappedErrors,
}) })
} }
@ -373,38 +373,38 @@ export default class App extends React.Component {
let activeStyle; let activeStyle;
// Check our dirty style state first, otherwise just undo to that state. // Check our dirty style state first, otherwise just undo to that state.
if (isEqual(this.state.mapStyle, this.state.hopefulMapStyle)) { if (isEqual(this.state.mapStyle, this.state.dirtyMapStyle)) {
activeStyle = this.revisionStore.undo() activeStyle = this.revisionStore.undo()
} }
else { else {
activeStyle = this.state.mapStyle; activeStyle = this.state.mapStyle;
} }
const messages = undoMessages(this.state.hopefulMapStyle, activeStyle) const messages = undoMessages(this.state.dirtyMapStyle, activeStyle)
this.saveStyle(activeStyle) this.saveStyle(activeStyle)
this.setState({ this.setState({
infos: messages, infos: messages,
mapStyle: activeStyle, mapStyle: activeStyle,
hopefulMapStyle: activeStyle, dirtyMapStyle: activeStyle,
errors: [], errors: [],
}) })
} }
onRedo = () => { onRedo = () => {
const activeStyle = this.revisionStore.redo() const activeStyle = this.revisionStore.redo()
const messages = redoMessages(this.state.hopefulMapStyle, activeStyle) const messages = redoMessages(this.state.dirtyMapStyle, activeStyle)
this.saveStyle(activeStyle) this.saveStyle(activeStyle)
this.setState({ this.setState({
infos: messages, infos: messages,
mapStyle: activeStyle, mapStyle: activeStyle,
hopefulMapStyle: activeStyle, dirtyMapStyle: activeStyle,
errors: [], errors: [],
}) })
} }
onMoveLayer = (move) => { onMoveLayer = (move) => {
let { oldIndex, newIndex } = move; let { oldIndex, newIndex } = move;
let layers = this.state.hopefulMapStyle.layers; let layers = this.state.dirtyMapStyle.layers;
oldIndex = clamp(oldIndex, 0, layers.length-1); oldIndex = clamp(oldIndex, 0, layers.length-1);
newIndex = clamp(newIndex, 0, layers.length-1); newIndex = clamp(newIndex, 0, layers.length-1);
if(oldIndex === newIndex) return; if(oldIndex === newIndex) return;
@ -422,14 +422,14 @@ export default class App extends React.Component {
onLayersChange = (changedLayers) => { onLayersChange = (changedLayers) => {
const changedStyle = { const changedStyle = {
...this.state.hopefulMapStyle, ...this.state.dirtyMapStyle,
layers: changedLayers layers: changedLayers
} }
this.onStyleChanged(changedStyle) this.onStyleChanged(changedStyle)
} }
onLayerDestroy = (layerId) => { onLayerDestroy = (layerId) => {
let layers = this.state.hopefulMapStyle.layers; let layers = this.state.dirtyMapStyle.layers;
const remainingLayers = layers.slice(0); const remainingLayers = layers.slice(0);
const idx = style.indexOfLayer(remainingLayers, layerId) const idx = style.indexOfLayer(remainingLayers, layerId)
remainingLayers.splice(idx, 1); remainingLayers.splice(idx, 1);
@ -448,7 +448,7 @@ export default class App extends React.Component {
} }
onLayerVisibilityToggle = (layerId) => { onLayerVisibilityToggle = (layerId) => {
let layers = this.state.hopefulMapStyle.layers; let layers = this.state.dirtyMapStyle.layers;
const changedLayers = layers.slice(0) const changedLayers = layers.slice(0)
const idx = style.indexOfLayer(changedLayers, layerId) const idx = style.indexOfLayer(changedLayers, layerId)
@ -463,7 +463,7 @@ export default class App extends React.Component {
onLayerIdChange = (oldId, newId) => { onLayerIdChange = (oldId, newId) => {
const changedLayers = this.state.hopefulMapStyle.layers.slice(0) const changedLayers = this.state.dirtyMapStyle.layers.slice(0)
const idx = style.indexOfLayer(changedLayers, oldId) const idx = style.indexOfLayer(changedLayers, oldId)
changedLayers[idx] = { changedLayers[idx] = {
@ -476,7 +476,7 @@ export default class App extends React.Component {
onLayerChanged = (layer) => { onLayerChanged = (layer) => {
console.log("test: onLayerChanged", layer); console.log("test: onLayerChanged", layer);
const changedLayers = this.state.hopefulMapStyle.layers.slice(0) const changedLayers = this.state.dirtyMapStyle.layers.slice(0)
const idx = style.indexOfLayer(changedLayers, layer.id) const idx = style.indexOfLayer(changedLayers, layer.id)
changedLayers[idx] = layer changedLayers[idx] = layer
@ -513,7 +513,7 @@ export default class App extends React.Component {
fetchSources() { fetchSources() {
const sourceList = {...this.state.sources}; const sourceList = {...this.state.sources};
for(let [key, val] of Object.entries(this.state.hopefulMapStyle.sources)) { for(let [key, val] of Object.entries(this.state.dirtyMapStyle.sources)) {
if(sourceList.hasOwnProperty(key)) { if(sourceList.hasOwnProperty(key)) {
continue; continue;
} }
@ -637,7 +637,7 @@ export default class App extends React.Component {
} }
onLayerSelect = (layerId) => { onLayerSelect = (layerId) => {
const idx = style.indexOfLayer(this.state.hopefulMapStyle.layers, layerId) const idx = style.indexOfLayer(this.state.dirtyMapStyle.layers, layerId)
this.setState({ selectedLayerIndex: idx }) this.setState({ selectedLayerIndex: idx })
} }
@ -677,14 +677,14 @@ export default class App extends React.Component {
} }
render() { render() {
const layers = this.state.hopefulMapStyle.layers || [] const layers = this.state.dirtyMapStyle.layers || []
const selectedLayer = layers.length > 0 ? layers[this.state.selectedLayerIndex] : null const selectedLayer = layers.length > 0 ? layers[this.state.selectedLayerIndex] : null
const metadata = this.state.hopefulMapStyle.metadata || {} const metadata = this.state.dirtyMapStyle.metadata || {}
const toolbar = <Toolbar const toolbar = <Toolbar
renderer={this._getRenderer()} renderer={this._getRenderer()}
mapState={this.state.mapState} mapState={this.state.mapState}
mapStyle={this.state.hopefulMapStyle} mapStyle={this.state.dirtyMapStyle}
inspectModeEnabled={this.state.mapState === "inspect"} inspectModeEnabled={this.state.mapState === "inspect"}
sources={this.state.sources} sources={this.state.sources}
onStyleChanged={this.onStyleChanged} onStyleChanged={this.onStyleChanged}
@ -711,7 +711,7 @@ export default class App extends React.Component {
layer={selectedLayer} layer={selectedLayer}
layerIndex={this.state.selectedLayerIndex} layerIndex={this.state.selectedLayerIndex}
isFirstLayer={this.state.selectedLayerIndex < 1} isFirstLayer={this.state.selectedLayerIndex < 1}
isLastLayer={this.state.selectedLayerIndex === this.state.hopefulMapStyle.layers.length-1} isLastLayer={this.state.selectedLayerIndex === this.state.dirtyMapStyle.layers.length-1}
sources={this.state.sources} sources={this.state.sources}
vectorLayers={this.state.vectorLayers} vectorLayers={this.state.vectorLayers}
spec={this.state.spec} spec={this.state.spec}
@ -748,7 +748,7 @@ export default class App extends React.Component {
onOpenToggle={this.toggleModal.bind(this, 'shortcuts')} onOpenToggle={this.toggleModal.bind(this, 'shortcuts')}
/> />
<SettingsModal <SettingsModal
mapStyle={this.state.hopefulMapStyle} mapStyle={this.state.dirtyMapStyle}
onStyleChanged={this.onStyleChanged} onStyleChanged={this.onStyleChanged}
onChangeMetadataProperty={this.onChangeMetadataProperty} onChangeMetadataProperty={this.onChangeMetadataProperty}
isOpen={this.state.isOpen.settings} isOpen={this.state.isOpen.settings}
@ -756,7 +756,7 @@ export default class App extends React.Component {
openlayersDebugOptions={this.state.openlayersDebugOptions} openlayersDebugOptions={this.state.openlayersDebugOptions}
/> />
<ExportModal <ExportModal
mapStyle={this.state.hopefulMapStyle} mapStyle={this.state.dirtyMapStyle}
onStyleChanged={this.onStyleChanged} onStyleChanged={this.onStyleChanged}
isOpen={this.state.isOpen.export} isOpen={this.state.isOpen.export}
onOpenToggle={this.toggleModal.bind(this, 'export')} onOpenToggle={this.toggleModal.bind(this, 'export')}
@ -767,7 +767,7 @@ export default class App extends React.Component {
onOpenToggle={this.toggleModal.bind(this, 'open')} onOpenToggle={this.toggleModal.bind(this, 'open')}
/> />
<SourcesModal <SourcesModal
mapStyle={this.state.hopefulMapStyle} mapStyle={this.state.dirtyMapStyle}
onStyleChanged={this.onStyleChanged} onStyleChanged={this.onStyleChanged}
isOpen={this.state.isOpen.sources} isOpen={this.state.isOpen.sources}
onOpenToggle={this.toggleModal.bind(this, 'sources')} onOpenToggle={this.toggleModal.bind(this, 'sources')}