@maptiler/sdk 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.eslintrc.cjs +15 -5
  2. package/.github/pull_request_template.md +11 -0
  3. package/.github/workflows/format-lint.yml +24 -0
  4. package/CHANGELOG.md +94 -51
  5. package/colorramp.md +93 -0
  6. package/dist/maptiler-sdk.d.ts +1207 -123
  7. package/dist/maptiler-sdk.min.mjs +3 -1
  8. package/dist/maptiler-sdk.mjs +3561 -485
  9. package/dist/maptiler-sdk.mjs.map +1 -1
  10. package/dist/maptiler-sdk.umd.js +3825 -869
  11. package/dist/maptiler-sdk.umd.js.map +1 -1
  12. package/dist/maptiler-sdk.umd.min.js +51 -49
  13. package/package.json +27 -13
  14. package/readme.md +298 -0
  15. package/rollup.config.js +2 -16
  16. package/src/Map.ts +489 -357
  17. package/src/MaptilerGeolocateControl.ts +23 -20
  18. package/src/MaptilerLogoControl.ts +3 -3
  19. package/src/MaptilerNavigationControl.ts +9 -6
  20. package/src/MaptilerTerrainControl.ts +15 -14
  21. package/src/Minimap.ts +373 -0
  22. package/src/Point.ts +3 -5
  23. package/src/colorramp.ts +1216 -0
  24. package/src/config.ts +4 -3
  25. package/src/converters/index.ts +1 -0
  26. package/src/converters/xml.ts +681 -0
  27. package/src/defaults.ts +1 -1
  28. package/src/helpers/index.ts +27 -0
  29. package/src/helpers/stylehelper.ts +395 -0
  30. package/src/helpers/vectorlayerhelpers.ts +1511 -0
  31. package/src/index.ts +10 -0
  32. package/src/language.ts +116 -79
  33. package/src/mapstyle.ts +4 -2
  34. package/src/tools.ts +68 -16
  35. package/tsconfig.json +8 -5
  36. package/vite.config.ts +10 -0
  37. package/demos/maptiler-sdk.css +0 -147
  38. package/demos/maptiler-sdk.umd.js +0 -4041
  39. package/demos/mountain.html +0 -67
  40. package/demos/simple.html +0 -67
  41. package/demos/transform-request.html +0 -81
