import React from "react"; import latest from "@maplibre/maplibre-gl-style-spec/dist/latest.json"; import type {LightSpecification, ProjectionSpecification, 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 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, }); } 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; return
this.changeStyleProperty("name", value)} /> this.changeStyleProperty("owner", value)} /> this.changeStyleProperty("sprite", value)} /> this.changeStyleProperty("glyphs", 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.changeLightProperty("anchor", value)} /> this.changeLightProperty("color", value)} /> this.changeLightProperty("intensity", value)} /> this.changeLightProperty("position", value)} /> this.changeTerrainProperty("source", value)} /> this.changeTerrainProperty("exaggeration", value)} /> this.changeTransitionProperty("delay", value)} /> this.changeTransitionProperty("duration", value)} /> this.changeProjectionType(value)} /> onChangeMetadataProperty("maputnik:renderer", value)} />
; } } const ModalSettings = withTranslation()(ModalSettingsInternal); export default ModalSettings;