Skip to content

Commit a41eb5f

Browse files
Add hotSourceOptions and coldSourceOptions
Add hotSourceOptions and coldSourceOptions to the options to pass to the drawing and drawn layers. This could fix issue [#858](#858) and [#1143](#1143).
1 parent cf51a60 commit a41eb5f

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

docs/API.md

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ All of the following options are optional.
3636
- `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).
3737
- `defaultMode`, String (default: `'simple_select'`): the mode (from `modes`) that user will first land in.
3838
- `userProperties`, boolean (default: `false`): properties of a feature will also be available for styling and prefixed with `user_`, e.g., `['==', 'user_custom_label', 'Example']`
39+
- `hotSourceOptions`, Object (default {}): same as [GeoJSONSource](https://docs.mapbox.com/style-spec/reference/sources#geojson) in mapbox,can control hot features style.
40+
- `coldSourceOptions`, Object (default {}): same as [GeoJSONSource](https://docs.mapbox.com/style-spec/reference/sources#geojson) in mapbox,can control drawn features style.
3941

4042
## Modes
4143

src/options.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ const defaultOptions = {
1515
styles,
1616
modes,
1717
controls: {},
18-
userProperties: false
18+
userProperties: false,
19+
coldSourceOptions: {},
20+
hotSourceOptions: {}
1921
};
2022

2123
const showControls = {

src/setup.js

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export default function(ctx) {
8585
addLayers() {
8686
// drawn features style
8787
ctx.map.addSource(Constants.sources.COLD, {
88+
...ctx.options.coldSourceOptions,
8889
data: {
8990
type: Constants.geojsonTypes.FEATURE_COLLECTION,
9091
features: []
@@ -94,6 +95,7 @@ export default function(ctx) {
9495

9596
// hot features style
9697
ctx.map.addSource(Constants.sources.HOT, {
98+
...ctx.options.hotSourceOptions,
9799
data: {
98100
type: Constants.geojsonTypes.FEATURE_COLLECTION,
99101
features: []

test/options.test.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ test('Options test', (t) => {
2525
trash: true,
2626
combine_features: true,
2727
uncombine_features: true
28-
}
28+
},
29+
coldSourceOptions: {},
30+
hotSourceOptions: {}
2931
};
3032
t.deepEquals(defaultOptions, Draw.options);
3133
t.deepEquals(styleWithSourcesFixture, Draw.options.styles);
@@ -52,7 +54,9 @@ test('Options test', (t) => {
5254
trash: true,
5355
combine_features: true,
5456
uncombine_features: true
55-
}
57+
},
58+
coldSourceOptions: {},
59+
hotSourceOptions: {}
5660
};
5761

5862
t.deepEquals(defaultOptions, Draw.options);
@@ -79,7 +83,9 @@ test('Options test', (t) => {
7983
trash: false,
8084
combine_features: false,
8185
uncombine_features: false
82-
}
86+
},
87+
coldSourceOptions: {},
88+
hotSourceOptions: {}
8389
};
8490
t.deepEquals(defaultOptions, Draw.options);
8591
t.end();
@@ -105,7 +111,9 @@ test('Options test', (t) => {
105111
trash: false,
106112
combine_features: false,
107113
uncombine_features: false
108-
}
114+
},
115+
coldSourceOptions: {},
116+
hotSourceOptions: {}
109117
};
110118

111119
t.deepEquals(defaultOptions, Draw.options);
@@ -132,7 +140,9 @@ test('Options test', (t) => {
132140
trash: true,
133141
combine_features: true,
134142
uncombine_features: true
135-
}
143+
},
144+
coldSourceOptions: {},
145+
hotSourceOptions: {}
136146
};
137147

138148
t.deepEquals(defaultOptions, Draw.options);
@@ -159,7 +169,9 @@ test('Options test', (t) => {
159169
trash: true,
160170
combine_features: true,
161171
uncombine_features: true
162-
}
172+
},
173+
coldSourceOptions: {},
174+
hotSourceOptions: {}
163175
};
164176
t.deepEquals(defaultOptions, Draw.options);
165177
t.deepEquals(styleWithSourcesFixture, Draw.options.styles);

0 commit comments

Comments
 (0)