Layer: {formatLayerId(this.props.layer.id)}
-
{Object.keys(items).map((id, idx) => {
const item = items[id];
return (
- ); })}
import PropTypes from "prop-types"; import React from "react"; import { Button, Menu, MenuItem, Wrapper } from "react-aria-menubutton"; import { Accordion } from "react-accessible-accordion"; import FieldComment from "./FieldComment"; import FieldId from "./FieldId"; import FieldJson from "./FieldJson"; import FieldMaxZoom from "./FieldMaxZoom"; import FieldMinZoom from "./FieldMinZoom"; import FieldSource from "./FieldSource"; import FieldSourceLayer from "./FieldSourceLayer"; import FieldType from "./FieldType"; import FilterEditor from "./FilterEditor"; import LayerEditorGroup from "./LayerEditorGroup"; import PropertyGroup from "./PropertyGroup"; import { MdMoreVert } from "react-icons/md"; import layout from "../config/layout.json"; import { changeProperty, changeType } from "../libs/layer"; import { formatLayerId } from "../util/format"; function getLayoutForType(type) { return layout[type] ? layout[type] : layout.invalid; } function layoutGroups(layerType) { const layerGroup = { title: "Layer", type: "layer", }; const filterGroup = { title: "Filter", type: "filter", }; const editorGroup = { title: "JSON Editor", type: "jsoneditor", }; return [layerGroup, filterGroup] .concat(getLayoutForType(layerType).groups) .concat([editorGroup]); } /** Layer editor supporting multiple types of layers. */ export default class LayerEditor extends React.Component { static propTypes = { layer: PropTypes.object.isRequired, sources: PropTypes.object, vectorLayers: PropTypes.object, spec: PropTypes.object.isRequired, onLayerChanged: PropTypes.func, onLayerIdChange: PropTypes.func, onMoveLayer: PropTypes.func, onLayerDestroy: PropTypes.func, onLayerCopy: PropTypes.func, onLayerVisibilityToggle: PropTypes.func, isFirstLayer: PropTypes.bool, isLastLayer: PropTypes.bool, layerIndex: PropTypes.number, errors: PropTypes.array, }; static defaultProps = { onLayerChanged: () => {}, onLayerIdChange: () => {}, onLayerDestroyed: () => {}, }; static childContextTypes = { reactIconBase: PropTypes.object, }; constructor(props) { super(props); //TODO: Clean this up and refactor into function const editorGroups = {}; layoutGroups(this.props.layer.type).forEach((group) => { editorGroups[group.title] = true; }); this.state = { editorGroups }; } static getDerivedStateFromProps(props, state) { const additionalGroups = { ...state.editorGroups }; getLayoutForType(props.layer.type).groups.forEach((group) => { if (!(group.title in additionalGroups)) { additionalGroups[group.title] = true; } }); return { editorGroups: additionalGroups, }; } getChildContext() { return { reactIconBase: { size: 14, color: "#8e8e8e", }, }; } changeProperty(group, property, newValue) { this.props.onLayerChanged( this.props.layerIndex, changeProperty(this.props.layer, group, property, newValue) ); } onGroupToggle(groupTitle, active) { const changedActiveGroups = { ...this.state.editorGroups, [groupTitle]: active, }; this.setState({ editorGroups: changedActiveGroups, }); } renderGroupType(type, fields) { let comment = ""; if (this.props.layer.metadata) { comment = this.props.layer.metadata["maputnik:comment"]; } const { errors, layerIndex } = this.props; const errorData = {}; errors.forEach((error) => { if ( error.parsed && error.parsed.type === "layer" && error.parsed.data.index == layerIndex ) { errorData[error.parsed.data.key] = { message: error.parsed.data.message, }; } }); let sourceLayerIds; if (this.props.sources.hasOwnProperty(this.props.layer.source)) { sourceLayerIds = this.props.sources[this.props.layer.source].layers; } switch (type) { case "layer": return (