Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose APIs for writing custom drawing modes #1056

Open
ThisIsMissEm opened this issue May 27, 2021 · 1 comment
Open

Expose APIs for writing custom drawing modes #1056

ThisIsMissEm opened this issue May 27, 2021 · 1 comment
Labels
api API & programatically working with library

Comments

@ThisIsMissEm
Copy link

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

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+ 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.

@ThisIsMissEm
Copy link
Author

Admittedly we can already access both @mapbox/mapbox-gl-draw/src/modes/draw_polygon and @mapbox/mapbox-gl-draw/src/modes/direct_select via:

import MapboxDraw from '@mapbox/mapbox-gl-draw';

const DrawPolygon = MapboxDraw.modes.draw_polygon;

If I'm understanding the code correctly.

@avpeery avpeery added the api API & programatically working with library label Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api API & programatically working with library
Projects
None yet
Development

No branches or pull requests

2 participants