-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add mapbox-gl draw mode if tooltip state is draw , mount mapbox-gl-draw and change mode accordingly. Signed-off-by: Vijayan Balasubramanian <balasvij@amazon.com>
- Loading branch information
Showing
5 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
public/components/toolbar/spatial_filter/draw_filter_shape.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { Fragment, useEffect, useRef } from 'react'; | ||
import { IControl, Map as Maplibre } from 'maplibre-gl'; | ||
import MapboxDraw from '@mapbox/mapbox-gl-draw'; | ||
import { Feature } from 'geojson'; | ||
import { | ||
DrawFilterProperties, | ||
FILTER_DRAW_MODE, | ||
MAPBOX_GL_DRAW_MODES, | ||
MAPBOX_GL_DRAW_CREATE_LISTENER, | ||
} from '../../../../common'; | ||
|
||
interface DrawFilterShapeProps { | ||
filterProperties: DrawFilterProperties; | ||
map: Maplibre; | ||
updateFilterProperties: (properties: DrawFilterProperties) => void; | ||
} | ||
|
||
export const DrawFilterShape = ({ | ||
filterProperties, | ||
map, | ||
updateFilterProperties, | ||
}: DrawFilterShapeProps) => { | ||
const onDraw = (event: { features: Feature[] }) => { | ||
updateFilterProperties({ | ||
mode: FILTER_DRAW_MODE.NONE, | ||
}); | ||
}; | ||
const mapboxDrawRef = useRef<MapboxDraw>( | ||
new MapboxDraw({ | ||
displayControlsDefault: false, | ||
}) | ||
); | ||
|
||
useEffect(() => { | ||
if (map) { | ||
map.addControl((mapboxDrawRef.current as unknown) as IControl, 'top-right'); | ||
map.on(MAPBOX_GL_DRAW_CREATE_LISTENER, onDraw); | ||
} | ||
return () => { | ||
if (map) { | ||
map.off(MAPBOX_GL_DRAW_CREATE_LISTENER, onDraw); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
map.removeControl((mapboxDrawRef.current as unknown) as IControl); | ||
} | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (filterProperties.mode === FILTER_DRAW_MODE.POLYGON) { | ||
mapboxDrawRef.current.changeMode(MAPBOX_GL_DRAW_MODES.DRAW_POLYGON); | ||
} else { | ||
// default mode | ||
mapboxDrawRef.current.changeMode(MAPBOX_GL_DRAW_MODES.SIMPLE_SELECT); | ||
} | ||
}, [filterProperties.mode]); | ||
|
||
return <Fragment />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters