mirror of
https://github.com/maputnik/editor.git
synced 2025-12-28 00:50:00 +00:00
## Launch Checklist This adds support for `relief-color` property so that it will create an elevation expression when the button is pressed. It also adds support for `colorArray` and `numberArray` types so that the user would be able to add the relevant information. Before: <img width="403" height="324" alt="image" src="https://github.com/user-attachments/assets/250abd81-6176-4711-a1ee-d33d443932d7" /> <img width="403" height="324" alt="image" src="https://github.com/user-attachments/assets/6a1bb268-66db-42a1-97fc-33e5a40863b6" /> After: <img width="403" height="324" alt="image" src="https://github.com/user-attachments/assets/8ebaa1ea-4ef9-4aed-abcd-3c8b0057ea76" /> <img width="403" height="324" alt="image" src="https://github.com/user-attachments/assets/e0728c92-85f9-4b86-8635-8877cf257b2f" /> - [x] Briefly describe the changes in this PR. - [x] Include before/after visuals or gifs if this PR includes visual changes. - [x] Write tests for all new functionality. - [x] Add an entry to `CHANGELOG.md` under the `## main` section. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
import React from 'react'
|
|
|
|
import FieldFunction from './FieldFunction'
|
|
import type {LayerSpecification} from 'maplibre-gl'
|
|
|
|
const iconProperties = ['background-pattern', 'fill-pattern', 'line-pattern', 'fill-extrusion-pattern', 'icon-image']
|
|
|
|
/** Extract field spec by {@fieldName} from the {@layerType} in the
|
|
* style specification from either the paint or layout group */
|
|
function getFieldSpec(spec: any, layerType: LayerSpecification["type"], fieldName: string) {
|
|
const groupName = getGroupName(spec, layerType, fieldName)
|
|
const group = spec[groupName + '_' + layerType]
|
|
const fieldSpec = group[fieldName]
|
|
if(iconProperties.indexOf(fieldName) >= 0) {
|
|
return {
|
|
...fieldSpec,
|
|
values: spec.$root.sprite.values
|
|
}
|
|
}
|
|
if(fieldName === 'text-font') {
|
|
return {
|
|
...fieldSpec,
|
|
values: spec.$root.glyphs.values
|
|
}
|
|
}
|
|
return fieldSpec
|
|
}
|
|
|
|
function getGroupName(spec: any, layerType: LayerSpecification["type"], fieldName: string): 'paint' | 'layout' {
|
|
const paint = spec['paint_' + layerType] || {}
|
|
return (fieldName in paint) ? 'paint' : 'layout';
|
|
}
|
|
|
|
type PropertyGroupProps = {
|
|
layer: LayerSpecification
|
|
groupFields: string[]
|
|
onChange(...args: unknown[]): unknown
|
|
spec: any
|
|
errors?: {[key: string]: {message: string}}
|
|
};
|
|
|
|
export default class PropertyGroup extends React.Component<PropertyGroupProps> {
|
|
onPropertyChange = (property: string, newValue: any) => {
|
|
const group = getGroupName(this.props.spec, this.props.layer.type, property)
|
|
this.props.onChange(group ,property, newValue)
|
|
}
|
|
|
|
render() {
|
|
const {errors} = this.props;
|
|
const fields = this.props.groupFields.map(fieldName => {
|
|
const fieldSpec = getFieldSpec(this.props.spec, this.props.layer.type, fieldName)
|
|
|
|
const paint = this.props.layer.paint || {}
|
|
const layout = this.props.layer.layout || {}
|
|
const fieldValue = fieldName in paint
|
|
? paint[fieldName as keyof typeof paint]
|
|
: layout[fieldName as keyof typeof layout]
|
|
const fieldType = fieldName in paint ? 'paint' : 'layout';
|
|
|
|
return <FieldFunction
|
|
errors={errors}
|
|
onChange={this.onPropertyChange}
|
|
key={fieldName}
|
|
fieldName={fieldName}
|
|
value={fieldValue}
|
|
fieldType={fieldType}
|
|
fieldSpec={fieldSpec}
|
|
/>
|
|
})
|
|
|
|
return <div className="maputnik-property-group">
|
|
{fields}
|
|
</div>
|
|
}
|
|
}
|