diff --git a/src/components/ControlMap.js b/src/components/ControlMap.js index a724253..22ca881 100644 --- a/src/components/ControlMap.js +++ b/src/components/ControlMap.js @@ -19,93 +19,84 @@ export type ControlMapProps = { onChangeControl: (control: Control) => void }; -export default class ControlMap extends React.PureComponent { - constructor(props: ControlMapProps) { - super(props); - } +const center = (props: ControlMapProps): Point => + convertPoint([ + props.width / 2, + props.height / 2 + ]); - get center(): Point { - return convertPoint([ - this.props.width / 2, - this.props.height / 2 - ]); +const iconColor = (control: Control, state: State): string => { + if (control.iconColor != null) { + return control.iconColor(state); } + return "#000"; +}; - render() { - return ( - - {this.renderMarkers()} - {this.renderLayers()} - - ); - } +const createLeafletIcon = (control: Control, state: State) => { + const icon = control.icon(state); + const iconClass = `${icon} mdi-36px`; + return divIcon({ + iconSize: point(36, 36), + iconAnchor: point(18, 18), + html: `` + }); +}; - renderMarkers() { - return map(this.props.controls, this.renderMarker.bind(this)); - } +const renderMarker = (props: ControlMapProps) => + (control: Control, key: string) => ( + + {({ state }) => ( + props.onChangeControl(control)} + > + + )} + + ); - createLeafletIcon(control: Control, state: State) { - const icon = control.icon(state); - const iconClass = `${icon} mdi-36px`; - return divIcon({ - iconSize: point(36, 36), - iconAnchor: point(18, 18), - html: `` - }); - } +const renderMarkers = (props: ControlMapProps) => + map(props.controls, renderMarker(props)); - iconColor(control: Control, state: State): string { - if (control.iconColor != null) { - return control.iconColor(state); - } - return "#000"; - } +const renderLayer = (layer: Layer) => { + const LayersControlType = + layer.baseLayer ? LayersControl.BaseLayer : LayersControl.Overlay; + return ( + {}} // eslint-disable-line fp/no-nil + removeLayerControl={(_layer) => {}} // eslint-disable-line fp/no-nil + // eslint-disable-next-line fp/no-nil + addOverlay={(_layer, _name, _checked) => {}} + // eslint-disable-next-line fp/no-nil + addBaseLayer={(_layer, _name, _checked) => {}}> + + + ); +}; - renderMarker(control: Control, key: string) { - return ( - - {({ state }) => ( - this.props.onChangeControl(control)} - > - - )} - - ); - } +const renderLayers = (props: ControlMapProps) => ( + + {props.layers.map(renderLayer)} + +); - renderLayers() { - return ( - - {this.props.layers.map(this.renderLayer)} - - ); - } +const ControlMap = (props: ControlMapProps) => ( + + {renderMarkers(props)} + {renderLayers(props)} + +); - renderLayer(layer: Layer) { - const LayersControlType = - layer.baseLayer ? LayersControl.BaseLayer : LayersControl.Overlay; - return ( - {}} - removeLayerControl={(_layer) => {}} - addOverlay={(_layer, _name, _checked) => {}} - addBaseLayer={(_layer, _name, _checked) => {}}> - - - ); - } -} +export default ControlMap;