Skip to content

Commit 9cc9e36

Browse files
lesbaaLes Moffat
andauthored
RD-881 re-add deprecation warning (#53)
* RD-881 Add deprecation warning for older styles. * 2.3.2 * RD-881 Fix double call of getDefaultVariant and add cleaner solution for deprecation warning * RD-811 Add warnIfDepreacted call to getVariants * RD-881 Update Changelog --------- Co-authored-by: Les Moffat <les.moffat@maptiler.com>
1 parent b4ea3ad commit 9cc9e36

File tree

4 files changed

+54
-8
lines changed

4 files changed

+54
-8
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# MapTiler Client Changelog
22

3+
## 2.3.2
4+
### New Features
5+
None
6+
7+
### Bug Fixes
8+
None
9+
10+
### Others
11+
Added deprecation warning and field for styles that will be deprecated in the future.
12+
313
## 2.3.1
414
### New Features
515
None

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@maptiler/client",
3-
"version": "2.3.1",
3+
"version": "2.3.2",
44
"description": "Javascript & Typescript wrapper to MapTiler Cloud API",
55
"module": "dist/maptiler-client.mjs",
66
"types": "dist/maptiler-client.d.ts",

src/mapstyle.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type MapStylePreset = {
3131
name: string;
3232
description: string;
3333
variants: Array<{
34+
deprecated?: boolean;
3435
id: string;
3536
name: string;
3637
variantType: string;
@@ -74,6 +75,10 @@ export class MapStyleVariant {
7475
*/
7576
private imageURL: string,
7677

78+
/**
79+
* Whether this variant is deprecated or not
80+
*/
81+
public deprecated: boolean = false,
7782
) {}
7883

7984
/**
@@ -136,15 +141,23 @@ export class MapStyleVariant {
136141
* @returns
137142
*/
138143
getVariant(variantType: string): MapStyleVariant {
139-
return this.referenceStyle.getVariant(variantType);
144+
const variant = this.referenceStyle.getVariant(variantType);
145+
this.warnIfDeprecated(variant);
146+
return variant;
140147
}
141148

142149
/**
143150
* Get all the variants for _this_ variants, except _this_ current one
144151
* @returns
145152
*/
146153
getVariants(): Array<MapStyleVariant> {
147-
return this.referenceStyle.getVariants().filter((v) => v !== this);
154+
return this.referenceStyle
155+
.getVariants()
156+
.filter((v) => v !== this)
157+
.map((v) => {
158+
this.warnIfDeprecated(v);
159+
return v;
160+
});
148161
}
149162

150163
/**
@@ -162,6 +175,18 @@ export class MapStyleVariant {
162175
getExpandedStyleURL(): string {
163176
return expandMapStyle(this.getId());
164177
}
178+
179+
warnIfDeprecated(variant: MapStyleVariant = this): MapStyleVariant {
180+
if (!variant.deprecated) return variant;
181+
182+
const name = variant.getFullName();
183+
184+
console.warn(
185+
`Style "${name}" is deprecated and will be removed in a future version.`,
186+
);
187+
188+
return variant;
189+
}
165190
}
166191

167192
/**
@@ -249,7 +274,7 @@ export class ReferenceMapStyle {
249274
* @returns
250275
*/
251276
getDefaultVariant(): MapStyleVariant {
252-
return this.orderedVariants[0];
277+
return this.orderedVariants[0].warnIfDeprecated();
253278
}
254279
}
255280

@@ -412,7 +437,7 @@ export type MapStyleType = {
412437
VOYAGER: ReferenceMapStyle & {
413438
/**
414439
* A nice alternative to `streets` with a soft color palette
415-
*
440+
*
416441
*/
417442
DEFAULT: MapStyleVariant;
418443
/**
@@ -644,6 +669,7 @@ export const mapStylePresetList: Array<MapStylePreset> = [
644669
variants: [
645670
{
646671
id: "hybrid",
672+
deprecated: true,
647673
name: "Default",
648674
variantType: "DEFAULT",
649675
description: "",
@@ -753,6 +779,7 @@ export const mapStylePresetList: Array<MapStylePreset> = [
753779
{
754780
id: "topo-v2-shiny",
755781
name: "Shiny",
782+
deprecated: true,
756783
variantType: "SHINY",
757784
description: "",
758785
imageURL: "",
@@ -782,27 +809,31 @@ export const mapStylePresetList: Array<MapStylePreset> = [
782809
{
783810
id: "voyager-v2",
784811
name: "Default",
812+
deprecated: true,
785813
variantType: "DEFAULT",
786814
description: "",
787815
imageURL: "",
788816
},
789817
{
790818
id: "voyager-v2-darkmatter",
791819
name: "Darkmatter",
820+
deprecated: true,
792821
variantType: "DARK",
793822
description: "",
794823
imageURL: "",
795824
},
796825
{
797826
id: "voyager-v2-positron",
798827
name: "Positron",
828+
deprecated: true,
799829
variantType: "LIGHT",
800830
description: "",
801831
imageURL: "",
802832
},
803833
{
804834
id: "voyager-v2-vintage",
805835
name: "Vintage",
836+
deprecated: true,
806837
variantType: "VINTAGE",
807838
description: "",
808839
imageURL: "",
@@ -826,6 +857,7 @@ export const mapStylePresetList: Array<MapStylePreset> = [
826857
id: "toner-v2-background",
827858
name: "Background",
828859
variantType: "BACKGROUND",
860+
deprecated: true,
829861
description: "",
830862
imageURL: "",
831863
},
@@ -840,6 +872,7 @@ export const mapStylePresetList: Array<MapStylePreset> = [
840872
id: "toner-v2-lines",
841873
name: "Lines",
842874
variantType: "LINES",
875+
deprecated: true,
843876
description: "",
844877
imageURL: "",
845878
},
@@ -990,7 +1023,9 @@ function makeReferenceStyleProxy(referenceStyle: ReferenceMapStyle) {
9901023
return referenceStyle.getDefaultVariant();
9911024
}
9921025

993-
return Reflect.get(target, prop, receiver);
1026+
const style = Reflect.get(target, prop, receiver);
1027+
1028+
return style;
9941029
},
9951030
});
9961031
}
@@ -1014,6 +1049,7 @@ function buildMapStyles(): MapStyleType {
10141049
refStyle, // referenceStyle
10151050
variantInfo.description,
10161051
variantInfo.imageURL, // imageURL
1052+
variantInfo.deprecated, // deprecated
10171053
);
10181054

10191055
refStyle.addVariant(variant);

0 commit comments

Comments
 (0)