Skip to content

Commit f90963c

Browse files
committed
[maps] fix drawing shapes
1 parent 23adb25 commit f90963c

File tree

4 files changed

+44
-32
lines changed

4 files changed

+44
-32
lines changed

x-pack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
"@kbn/interpreter": "1.0.0",
218218
"@kbn/ui-framework": "1.0.0",
219219
"@mapbox/geojson-rewind": "^0.4.1",
220-
"@mapbox/mapbox-gl-draw": "^1.1.2",
220+
"@mapbox/mapbox-gl-draw": "^1.2.0",
221221
"@mapbox/mapbox-gl-rtl-text": "^0.2.3",
222222
"@scant/router": "^0.1.0",
223223
"@slack/webhook": "^5.0.0",
@@ -397,4 +397,4 @@
397397
"cypress-multi-reporters"
398398
]
399399
}
400-
}
400+
}

x-pack/plugins/maps/public/connected_components/map/mb/draw_control/draw_control.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ import {
1818
} from '../../../../elasticsearch_geo_utils';
1919
import { DrawTooltip } from './draw_tooltip';
2020

21+
const DRAW_RECTANGLE = 'draw_rectangle';
22+
const DRAW_CIRCLE = 'draw_circle';
23+
2124
const mbDrawModes = MapboxDraw.modes;
22-
mbDrawModes.draw_rectangle = DrawRectangle;
23-
mbDrawModes.draw_circle = DrawCircle;
25+
mbDrawModes[DRAW_RECTANGLE] = DrawRectangle;
26+
mbDrawModes[DRAW_CIRCLE] = DrawCircle;
2427