package/.eslintrc.cjs CHANGED
@@ -1,10 +1,20 @@
1
+ const tsConfig = require('./tsconfig.json');
2
+
1
3
  module.exports = {
2
- extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
4
+ extends: [
5
+ 'eslint:recommended',
6
+ 'plugin:@typescript-eslint/recommended',
7
+ 'prettier'
8
+ ],
3
9
  parser: '@typescript-eslint/parser',
4
- plugins: ['@typescript-eslint'],
10
+ plugins: [
11
+ '@typescript-eslint',
12
+ 'prettier'
13
+ ],
5
14
  root: true,
6
- //"@typescript-eslint/ban-ts-comment": "warn"
7
15
  rules: {
8
16
  "@typescript-eslint/ban-ts-comment": "warn",
9
- }
10
- };
17
+ "prettier/prettier": "error",
18
+ },
19
+ ignorePatterns: tsConfig.exclude,
20
+ };
@@ -0,0 +1,11 @@
1
+ ## Objective
2
+ What is the goal?
3
+
4
+ ## Description
5
+ What changed, how and why?
6
+
7
+ ## Acceptance
8
+ How were changes tested?
9
+
10
+ ## Checklist
11
+ - [ ] I have added relevant info to the CHANGELOG.md
@@ -0,0 +1,24 @@
1
+ name: Format and Lint
2
+
3
+ on: [pull_request]
4
+
5
+ jobs:
6
+ format-and-lint:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - name: Check out Git repository
10
+ uses: actions/checkout@v3
11
+
12
+ - name: Set up Node.js
13
+ uses: actions/setup-node@v3
14
+ with:
15
+ node-version: 18
16
+
17
+ - name: Install Node.js dependencies
18
+ run: npm ci
19
+
20
+ - name: Formatting with Prettier
21
+ run: npm run format
22
+
23
+ - name: Linting with ESLint
24
+ run: npm run lint
package/CHANGELOG.md CHANGED
@@ -1,37 +1,77 @@
1
- # Changelog
2
-
3
- ## [v1.1.1](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.1.1)
4
- - VER update to `maplibre-gl@3.1.0`
5
-
6
- ## [v1.1.0](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.1.0)
7
- - VER updated from `maplibre-gl@3.0.0-pre.4` to `maplibre-gl@3.0.1` (this includes the switch to WebGL2)
8
- - UP made the few necessary changes acording to updating the ML v3. No braking change for SDK API
9
- - FIX the MapTiler logo rel name and its nofollow feature
10
- - ADD bringing back Map's `options.transformRequest` and `.setTransformRequest()`
11
-
12
-
13
- ## [v1.0.12](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.12)
14
- - ADD a new language flag `Language.STYLE_LOCK` to force keep the language form the style and prevent any further update. Can be at a sigle map instance level (via constuctor option `language`) or via global config (`config.primaryLanguage`)
15
- - FIX the fallback language was `{name:latin}`, it is now replaced by `{name}`, which is for the local name (present by default for many places while `latin` is less frequent).
16
-
17
- ## [v1.0.11](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.11)
18
- - DOC update for `Map`'s `option.maptilerLogo` that was a bit unclear
19
- - FIX now exporting `MaptilerNavigationControl`
20
-
21
- ## [v1.0.10](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.10)
22
- - ADD terrain growing animation on enabling/disabling
23
- - ADD `Map` custom event `loadWithTerrain`
24
- - ADD `Map` lifecycle methods `.onLoadAsync()` and `.onLoadWithTerrainAsync()`
25
- - DOC readme section was added about the event an methods above
26
- - VER updated from `maplibre-gl@3.0.0-pre.3` to `maplibre-gl@3.0.0-pre.4`
27
- - VER updated from `typedoc@0.23.21` to `typedoc@0.24.4`, which changes slightly the look of the reference documentation.
28
- - VER updated from `typescript@4.8.4` to `typescript@5.0.4`
29
- - VER updated from `rollup@2.79.0` to `rollup@3.20.6` as well as all the Rollup plugins
30
-
31
- ## [v1.0.9](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.9)
32
- - FIX: if the geolocate option is missing from `Map` constructor, then it's considered `false`
33
-
34
- - FIX: The instance types for the following MapLibre classes are now fully exported:
1
+ # MapTiler SDK Changelog
2
+
3
+ ## DEVEL
4
+ ### New Features
5
+ ### Bug Fixes
6
+ ### Others
7
+
8
+ ## 1.2.0
9
+ ### New Features
10
+ - Added the Minimap control https://github.com/maptiler/maptiler-sdk-js/pull/54
11
+ - Added vector layer helpers to create easier:
12
+ - point layer (https://github.com/maptiler/maptiler-sdk-js/pull/61)
13
+ - heatmap layer (https://github.com/maptiler/maptiler-sdk-js/pull/61)
14
+ - polyline layer, including parsing from GPX/KML (https://github.com/maptiler/maptiler-sdk-js/pull/51)
15
+ - polygon layer (https://github.com/maptiler/maptiler-sdk-js/pull/56)
16
+ - Add the `ColorRamp` class to create and customize color ramps, as well as `ColorRampCollection` with many predefined ones (as part of https://github.com/maptiler/maptiler-sdk-js/pull/61)
17
+ - Improved the language management for increased compatibility with [MapTiler Customize](https://cloud.maptiler.com/maps/editor/) (https://github.com/maptiler/maptiler-sdk-js/pull/58)
18
+ ### Bug Fixes
19
+ - Fixed type export (https://github.com/maptiler/maptiler-sdk-js/pull/47)
20
+ ### Others
21
+ - Upgrade to MapLibre v3.5.2 (https://github.com/maptiler/maptiler-sdk-js/pull/63)
22
+ - Update of TypeScript configuration `moduleResolution` to `Bundler` (https://github.com/maptiler/maptiler-sdk-js/pull/62)
23
+
24
+ ## 1.1.2
25
+ ### Bug Fixes
26
+ - Now using a fixed version of MapLibre GL. No longer use `^` because this caused issues as MapLibre made minor/patch update that were not backward compatible
27
+
28
+ ## 1.1.1
29
+ ### Others
30
+ - Update to `maplibre-gl@3.1.0`
31
+
32
+ ## 1.1.0
33
+ ### New Features
34
+ - Bringing back Map's `options.transformRequest` and `.setTransformRequest()`
35
+ ### Bug Fixes
36
+ - Fixed the MapTiler logo rel name and its nofollow feature
37
+ - Made the few necessary changes acording to updating the ML v3. No braking change for SDK API
38
+ ### Others
39
+ - Updated from `maplibre-gl@3.0.0-pre.4` to `maplibre-gl@3.0.1` (this includes the switch to WebGL2)
40
+
41
+
42
+ ## 1.0.12
43
+ ### New Features
44
+ - Added a new language flag `Language.STYLE_LOCK` to force keep the language form the style and prevent any further update. Can be at a sigle map instance level (via constuctor option `language`) or via global config (`config.primaryLanguage`)
45
+ ### Bug Fixes
46
+ - The fallback language was `{name:latin}`, it is now replaced by `{name}`, which is for the local name (present by default for many places while `latin` is less frequent).
47
+
48
+ ## 1.0.11
49
+ ### Bug Fixes
50
+ - Now exporting `MaptilerNavigationControl`
51
+ ### Others
52
+ - Documentation update for `Map`'s `option.maptilerLogo` that was a bit unclear
53
+
54
+ ## 1.0.10
55
+ ### New Features
56
+ - Terrain growing animation on enabling/disabling
57
+ - Added `Map` custom event `loadWithTerrain`
58
+ - Added `Map` lifecycle methods `.onLoadAsync()` and `.onLoadWithTerrainAsync()`
59
+ ### Others
60
+ - Readme section was added about the event an methods above
61
+ - Updated from `maplibre-gl@3.0.0-pre.3` to `maplibre-gl@3.0.0-pre.4`
62
+ - Updated from `typedoc@0.23.21` to `typedoc@0.24.4`, which changes slightly the look of the reference documentation.
63
+ - Updated from `typescript@4.8.4` to `typescript@5.0.4`
64
+ - Updated from `rollup@2.79.0` to `rollup@3.20.6` as well as all the Rollup plugins
65
+
66
+ ## 1.0.9
67
+ ### New Features
68
+ - Added new styles:
69
+ - `MapStyle.STREETS.NIGHT`
70
+ - `MapStyle.WINTER.DARK`
71
+ - `MapStyle.OUTDOOR.DARK`
72
+ ### Bug Fixes
73
+ - If the geolocate option is missing from `Map` constructor, then it's considered `false`
74
+ - The instance types for the following MapLibre classes are now fully exported:
35
75
  - `NavigationControl`
36
76
  - `GeolocateControl`
37
77
  - `AttributionControl`
@@ -55,8 +95,7 @@
55
95
  - `VectorTileSource`
56
96
  - `VideoSource`
57
97
  - `MapMLGL`
58
-
59
- - FIX: The following class have been extended to provide greater compatibility with SDK,s MapL
98
+ - The following class have been extended to provide greater compatibility with SDK,s MapL
60
99
  - `Popup`
61
100
  - `Marker`
62
101
  - `Style`
@@ -75,40 +114,44 @@
75
114
  - `FullscreenControl`
76
115
  - `TerrainControl`
77
116
 
78
- - ADD: new styles:
79
- - `MapStyle.STREETS.NIGHT`
80
- - `MapStyle.WINTER.DARK`
81
- - `MapStyle.OUTDOOR.DARK`
82
117
 
83
- ## [v1.0.8](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.8)
84
- - FIX: Since v1.0.7, the `Map` primary language (when custom) was no longer persistant on style update.
118
+ ## 1.0.8
119
+ ### Bug Fixes
120
+ - Since v1.0.7, the `Map` primary language (when custom) was no longer persistant on style update.
85
121
 
86
- ## [v1.0.7](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.7)
122
+ ## 1.0.7
123
+ ### New Features
87
124
  - The `apiKey` can now be specified in the `Map` constructor (will propagate to `config`)
88
125
  - The `language` can now be speficifed in the `Map` constructo (will **not** propagete to `config` and will apply only to this specific instance)
89
126
  - `Map` now has the method `.getSdkConfig()` to retrieve the config object.
90
127
  - `Map` now has the method `.getMaptilerSessionId()` to retrieve the MapTiler session ID
91
-
92
128
  Both `.getSdkConfig()` and `.getMaptilerSessionId()` are handy for layers or control built outside of the SDK that still need some of the configuration to interact with the server. Those components do not always have access to the internal of the SDK (especially that the config is scoped) but can access to the `Map` instance to which they are added with the implementation of the `.onAdd()` method.
93
129
 
94
- ## [v1.0.6](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.6)
130
+ ## 1.0.6
131
+ ### New Features
95
132
  - Now exposing `MaptilerGeolocateControl` for external initialization if needed
96
133
  - Now exposing `MaptilerTerrain` for external initialization if needed
97
134
 
98
- ## [v1.0.5](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.5)
135
+ ## 1.0.5
136
+ ### New Features
99
137
  - Terrain elevation is now using MapTiler's `terrain-rgb-v2`
100
138
 
101
- ## [v1.0.4](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.4)
139
+ ## 1.0.4
140
+ ### Others
102
141
  - Improved the geolocate control behavior by not zooming out
103
142
 
104
- ## [v1.0.3](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.3)
143
+ ## 1.0.3
144
+ ### Bug Fixes
105
145
  - Fixed the usage of relative path style JSON (in `Map` constructor and `.setStyle()`)
106
146
 
107
- ## [v1.0.2](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.2)
147
+ ## 1.0.2
148
+ ### Bug Fixes
108
149
  - Fixed the dependency scheme of MapLibre import.
109
150
 
110
- ## [v1.0.1](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.1)
151
+ ## 1.0.1
152
+ ### Others
111
153
  - Reducing the NPM size by ignoring documentation images
112
154
 
113
- ## [v1.0.0](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.0)
155
+ ## 1.0.0
156
+ ### Others
114
157
  - First public version!
package/colorramp.md ADDED
@@ -0,0 +1,93 @@
1
+ # ColorRamps resampling
2
+ `ColorRamps` in the SDK, whether they are built-in (`ColorRampCollection`) or custom made (`new ColorRamp()`) can be resampled in a non linear fashion. Such resampling can serve different purposes, for instance:
3
+ - the data to visualize follows a non-linear function
4
+ - the goal of the visualization is to specificaly emphasize difference towards the lower or upper bound of the range
5
+
6
+ Creating a non linear color ramp can be a bit difficult, so resampling an existing one that has been originaly created as linear is easier. At the moment, the SDK provides four methods to resample a color ramp with the `.resample()` function:
7
+ - folowing a square function: `"ease-in-square"`
8
+ - folowing a square function: `"ease-out-square"`
9
+ - following a square root: `"ease-in-sqrt"`
10
+ - following a square root: `"ease-out-sqrt"`
11
+ - folowing an exponential function: `"ease-in-exp"`
12
+ - folowing an exponential function: `"ease-in-exp"`
13
+
14
+ Note: the *ease-out* equivalent of *ease-in-square* is technically *ease-out-square* and the *ease-in* equivalent of *ease-out-sqrt* is technically *ease-in-sqrt* but after some tests, it appeared that `"ease-in-square"` and `"ease-out-sqrt"` where a better pairing so this is why we decided to focus mainly on those two.
15
+
16
+ Terminology:
17
+ - an function is said **ease in** when its acceleration is fairly low at the begining and much higher towards the end
18
+ - an function is said **ease out** when its acceleration is quite high at begining and much lower towards the end
19
+
20
+
21
+ ## Linear logic
22
+ All the built-in color ramps are defined in a range of `(0, 1)`. Even though they can be scaled (`.scale(min, max)`) or custom ones can be created on a diferent interval, the range of (0, 1) is the most convenient to visualize how things work. Also, to keep it simple we are using a linear gray color ramp going from `(R:0, G:0, B:0)` to `(R:255, G:255, B:255)`. You can find this specific one as `ColorRampCollection.GRAY`.
23
+
24
+ ![](images/plot_linear_gradient.jpg)
25
+
26
+ - along the `x` axis (horizontal), the input number. This can be the intensity or any real-worl metric
27
+ - along the `y` axis (vertical), the output color
28
+
29
+ As we can see:
30
+ - an input of `0` will yied the color `(R:0, G:0, B:0)`
31
+ - an input of `0.5` will yied the color `(R:127, G:127, B:127)`
32
+ - an input of `1` will yied the color `(R:255, G:255, B:255)`
33
+
34
+ The original linear GRAY color ramp looks like this:
35
+
36
+ ![](images/gray_linear.png)
37
+
38
+ ## *ease-out-sqrt* method
39
+ To resample a color ramp with the *square root* method, simply do:
40
+ ```ts
41
+ const graySqrt = ColorRampCollection.GRAY.resample("ease-out-sqrt");
42
+ ```
43
+
44
+ Note: this will **not** modify the origin `ColorRampCollection.GRAY`.
45
+
46
+ There are multiple ways to visualize the effect of such resampling. The simplest is probably to do as above (*linear logic*), but using a *square root* function:
47
+
48
+ ![](images/plot_sqrt_gradient.jpg)
49
+
50
+ This will yield the following color ramp:
51
+
52
+ ![](images/gray_sqrt.png)
53
+
54
+ If we compare with the linear GRAY from above, we can see that the lower part (the darkest) is sort of compressed, while the upper part (the lightest) looks stretched.
55
+
56
+ As a result:
57
+ - an input of `0` will yied the color `(R:0, G:0, B:0)`
58
+ - an input of `0.5` will yied the color `(R:180, G:180, B:180)`
59
+ - an input of `1` will yied the color `(R:255, G:255, B:255)`
60
+
61
+ Another way to look at the *ease-out-sqrt-resampled* GRAY color ramp is by using it along the `y` axis and addressing it with data that are following a linear rule:
62
+ ![](images/linear_on_sqrt.jpg)
63
+
64
+ This can be convenient to do if the purpose is to emphasize the change of values on the lower-end, say in the range `(0, 0.4)` as the color response will be faster-changing than with a linear scale.
65
+
66
+ ## *ease-in-square* method
67
+ To resample a color ramp with the *square* method, simply do:
68
+ ```ts
69
+ const graySquare = ColorRampCollection.GRAY.resample("ease-in-square");
70
+ ```
71
+
72
+ Note: this will **not** modify the origin `ColorRampCollection.GRAY`.
73
+
74
+ Let's visualize it, using the original linear gradient along the `y` axis:
75
+
76
+ ![](images/plot_square_gradient.jpg)
77
+
78
+ This will yield the following color ramp:
79
+
80
+ ![](images/gray_square.png)
81
+
82
+ As we can see, compared to the linear ramping, the change is color is slower towards the lower end and faster towards the end of the range.
83
+
84
+ As a result:
85
+ - an input of `0` will yied the color `(R:0, G:0, B:0)`
86
+ - an input of `0.5` will yied the color `(R:64, G:64, B:64)`
87
+ - an input of `1` will yied the color `(R:255, G:255, B:255)`
88
+
89
+ Again, we can visualize a *ease-in-square-resampled* color ramp by using it alongside the `y` axis, with linear data:
90
+
91
+ ![](images/linear_on_square.jpg)
92
+
93
+ Contrary to the *ease-out-sqrt* method, the *ease-in-square* will yield faster changing colors on the upper bound of the input range.