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

Add hotSourceOptions and coldSourceOptions #1218

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ All of the following options are optional.
- `modes`, Object: over ride the default modes with your own. `MapboxDraw.modes` can be used to see the default values. More information on custom modes [can be found here](https://github.com/mapbox/mapbox-gl-draw/blob/main/docs/MODES.md).
- `defaultMode`, String (default: `'simple_select'`): the mode (from `modes`) that user will first land in.
- `userProperties`, boolean (default: `false`): properties of a feature will also be available for styling and prefixed with `user_`, e.g., `['==', 'user_custom_label', 'Example']`
- `hotSourceOptions`, Object (default {}): same as [GeoJSONSource](https://docs.mapbox.com/style-spec/reference/sources#geojson) in mapbox,can control hot features style.
- `coldSourceOptions`, Object (default {}): same as [GeoJSONSource](https://docs.mapbox.com/style-spec/reference/sources#geojson) in mapbox,can control drawn features style.

## Modes

Expand Down
4 changes: 3 additions & 1 deletion src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const defaultOptions = {
styles,
modes,
controls: {},
userProperties: false
userProperties: false,
coldSourceOptions: {},
hotSourceOptions: {}
};

const showControls = {
Expand Down
2 changes: 2 additions & 0 deletions src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default function(ctx) {
addLayers() {
// drawn features style
ctx.map.addSource(Constants.sources.COLD, {
...ctx.options.coldSourceOptions,
data: {
type: Constants.geojsonTypes.FEATURE_COLLECTION,
features: []
Expand All @@ -94,6 +95,7 @@ export default function(ctx) {

// hot features style
ctx.map.addSource(Constants.sources.HOT, {
...ctx.options.hotSourceOptions,
data: {
type: Constants.geojsonTypes.FEATURE_COLLECTION,
features: []
Expand Down
24 changes: 18 additions & 6 deletions test/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ test('Options test', (t) => {
trash: true,
combine_features: true,
uncombine_features: true
}
},
coldSourceOptions: {},
hotSourceOptions: {}
};
t.deepEquals(defaultOptions, Draw.options);
t.deepEquals(styleWithSourcesFixture, Draw.options.styles);
Expand All @@ -52,7 +54,9 @@ test('Options test', (t) => {
trash: true,
combine_features: true,
uncombine_features: true
}
},
coldSourceOptions: {},
hotSourceOptions: {}
};

t.deepEquals(defaultOptions, Draw.options);
Expand All @@ -79,7 +83,9 @@ test('Options test', (t) => {
trash: false,
combine_features: false,
uncombine_features: false
}
},
coldSourceOptions: {},
hotSourceOptions: {}
};
t.deepEquals(defaultOptions, Draw.options);
t.end();
Expand All @@ -105,7 +111,9 @@ test('Options test', (t) => {
trash: false,
combine_features: false,
uncombine_features: false
}
},
coldSourceOptions: {},
hotSourceOptions: {}
};

t.deepEquals(defaultOptions, Draw.options);
Expand All @@ -132,7 +140,9 @@ test('Options test', (t) => {
trash: true,
combine_features: true,
uncombine_features: true
}
},
coldSourceOptions: {},
hotSourceOptions: {}
};

t.deepEquals(defaultOptions, Draw.options);
Expand All @@ -159,7 +169,9 @@ test('Options test', (t) => {
trash: true,
combine_features: true,
uncombine_features: true
}
},
coldSourceOptions: {},
hotSourceOptions: {}
};
t.deepEquals(defaultOptions, Draw.options);
t.deepEquals(styleWithSourcesFixture, Draw.options.styles);
Expand Down