2528
export class DrawControl extends React.Component {
2629
constructor() {
@@ -45,8 +48,10 @@ export class DrawControl extends React.Component {
4548
this._removeDrawControl();
4649
}
4750

51+
// debounce with zero timeout needed to allow mapbox-draw finish logic to complete
52+
// before _removeDrawControl is called
4853
_syncDrawControl = _.debounce(() => {
49-
if (!this.props.mbMap) {
54+
if (!this._isMounted) {
5055
return;
5156
}
5257

@@ -55,7 +60,7 @@ export class DrawControl extends React.Component {
5560
} else {
5661
this._removeDrawControl();
5762
}
58-
}, 256);
63+
}, 0);
5964

6065
_onDraw = (e) => {
6166
if (!e.features.length) {
@@ -118,7 +123,7 @@ export class DrawControl extends React.Component {
118123
};
119124

120125
_removeDrawControl() {
121-
if (!this._mbDrawControlAdded) {
126+
if (!this.props.mbMap || !this._mbDrawControlAdded) {
122127
return;
123128
}
124129

@@ -129,18 +134,26 @@ export class DrawControl extends React.Component {
129134
}
130135

131136
_updateDrawControl() {
137+
if (!this.props.mbMap) {
138+
return;
139+
}
140+
132141
if (!this._mbDrawControlAdded) {
133142
this.props.mbMap.addControl(this._mbDrawControl);
134143
this._mbDrawControlAdded = true;
135144
this.props.mbMap.getCanvas().style.cursor = 'crosshair';
136145
this.props.mbMap.on('draw.create', this._onDraw);
137146
}
138147

139-
if (this.props.drawState.drawType === DRAW_TYPE.BOUNDS) {
140-
this._mbDrawControl.changeMode('draw_rectangle');
141-
} else if (this.props.drawState.drawType === DRAW_TYPE.DISTANCE) {
142-
this._mbDrawControl.changeMode('draw_circle');
143-
} else if (this.props.drawState.drawType === DRAW_TYPE.POLYGON) {
148+
const drawMode = this._mbDrawControl.getMode();
149+
if (drawMode !== DRAW_RECTANGLE && this.props.drawState.drawType === DRAW_TYPE.BOUNDS) {
150+
this._mbDrawControl.changeMode(DRAW_RECTANGLE);
151+
} else if (drawMode !== DRAW_CIRCLE && this.props.drawState.drawType === DRAW_TYPE.DISTANCE) {
152+
this._mbDrawControl.changeMode(DRAW_CIRCLE);
153+
} else if (
154+
drawMode !== this._mbDrawControl.modes.DRAW_POLYGON &&
155+
this.props.drawState.drawType === DRAW_TYPE.POLYGON
156+
) {
144157
this._mbDrawControl.changeMode(this._mbDrawControl.modes.DRAW_POLYGON);
145158
}
146159
}

x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -356,22 +356,20 @@ export class MapsAppView extends React.Component {
356356
);
357357
}
358358

359-
render() {
360-
const { filters, isFullScreen } = this.props;
359+
_addFilter = (newFilters) => {
360+
newFilters.forEach((filter) => {
361+
filter.$state = { store: esFilters.FilterStateStore.APP_STATE };
362+
});
363+
this._onFiltersChange([...this.props.filters, ...newFilters]);
364+
};
361365

366+
render() {
362367
return this.state.initialized ? (
363-
<div id="maps-plugin" className={isFullScreen ? 'mapFullScreen' : ''}>
368+
<div id="maps-plugin" className={this.props.isFullScreen ? 'mapFullScreen' : ''}>
364369
{this._renderTopNav()}
365370
<h1 className="euiScreenReaderOnly">{`screenTitle placeholder`}</h1>
366371
<div id="react-maps-root">
367-
<MapContainer
368-
addFilters={(newFilters) => {
369-
newFilters.forEach((filter) => {
370-
filter.$state = { store: esFilters.FilterStateStore.APP_STATE };
371-
});
372-
this._onFiltersChange([...filters, ...newFilters]);
373-
}}
374-
/>
372+
<MapContainer addFilters={this._addFilter} />
375373
</div>
376374
</div>
377375
) : null;

yarn.lock

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,10 +3026,10 @@
30263026
resolved "https://registry.yarnpkg.com/@mapbox/geojson-types/-/geojson-types-1.0.2.tgz#9aecf642cb00eab1080a57c4f949a65b4a5846d6"
30273027
integrity sha512-e9EBqHHv3EORHrSfbR9DqecPNn+AmuAoQxV6aL8Xu30bJMJR1o8PZLZzpk1Wq7/NfCbuhmakHTPYRhoqLsXRnw==
30283028

3029-
"@mapbox/geojsonhint@^2.0.0":
3030-
version "2.2.0"
3031-
resolved "https://registry.yarnpkg.com/@mapbox/geojsonhint/-/geojsonhint-2.2.0.tgz#75ca94706e9a56e6debf4e1c78fabdc67978b883"
3032-
integrity sha512-8qQYRB+/2z2JsN5s6D0WAnpo69+3V3nvJsSFLwMB1dsaWz1V4oZeuoje9srbYAxxL8PXCwIywfhYa3GxOkBv5Q==
3029+
"@mapbox/geojsonhint@3.0.0":
3030+
version "3.0.0"
3031+
resolved "https://registry.yarnpkg.com/@mapbox/geojsonhint/-/geojsonhint-3.0.0.tgz#42448232ce4236cb89c1b69c36b0cadeac99e02e"
3032+
integrity sha512-zHcyh1rDHYnEBd6NvOWoeHLuvazlDkIjvz9MJx4cKwcKTlfrqgxVnTv1QLnVJnsSU5neJnhQJcgscR/Zl4uYgw==
30333033
dependencies:
30343034
concat-stream "^1.6.1"
30353035
jsonlint-lines "1.7.1"
@@ -3042,16 +3042,17 @@
30423042
resolved "https://registry.yarnpkg.com/@mapbox/jsonlint-lines-primitives/-/jsonlint-lines-primitives-2.0.2.tgz#ce56e539f83552b58d10d672ea4d6fc9adc7b234"
30433043
integrity sha1-zlblOfg1UrWNENZy6k1vya3HsjQ=
30443044

3045-
"@mapbox/mapbox-gl-draw@^1.1.2":
3046-
version "1.1.2"
3047-
resolved "https://registry.yarnpkg.com/@mapbox/mapbox-gl-draw/-/mapbox-gl-draw-1.1.2.tgz#247b3f0727db34c2641ab718df5eebeee69a2585"
3048-
integrity sha512-DWtATUAnJaGZYoH/y2O+QTRybxrp5y3w3eV5FXHFNVcKsCAojKEMB8ALKUG2IsiCKqV/JCAguK9AlPWR7Bjafw==
3045+
"@mapbox/mapbox-gl-draw@^1.2.0":
3046+
version "1.2.0"
3047+
resolved "https://registry.yarnpkg.com/@mapbox/mapbox-gl-draw/-/mapbox-gl-draw-1.2.0.tgz#b6e5278afef65bd5d7d92366034997768e478ad9"
3048+
integrity sha512-gMrP2zn8PzDtrs72FMJTPytCumX5vUn9R7IK38qBOVy9UfqbdWr56KYuNA/2X+jKn4FIOpmWf8CWkKpOaQkv7w==
30493049
dependencies:
30503050
"@mapbox/geojson-area" "^0.2.1"
30513051
"@mapbox/geojson-extent" "^0.3.2"
30523052
"@mapbox/geojson-normalize" "0.0.1"
3053-
"@mapbox/geojsonhint" "^2.0.0"
3053+
"@mapbox/geojsonhint" "3.0.0"
30543054
"@mapbox/point-geometry" "0.1.0"
3055+
eslint-plugin-import "^2.19.1"
30553056
hat "0.0.3"
30563057
lodash.isequal "^4.2.0"
30573058
xtend "^4.0.1"

0 commit comments

Comments
 (0)