@maplibre/maplibre-gl-native 5.2.0 → 5.3.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.
- package/README.md +15 -13
- package/package.json +6 -5
- package/platform/node/README.md +52 -9
- package/platform/node/index.d.ts +2 -2
- package/platform/node/index.js +36 -30
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
[](https://maplibre.org/)
|
|
2
2
|
|
|
3
|
-
# MapLibre
|
|
3
|
+
# MapLibre Native
|
|
4
4
|
|
|
5
|
-
MapLibre
|
|
5
|
+
MapLibre Native is a free and open-source library for publishing maps in your apps and desktop applications on various platforms. Fast displaying of maps is possible thanks to GPU-accelerated vector tile rendering.
|
|
6
6
|
|
|
7
7
|
This project originated as a fork of Mapbox GL Native, before their switch to a non-OSS license in December 2020. For more information, see: [`FORK.md`](./FORK.md).
|
|
8
8
|
|
|
@@ -12,11 +12,11 @@ This project originated as a fork of Mapbox GL Native, before their switch to a
|
|
|
12
12
|
|
|
13
13
|
## Getting Started
|
|
14
14
|
|
|
15
|
-
To get started with MapLibre
|
|
15
|
+
To get started with MapLibre Native, go to your platform below.
|
|
16
16
|
|
|
17
17
|
## Documentation
|
|
18
18
|
|
|
19
|
-
The documentation of MapLibre
|
|
19
|
+
The documentation of MapLibre Native is a work in progress. To get an architectural overview and to learn about the current state of the project and its path forward read the [MapLibre Native Markdown Book](https://maplibre.org/maplibre-native/docs/book/). See below for platform-specific documentation.
|
|
20
20
|
|
|
21
21
|
## Platforms
|
|
22
22
|
|
|
@@ -35,21 +35,24 @@ Platforms with a ⭐️ are **MapLibre Core Projects** and have a substantial am
|
|
|
35
35
|
|
|
36
36
|

|
|
37
37
|
|
|
38
|
-
MapLibre
|
|
38
|
+
MapLibre Native is being actively developed. Our big goal for 2023 is to modularize the OpenGL renderer and implement a Metal graphics backend (https://developer.apple.com/metal/). This will improve the performance and yield lower power consumption on iOS devices. At the same time, the Metal preparations will help us in the implementation of a Vulkan graphics backend.
|
|
39
39
|
|
|
40
40
|
Your help in preparing the codebase for the latest graphics backends is more than welcome. Feel free to reach out if you are interested in joining the effort!
|
|
41
41
|
|
|
42
42
|
- Check out the [news](https://maplibre.org/news/) on MapLibre's website.
|
|
43
|
-
- See the [Design Proposals](https://github.com/
|
|
43
|
+
- See the [Design Proposals](https://github.com/maplibre/maplibre-native/tree/main/design-proposals) that have been accepted and are being worked on, the most recent ones being the [Rendering Modularization Design Proposal](design-proposals/2022-10-27-rendering-modularization.md) and the [Metal Port Design Proposal](design-proposals/2022-11-29-metal-port.md).
|
|
44
44
|
|
|
45
45
|
## Contributing
|
|
46
46
|
|
|
47
|
-
To contribute to MapLibre
|
|
47
|
+
To contribute to MapLibre Native, see [`CONTRIBUTING.md`](CONTRIBUTING.md) and (if applicable) the specific instructions for the platform you want to contribute to.
|
|
48
48
|
|
|
49
49
|
### Getting Involved
|
|
50
50
|
|
|
51
51
|
Join the `#maplibre-native` Slack channel at OSMUS. Get an invite at https://slack.openstreetmap.us/
|
|
52
52
|
|
|
53
|
+
### Bounties 💰
|
|
54
|
+
|
|
55
|
+
Thanks to our sponsors, we are able to award bounties to developers making contributions toward certain [bounty directions](https://github.com/maplibre/maplibre/issues?q=is%3Aissue+is%3Aopen+label%3A%22bounty+direction%22). To get started doing bounties, refer to the [step-by-step bounties guide](https://maplibre.org/roadmap/step-by-step-bounties-guide/).
|
|
53
56
|
|
|
54
57
|
## Sponsors
|
|
55
58
|
|
|
@@ -59,16 +62,15 @@ Read more about the MapLibre Sponsorship Program at [https://maplibre.org/sponso
|
|
|
59
62
|
|
|
60
63
|
Platinum:
|
|
61
64
|
|
|
62
|
-
<img src="https://maplibre.org/img/aws-logo.svg" alt="Logo AWS" width="25%"
|
|
63
|
-
|
|
65
|
+
<a href="https://aws.com"><img src="https://maplibre.org/img/aws-logo.svg" alt="Logo AWS" width="25%"/></a>
|
|
64
66
|
|
|
65
67
|
Silver:
|
|
66
68
|
|
|
67
|
-
<img src="https://maplibre.org/img/meta-logo.svg" alt="Logo Meta" width="
|
|
69
|
+
<a href="https://meta.com"><img src="https://maplibre.org/img/meta-logo.svg" alt="Logo Meta" width="25%"/></a>
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
<a href="https://www.mierune.co.jp/?lang=en"><img src="https://maplibre.org/img/mierune-logo.svg" alt="Logo MIERUNE" width="25%"/></a>
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
<a href="https://komoot.com/"><img src="https://maplibre.org/img/komoot-logo.svg" alt="Logo komoot" width="25%"/></a>
|
|
72
74
|
|
|
73
75
|
Backers and Supporters:
|
|
74
76
|
|
|
@@ -76,4 +78,4 @@ Backers and Supporters:
|
|
|
76
78
|
|
|
77
79
|
## License
|
|
78
80
|
|
|
79
|
-
**MapLibre
|
|
81
|
+
**MapLibre Native** is licensed under the [BSD 2-Clause License](./LICENSE.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maplibre/maplibre-gl-native",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Renders map tiles with Maplibre GL",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"maplibre",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"types": "platform/node/index.d.ts",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/maplibre/maplibre-
|
|
20
|
+
"url": "git+https://github.com/maplibre/maplibre-native.git"
|
|
21
21
|
},
|
|
22
22
|
"license": "BSD-2-Clause",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@acalcutt/node-pre-gyp": "^1.0.
|
|
24
|
+
"@acalcutt/node-pre-gyp": "^1.0.14",
|
|
25
25
|
"@acalcutt/node-pre-gyp-github": "1.4.8",
|
|
26
26
|
"minimatch": "^7.2.0",
|
|
27
27
|
"npm-run-all": "^4.0.2"
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@mapbox/mvt-fixtures": "3.10.0",
|
|
32
32
|
"@octokit/plugin-retry": "^4.1.2",
|
|
33
33
|
"@octokit/rest": "^19.0.7",
|
|
34
|
+
"argparse": "^2.0.1",
|
|
34
35
|
"aws-sdk": "^2.1318.0",
|
|
35
36
|
"csscolorparser": "~1.0.2",
|
|
36
37
|
"d3-queue": "3.0.7",
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
"node": ">=6"
|
|
58
59
|
},
|
|
59
60
|
"scripts": {
|
|
60
|
-
"install": "node-pre-gyp install --fallback-to-build=
|
|
61
|
+
"install": "node-pre-gyp install --fallback-to-build=false",
|
|
61
62
|
"test": "tape platform/node/test/js/**/*.test.js",
|
|
62
63
|
"test-memory": "node --expose-gc platform/node/test/memory.test.js",
|
|
63
64
|
"test-expressions": "node -r esm platform/node/test/expression.test.js",
|
|
@@ -68,7 +69,7 @@
|
|
|
68
69
|
"binary": {
|
|
69
70
|
"module_name": "mbgl",
|
|
70
71
|
"module_path": "./lib/{node_abi}",
|
|
71
|
-
"host": "https://github.com/maplibre/maplibre-
|
|
72
|
+
"host": "https://github.com/maplibre/maplibre-native/releases/download/",
|
|
72
73
|
"remote_path": "node-v{version}",
|
|
73
74
|
"package_name": "{node_abi}-{platform}-{arch}-{configuration}.tar.gz"
|
|
74
75
|
}
|
package/platform/node/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# @maplibre/maplibre-gl-native
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@maplibre/maplibre-gl-native)
|
|
4
|
-
[](https://github.com/maplibre/maplibre-native/actions/workflows/node-ci.yml)
|
|
5
5
|
|
|
6
6
|
## Installing
|
|
7
7
|
|
|
8
8
|
Binaries are available and downloaded during install for the following platforms:
|
|
9
9
|
|
|
10
10
|
- Operating systems:
|
|
11
|
-
- Ubuntu
|
|
11
|
+
- Ubuntu 22.04 (amd64/arm64)
|
|
12
12
|
- macOS 12 (amd64/arm64)
|
|
13
13
|
- Windows (amd64)
|
|
14
|
-
- Node.js
|
|
14
|
+
- Node.js 16, 18, 20
|
|
15
15
|
|
|
16
16
|
Run:
|
|
17
17
|
|
|
@@ -19,7 +19,7 @@ Run:
|
|
|
19
19
|
npm install @maplibre/maplibre-gl-native
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
Further platforms might work [with additional libraries installed](https://github.com/maplibre/maplibre-
|
|
22
|
+
Further platforms might work [with additional libraries installed](https://github.com/maplibre/maplibre-native/tree/main/platform/linux#prerequisites).
|
|
23
23
|
|
|
24
24
|
## Testing
|
|
25
25
|
|
|
@@ -30,6 +30,38 @@ npm run test-suite
|
|
|
30
30
|
|
|
31
31
|
## Rendering a map tile
|
|
32
32
|
|
|
33
|
+
The minimal example requires only the instantiation of the `mbgl.Map` object, loading a style and calling the `map.render` method:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
var mbgl = require('@maplibre/maplibre-gl-native');
|
|
37
|
+
var sharp = require('sharp');
|
|
38
|
+
|
|
39
|
+
var map = new mbgl.Map();
|
|
40
|
+
|
|
41
|
+
map.load(require('./test/fixtures/style.json'));
|
|
42
|
+
|
|
43
|
+
map.render(function(err, buffer) {
|
|
44
|
+
if (err) throw err;
|
|
45
|
+
|
|
46
|
+
map.release();
|
|
47
|
+
|
|
48
|
+
var image = sharp(buffer, {
|
|
49
|
+
raw: {
|
|
50
|
+
width: 512,
|
|
51
|
+
height: 512,
|
|
52
|
+
channels: 4
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Convert raw image buffer to PNG
|
|
57
|
+
image.toFile('image.png', function(err) {
|
|
58
|
+
if (err) throw err;
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
But you can customize the map providing an options object to `mbgl.Map` constructor and to `map.render` method:
|
|
64
|
+
|
|
33
65
|
```js
|
|
34
66
|
var fs = require('fs');
|
|
35
67
|
var path = require('path');
|
|
@@ -87,7 +119,7 @@ When you are finished using a map object, you can call `map.release()` to perman
|
|
|
87
119
|
|
|
88
120
|
## Implementing a file source
|
|
89
121
|
|
|
90
|
-
When creating a `Map`, you
|
|
122
|
+
When creating a `Map`, you can optionally pass an options object (with an optional `request` method and optional `ratio` number) as the first parameter. The `request()` method handles a request for a resource. The `ratio` sets the scale at which the map will render tiles, such as `2.0` for rendering images for high pixel density displays:
|
|
91
123
|
|
|
92
124
|
```js
|
|
93
125
|
var map = new mbgl.Map({
|
|
@@ -98,7 +130,7 @@ var map = new mbgl.Map({
|
|
|
98
130
|
});
|
|
99
131
|
```
|
|
100
132
|
|
|
101
|
-
|
|
133
|
+
If you omit the `request` method, the `map` object will use the default internal request handlers, which is ok for most cases. However, if you have specific needs, you can implement your own `request` handler. When a `request` method is provided, all `map` resources will be requested by calling the `request` method with two parameters, called `req` and `callback` respectively in this example. The `req` parameter has two properties:
|
|
102
134
|
|
|
103
135
|
```json
|
|
104
136
|
{
|
|
@@ -107,7 +139,7 @@ The `request()` method handles a request for a resource. The `ratio` sets the sc
|
|
|
107
139
|
}
|
|
108
140
|
```
|
|
109
141
|
|
|
110
|
-
The `kind` is an enum and defined in [`mbgl.Resource`](https://github.com/maplibre/maplibre-
|
|
142
|
+
The `kind` is an enum and defined in [`mbgl.Resource`](https://github.com/maplibre/maplibre-native/blob/main/include/mbgl/storage/resource.hpp):
|
|
111
143
|
|
|
112
144
|
```json
|
|
113
145
|
{
|
|
@@ -123,7 +155,18 @@ The `kind` is an enum and defined in [`mbgl.Resource`](https://github.com/maplib
|
|
|
123
155
|
|
|
124
156
|
The `kind` enum has no significance for anything but serves as a hint to your implemention as to what sort of resource to expect. E.g., your implementation could choose caching strategies based on the expected file type.
|
|
125
157
|
|
|
126
|
-
The `
|
|
158
|
+
The `callback` parameter is a function that must be called with two parameters: an error message (if there are no errors, then you must pass `null`), and a response object:
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
{
|
|
162
|
+
data: {data}, // required, must be a byte array, usually a Buffer object
|
|
163
|
+
modified: {modified}, // Date, optional
|
|
164
|
+
expires: {expires}, // Date, optional
|
|
165
|
+
etag: {etag} // string, optional
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
If there is no data to be sent to the `callback` (empty data, or `no-content` respose), then it must be called without parameters. The `request` implementation should pass uncompressed data to `callback`. If you are downloading assets from a source that applies gzip transport encoding, the implementation must decompress the results before passing them on.
|
|
127
170
|
|
|
128
171
|
A sample implementation that reads files from disk would look like the following:
|
|
129
172
|
|
|
@@ -187,7 +230,7 @@ Stylesheets are free to use any protocols, but your implementation of `request`
|
|
|
187
230
|
|
|
188
231
|
## Listening for log events
|
|
189
232
|
|
|
190
|
-
The module imported with `require('maplibre-gl-native')` inherits from [`EventEmitter`](https://nodejs.org/api/events.html), and the `NodeLogObserver` will push log events to this. Log messages can have [`class`](https://github.com/maplibre/maplibre-
|
|
233
|
+
The module imported with `require('maplibre-gl-native')` inherits from [`EventEmitter`](https://nodejs.org/api/events.html), and the `NodeLogObserver` will push log events to this. Log messages can have [`class`](https://github.com/maplibre/maplibre-native/blob/node-v2.1.0/include/mbgl/platform/event.hpp#L43-L60), [`severity`](https://github.com/maplibre/maplibre-native/blob/node-v2.1.0/include/mbgl/platform/event.hpp#L17-L23), `code` ([HTTP status codes](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)), and `text` parameters.
|
|
191
234
|
|
|
192
235
|
```js
|
|
193
236
|
var mbgl = require('@maplibre/maplibre-gl-native');
|
package/platform/node/index.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ declare module '@maplibre/maplibre-gl-native' {
|
|
|
35
35
|
/**
|
|
36
36
|
* Will be used during a `Map.render` call to request all necessary map resources (tiles, fonts...)
|
|
37
37
|
*/
|
|
38
|
-
request
|
|
38
|
+
request?: (
|
|
39
39
|
request: { url: string; kind: ResourceKind },
|
|
40
40
|
callback: (error?: Error, response?: RequestResponse) => void,
|
|
41
41
|
) => void;
|
|
@@ -111,7 +111,7 @@ declare module '@maplibre/maplibre-gl-native' {
|
|
|
111
111
|
* A `Map` instance is used to render images from map views
|
|
112
112
|
*/
|
|
113
113
|
class Map {
|
|
114
|
-
constructor(mapOptions
|
|
114
|
+
constructor(mapOptions?: MapOptions);
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
117
|
* Load a style into a map
|
package/platform/node/index.js
CHANGED
|
@@ -6,43 +6,49 @@ var mbgl = require('../../lib/node-v' + process.versions.modules + '/mbgl');
|
|
|
6
6
|
var constructor = mbgl.Map.prototype.constructor;
|
|
7
7
|
|
|
8
8
|
var Map = function(options) {
|
|
9
|
-
if (!(options instanceof Object)) {
|
|
9
|
+
if (options && !(options instanceof Object)) {
|
|
10
10
|
throw TypeError("Requires an options object as first argument");
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
if (
|
|
14
|
-
throw TypeError("Options object must
|
|
13
|
+
if (options && options.hasOwnProperty('request') && !(options.request instanceof Function)) {
|
|
14
|
+
throw TypeError("Options object 'request' property must be a function");
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
responded
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
17
|
+
if (options && options.request) {
|
|
18
|
+
var request = options.request;
|
|
19
|
+
|
|
20
|
+
return new constructor(Object.assign(options, {
|
|
21
|
+
request: function(req) {
|
|
22
|
+
// Protect against `request` implementations that call the callback synchronously,
|
|
23
|
+
// call it multiple times, or throw exceptions.
|
|
24
|
+
// http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony
|
|
25
|
+
|
|
26
|
+
var responded = false;
|
|
27
|
+
var callback = function() {
|
|
28
|
+
var args = arguments;
|
|
29
|
+
if (!responded) {
|
|
30
|
+
responded = true;
|
|
31
|
+
process.nextTick(function() {
|
|
32
|
+
req.respond.apply(req, args);
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
console.warn('request function responded multiple times; it should call the callback only once');
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
request(req, callback);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.warn('request function threw an exception; it should call the callback with an error instead');
|
|
43
|
+
callback(e);
|
|
35
44
|
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
request(req, callback);
|
|
40
|
-
} catch (e) {
|
|
41
|
-
console.warn('request function threw an exception; it should call the callback with an error instead');
|
|
42
|
-
callback(e);
|
|
43
45
|
}
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
+
}));
|
|
47
|
+
} else if (options) {
|
|
48
|
+
return new constructor(options);
|
|
49
|
+
} else {
|
|
50
|
+
return new constructor();
|
|
51
|
+
}
|
|
46
52
|
};
|
|
47
53
|
|
|
48
54
|
Map.prototype = mbgl.Map.prototype;
|