Skip to content

Commit

Permalink
Add hotSourceOptions and coldSourceOptions
Browse files Browse the repository at this point in the history
Add hotSourceOptions and coldSourceOptions to the options to pass to the drawing and drawn layers.
This could fix issue [#858](#858) and [#1143](#1143).
  • Loading branch information
shushanyalida5124 committed Apr 21, 2024
1 parent cf51a60 commit a41eb5f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
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

0 comments on commit a41eb5f

Please sign in to comment.