import React from "react"; import latest from "@maplibre/maplibre-gl-style-spec/dist/latest.json"; import type {LightSpecification, ProjectionSpecification, SkySpecification, StyleSpecification, TerrainSpecification, TransitionSpecification} from "maplibre-gl"; import { type WithTranslation, withTranslation } from "react-i18next"; import { FieldArray } from "../FieldArray"; import { FieldNumber } from "../FieldNumber"; import { FieldString } from "../FieldString"; import { FieldUrl } from "../FieldUrl"; import { FieldSelect } from "../FieldSelect"; import { FieldEnum } from "../FieldEnum"; import { FieldColor } from "../FieldColor"; import { Modal } from "./Modal"; import { FieldJson } from "../FieldJson"; import { Block } from "../Block"; import { spec as fieldSpecAdditional } from "../../libs/field-spec-additional"; import type {OnStyleChangedCallback, StyleSpecificationWithId} from "../../libs/definitions"; type ModalSettingsInternalProps = { mapStyle: StyleSpecificationWithId onStyleChanged: OnStyleChangedCallback onChangeMetadataProperty(...args: unknown[]): unknown isOpen: boolean onOpenToggle(): void } & WithTranslation; class ModalSettingsInternal extends React.Component { changeTransitionProperty(property: keyof TransitionSpecification, value: number | undefined) { const transition = { ...this.props.mapStyle.transition, }; if (value === undefined) { delete transition[property]; } else { transition[property] = value; } this.props.onStyleChanged({ ...this.props.mapStyle, transition, }); } changeLightProperty(property: keyof LightSpecification, value: any) { const light = { ...this.props.mapStyle.light, }; if (value === undefined) { delete light[property]; } else { // @ts-ignore light[property] = value; } this.props.onStyleChanged({ ...this.props.mapStyle, light, }); } changeTerrainProperty(property: keyof TerrainSpecification, value: any) { const terrain = { ...this.props.mapStyle.terrain, } as TerrainSpecification; if (value === undefined) { delete terrain[property]; } else { // @ts-ignore terrain[property] = value; } this.props.onStyleChanged({ ...this.props.mapStyle, terrain, }); } changeSkyProperty(property: keyof SkySpecification, value: any) { const sky = { ...this.props.mapStyle.sky, }; if (value === undefined) { delete sky[property]; } else { sky[property] = value; } this.props.onStyleChanged({ ...this.props.mapStyle, sky, }); } changeProjectionType(value: any) { const projection = { ...this.props.mapStyle.projection, } as ProjectionSpecification; if (value === undefined) { delete projection.type; } else { projection.type = value; } this.props.onStyleChanged({ ...this.props.mapStyle, projection, }); } changeStyleProperty(property: keyof StyleSpecification | "owner", value: any) { const changedStyle = { ...this.props.mapStyle, }; if (value === undefined) { // @ts-ignore delete changedStyle[property]; } else { // @ts-ignore changedStyle[property] = value; } this.props.onStyleChanged(changedStyle); } render() { const metadata = this.props.mapStyle.metadata || {} as any; const {t, onChangeMetadataProperty, mapStyle} = this.props; const fsa = fieldSpecAdditional(t); const light = this.props.mapStyle.light || {}; const transition = this.props.mapStyle.transition || {}; const terrain = this.props.mapStyle.terrain || {} as TerrainSpecification; const projection = this.props.mapStyle.projection || {} as ProjectionSpecification; const sky = this.props.mapStyle.sky || {}; return
this.changeStyleProperty("name", value)} /> this.changeStyleProperty("owner", value)} /> this.changeStyleProperty("sprite", value)} /> this.changeStyleProperty("glyphs", value)} /> this.changeStyleProperty("font-faces", value)} /> onChangeMetadataProperty("maputnik:openmaptiles_access_token", value)} /> onChangeMetadataProperty("maputnik:thunderforest_access_token", value)} /> onChangeMetadataProperty("maputnik:stadia_access_token", value)} /> onChangeMetadataProperty("maputnik:locationiq_access_token", value)} /> this.changeStyleProperty("center", value)} /> this.changeStyleProperty("zoom", value)} /> this.changeStyleProperty("bearing", value)} /> this.changeStyleProperty("pitch", value)} /> this.changeStyleProperty("roll", value)} /> this.changeStyleProperty("centerAltitude", value)} /> this.changeLightProperty("anchor", value)} /> this.changeLightProperty("color", value)} /> this.changeLightProperty("intensity", value)} /> this.changeLightProperty("position", value)} /> this.changeTerrainProperty("source", value)} /> this.changeTerrainProperty("exaggeration", value)} /> this.changeSkyProperty("sky-color", value)} /> this.changeSkyProperty("horizon-color", value)} /> this.changeSkyProperty("fog-color", value)} /> this.changeSkyProperty("sky-horizon-blend", value)} /> this.changeSkyProperty("horizon-fog-blend", value)} /> this.changeSkyProperty("fog-ground-blend", value)} /> this.changeSkyProperty("atmosphere-blend", value)} /> this.changeTransitionProperty("delay", value)} /> this.changeTransitionProperty("duration", value)} /> this.changeProjectionType(value)} /> onChangeMetadataProperty("maputnik:renderer", value)} />
; } } export const ModalSettings = withTranslation()(ModalSettingsInternal);