Skip to content

Commit

Permalink
Update polygon style
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Macri <[email protected]>
  • Loading branch information
macrigiuseppe committed Jul 8, 2019
1 parent 2cd8868 commit 9a5d7fd
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/components/common/toolbar-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const StyledDiv = styled.div`
const ToolbarItem = React.memo(({active, className, icon, label, onClick}) => (
<StyledDiv active={active} className="save-export-dropdown__item" onClick={(e) => {
e.stopPropagation();
onClick();
e.preventDefault();
onClick(e);
}}>
{icon}
<div className="save-export-dropdown__title">{label}</div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/draw/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const RENDER_TYPE = {

export const COLORS = {
PRIMARY: '#26B5F2',
SECONDARY: '#ffff00'
SECONDARY: '#ffff00',
TERTIARY: '#6c6c6c'
};

8 changes: 4 additions & 4 deletions src/components/draw/feature-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ export const DEFAULT_RADIUS = 4;
export const DEFAULT_STATE_STYLE_STROKE = COLORS.PRIMARY;

export const STATE_STYLES_STROKE = {
[RenderStates.INACTIVE]: DEFAULT_STATE_STYLE_STROKE,
[RenderStates.UNCOMMITTED]: COLORS.PRIMARY,
[RenderStates.INACTIVE]: COLORS.PRIMARY,
[RenderStates.UNCOMMITTED]: COLORS.TERTIARY,
[RenderStates.SELECTED]: COLORS.PRIMARY,
[RenderStates.HOVERED]: COLORS.PRIMARY
};

export const DEFAULT_STATE_STYLE_FILL = '#000';

export const STATE_STYLES_FILL = {
[RenderStates.INACTIVE]: COLORS.PRIMARY,
[RenderStates.INACTIVE]: COLORS.TERTIARY,
[RenderStates.UNCOMMITTED]: COLORS.PRIMARY,
[RenderStates.SELECTED]: COLORS.SECONDARY,
[RenderStates.SELECTED]: COLORS.PRIMARY,
[RenderStates.HOVERED]: COLORS.PRIMARY
};

Expand Down
25 changes: 18 additions & 7 deletions src/components/draw/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import {Editor} from 'react-map-gl-draw';
import window from 'global/window';

Expand All @@ -34,6 +35,7 @@ import {
const DEFAULT_EDIT_HANDLE_SHAPE = 'circle';

const DELETE_KEY_EVENT_CODE = 8;
const ESCAPE_KEY_EVENT_CODE = 27;

class Draw extends Component {
static propTypes = {
Expand All @@ -49,6 +51,10 @@ class Draw extends Component {
clickRadius: DEFAULT_RADIUS
};

state = {
showActions: false
};

componentDidMount() {
window.addEventListener('keydown', this._onKeyPressed);
}
Expand All @@ -65,34 +71,39 @@ class Draw extends Component {
return;
}

if (
event.which === DELETE_KEY_EVENT_CODE &&
selectedFeature
) {
this.props.onDeleteFeature((selectedFeature || {}).id)
switch (event.which) {
case DELETE_KEY_EVENT_CODE:
this.props.onDeleteFeature((selectedFeature || {}).id);
break;
default: break;
}
};

_getEditHandleShape = () => {
return DEFAULT_EDIT_HANDLE_SHAPE;
};

_onSelect = feature => {
this.props.onSelect(feature);
};

render() {
const {clickRadius, editor, features} = this.props;
const {selectedFeature = {}} = editor;

return (
<div>
<div className="editor">
<Editor
clickRadius={clickRadius}
mode={editor.mode}
features={features}
selectedFeatureId={(selectedFeature || {}).id}
onSelect={this.props.onSelect}
onSelect={this._onSelect}
onUpdate={this.props.onUpdate}
getEditHandleShape={this._getEditHandleShape}
getFeatureStyle={getFeatureStyle}
getEditHandleStyle={getEditHandleStyle}
style={{zIndex: 1}}
/>
</div>
);
Expand Down
19 changes: 10 additions & 9 deletions src/components/map-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ MapContainerFactory.deps = [
export default function MapContainerFactory(MapPopover, MapControl) {
/* eslint-disable complexity */
const MapTooltip = React.memo(({
mapState,
hoverInfo,
clicked,
datasets,
interactionConfig,
layers,
mapLayers,
mousePos: {mousePosition, coordinate, pinned}
}) => {
mapState,
hoverInfo,
clicked,
datasets,
interactionConfig,
layers,
mapLayers,
mousePos: {mousePosition, coordinate, pinned}
}) => {
if (!mousePosition) {
return null;
}
Expand Down Expand Up @@ -460,6 +460,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {
<Editor
editor={uiState.editor}
features={visState.editor.features}
isEnabled={isEdit}
onDeleteFeature={uiStateActions.deleteFeature}
onSelect={uiStateActions.setSelectedFeature}
onUpdate={visStateActions.setFeatures}
Expand Down
12 changes: 3 additions & 9 deletions src/components/map/map-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,25 +313,19 @@ const MapDrawPanel = React.memo(({editor, isActive, onToggleMenuPanel, onSetEdit
{isActive ? (
<StyledToolBar show={isActive} direction="column">
<ToolbarItem
onClick={() => {
onSetEditorMode(EDITOR_MODES.EDIT_VERTEX);
}}
onClick={() => onSetEditorMode(EDITOR_MODES.EDIT_VERTEX)}
label="select"
icon={(<CursorClick height="22px"/>)}
active={editor.mode === EDITOR_MODES.EDIT_VERTEX}
/>
<ToolbarItem
onClick={() => {
onSetEditorMode(EDITOR_MODES.DRAW_POLYGON);
}}
onClick={() => onSetEditorMode(EDITOR_MODES.DRAW_POLYGON)}
label="polygon"
icon={(<Polygon height="22px"/>)}
active={editor.mode === EDITOR_MODES.DRAW_POLYGON}
/>
<ToolbarItem
onClick={() => {
onSetEditorMode(EDITOR_MODES.DRAW_RECTANGLE);
}}
onClick={() => onSetEditorMode(EDITOR_MODES.DRAW_RECTANGLE)}
label="rectangle"
icon={(<Rectangle height="22px"/>)}
active={editor.mode === EDITOR_MODES.DRAW_RECTANGLE}
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/vis-state-updaters.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const visStateUpdaters = null;
* @property {boolean} fileLoading
* @property {*} fileLoadingErr
* @property {Array} splitMaps - a list of objects of layer availabilities and visibilities for each map
* @property {Object} editor
* @public
*/
export const INITIAL_VIS_STATE = {
Expand Down Expand Up @@ -945,7 +946,6 @@ export const mapClickUpdater = (state) => {
};

export const mouseMoveUpdater = (state, {evt}) => {

if (Object.values(state.interactionConfig).some(config => config.enabled)) {
return {
...state,
Expand Down

0 comments on commit 9a5d7fd

Please sign in to comment.