mapbox / mapbox/mapbox-gl-draw
Expose APIs for writing custom drawing modes
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 612
- Avg merge
- 8d 9h
- Merged PRs (30d)
- 5
Description
**mapbox-gl-js version**: n/a
**mapbox-gl-draw version**: latest
Currently when writing a custom drawing mode for `@mapbox/mapbox-draw-gl` a whole heap of internal modules are required to be imported, for instance: https://github.com/bemky/mapbox-gl-draw-freehand-mode/blob/master/src/index.js#L1-L3
```typescript
import DrawPolygon from '@mapbox/mapbox-gl-draw/src/modes/draw_polygon';
import {geojsonTypes, cursors, types, updateActions, modes, events} from '@mapbox/mapbox-gl-draw/src/constants';
import doubleClickZoom from '@mapbox/mapbox-gl-draw/src/lib/double_click_zoom';
```
This is further a problem for people using typescript, where you need to declare each of the internal modules that your drawing mode uses:
```
declare module '@mapbox/mapbox-gl-draw';
declare module '@mapbox/mapbox-gl-draw/src/lib/theme';
declare module '@mapbox/mapbox-gl-draw/src/constants';
declare module '@mapbox/mapbox-gl-draw-static-mode';
declare module '@mapbox/mapbox-gl-draw/src/lib/create_supplementary_points';
declare module '@mapbox/mapbox-gl-draw/src/lib/common_selectors';
declare module '@mapbox/mapbox-gl-draw/src/modes/draw_polygon';
declare module '@mapbox/mapbox-gl-draw/src/lib/is_event_at_coordinates';
declare module '@mapbox/mapbox-gl-draw/src/modes/direct_select';
declare module '@mapbox/mapbox-gl-draw/src/lib/double_click_zoom';
```
(the above are what we required for the custom drawing modes that we have in the [Yara AtFarm+](https://at.farm/) application)
I think the solution would be to have `/index.js` re-export all of those modules as a public API, rather than having them as internal modules.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the package's index.js and compare its current exports with the internal modules used by the linked custom freehand mode example, including src/constants, src/lib/double_click_zoom, and src/modes/draw_polygon. Review how custom modes import these modules and define a public export surface; the work is done when supported APIs no longer require those internal paths and TypeScript consumers can use them without individual module declarations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- api, developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100