@acalcutt/maplibre-gl-native-test 5.3.0-pre.1 → 5.4.1-pre.2
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 +223 -58
- package/{platform/node/index.js → index.js} +1 -1
- package/package.json +32 -29
- package/LICENSE.mbgl-core.md +0 -661
- package/LICENSE.md +0 -30
- package/platform/node/README.md +0 -247
- /package/{platform/node/index.d.ts → index.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,81 +1,246 @@
|
|
|
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)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
## Installing
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
Binaries are available and downloaded during install for the following platforms:
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
- Operating systems:
|
|
11
|
+
- Ubuntu 22.04 (amd64/arm64)
|
|
12
|
+
- macOS 12 (amd64/arm64)
|
|
13
|
+
- Windows (amd64)
|
|
14
|
+
- Node.js 16, 18, 20
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
Run:
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
```
|
|
19
|
+
npm install @maplibre/maplibre-gl-native
|
|
20
|
+
```
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
Further platforms might work [with additional libraries installed](https://github.com/maplibre/maplibre-native/tree/main/platform/linux#prerequisites).
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
## Testing
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
```
|
|
27
|
+
npm test
|
|
28
|
+
```
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
- [⭐️ iOS](platform/ios/platform/ios/README.md)
|
|
25
|
-
- [GLFW](platform/glfw)
|
|
26
|
-
- [Linux](platform/linux/README.md)
|
|
27
|
-
- [Node.js](platform/node/README.md)
|
|
28
|
-
- [Qt](platform/qt/README.md)
|
|
29
|
-
- [Windows](platform/windows/README.md)
|
|
30
|
-
- [macOS](platform/ios/platform/macos/README.md)
|
|
30
|
+
## Rendering a map tile
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
The minimal example requires only the instantiation of the `mbgl.Map` object, loading a style and calling the `map.render` method:
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
```js
|
|
35
|
+
var mbgl = require('@maplibre/maplibre-gl-native');
|
|
36
|
+
var sharp = require('sharp');
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
var map = new mbgl.Map();
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
map.load(require('./test/fixtures/style.json'));
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
map.render(function(err, buffer) {
|
|
43
|
+
if (err) throw err;
|
|
41
44
|
|
|
42
|
-
|
|
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).
|
|
45
|
+
map.release();
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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/).
|
|
56
|
-
|
|
57
|
-
## Sponsors
|
|
47
|
+
var image = sharp(buffer, {
|
|
48
|
+
raw: {
|
|
49
|
+
width: 512,
|
|
50
|
+
height: 512,
|
|
51
|
+
channels: 4
|
|
52
|
+
}
|
|
53
|
+
});
|
|
58
54
|
|
|
59
|
-
|
|
55
|
+
// Convert raw image buffer to PNG
|
|
56
|
+
image.toFile('image.png', function(err) {
|
|
57
|
+
if (err) throw err;
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
```
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
But you can customize the map providing an options object to `mbgl.Map` constructor and to `map.render` method:
|
|
62
63
|
|
|
63
|
-
|
|
64
|
+
```js
|
|
65
|
+
var fs = require('fs');
|
|
66
|
+
var path = require('path');
|
|
67
|
+
var mbgl = require('@maplibre/maplibre-gl-native');
|
|
68
|
+
var sharp = require('sharp');
|
|
64
69
|
|
|
65
|
-
|
|
70
|
+
var options = {
|
|
71
|
+
request: function(req, callback) {
|
|
72
|
+
fs.readFile(path.join(__dirname, 'test', req.url), function(err, data) {
|
|
73
|
+
callback(err, { data: data });
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
ratio: 1
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
var map = new mbgl.Map(options);
|
|
80
|
+
|
|
81
|
+
map.load(require('./test/fixtures/style.json'));
|
|
82
|
+
|
|
83
|
+
map.render({zoom: 0}, function(err, buffer) {
|
|
84
|
+
if (err) throw err;
|
|
85
|
+
|
|
86
|
+
map.release();
|
|
87
|
+
|
|
88
|
+
var image = sharp(buffer, {
|
|
89
|
+
raw: {
|
|
90
|
+
width: 512,
|
|
91
|
+
height: 512,
|
|
92
|
+
channels: 4
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Convert raw image buffer to PNG
|
|
97
|
+
image.toFile('image.png', function(err) {
|
|
98
|
+
if (err) throw err;
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The first argument passed to `map.render` is an options object, all keys are optional:
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
{
|
|
107
|
+
zoom: {zoom}, // number, defaults to 0
|
|
108
|
+
width: {width}, // number (px), defaults to 512
|
|
109
|
+
height: {height}, // number (px), defaults to 512
|
|
110
|
+
center: [{longitude}, {latitude}], // array of numbers (coordinates), defaults to [0,0]
|
|
111
|
+
bearing: {bearing}, // number (in degrees, counter-clockwise from north), defaults to 0
|
|
112
|
+
pitch: {pitch}, // number (in degrees, arcing towards the horizon), defaults to 0
|
|
113
|
+
classes: {classes} // array of strings
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
When you are finished using a map object, you can call `map.release()` to permanently dispose the internal map resources. This is not necessary, but can be helpful to optimize resource usage (memory, file sockets) on a more granular level than V8's garbage collector. Calling `map.release()` will prevent a map object from being used for any further render calls, but can be safely called as soon as the `map.render()` callback returns, as the returned pixel buffer will always be retained for the scope of the callback.
|
|
118
|
+
|
|
119
|
+
## Implementing a file source
|
|
120
|
+
|
|
121
|
+
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:
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
var map = new mbgl.Map({
|
|
125
|
+
request: function(req) {
|
|
126
|
+
// TODO
|
|
127
|
+
},
|
|
128
|
+
ratio: 2.0
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
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:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"url": "http://example.com",
|
|
137
|
+
"kind": 1
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The `kind` is an enum and defined in [`mbgl.Resource`](https://github.com/maplibre/maplibre-native/blob/main/include/mbgl/storage/resource.hpp):
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"Unknown": 0,
|
|
146
|
+
"Style": 1,
|
|
147
|
+
"Source": 2,
|
|
148
|
+
"Tile": 3,
|
|
149
|
+
"Glyphs": 4,
|
|
150
|
+
"SpriteImage": 5,
|
|
151
|
+
"SpriteJSON": 6
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
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.
|
|
156
|
+
|
|
157
|
+
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:
|
|
158
|
+
|
|
159
|
+
```js
|
|
160
|
+
{
|
|
161
|
+
data: {data}, // required, must be a byte array, usually a Buffer object
|
|
162
|
+
modified: {modified}, // Date, optional
|
|
163
|
+
expires: {expires}, // Date, optional
|
|
164
|
+
etag: {etag} // string, optional
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
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.
|
|
169
|
+
|
|
170
|
+
A sample implementation that reads files from disk would look like the following:
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
var map = new mbgl.Map({
|
|
174
|
+
request: function(req, callback) {
|
|
175
|
+
fs.readFile(path.join('base/path', req.url), function(err, data) {
|
|
176
|
+
callback(err, { data: data });
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
This is a very barebones implementation and you'll probably want a better implementation. E.g. it passes the url verbatim to the file system, but you'd want add some logic that normalizes `http` URLs. You'll notice that once your implementation has obtained the requested file, you have to deliver it to the requestee by calling `callback()`, which takes either an error object or `null` and an object with several keys:
|
|
183
|
+
|
|
184
|
+
```js
|
|
185
|
+
{
|
|
186
|
+
modified: new Date(),
|
|
187
|
+
expires: new Date(),
|
|
188
|
+
etag: "string",
|
|
189
|
+
data: new Buffer()
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
A sample implementation that uses [`request`](https://github.com/request/request) to fetch data from a remote source:
|
|
194
|
+
|
|
195
|
+
```js
|
|
196
|
+
var mbgl = require('@maplibre/maplibre-gl-native');
|
|
197
|
+
var request = require('request');
|
|
198
|
+
|
|
199
|
+
var map = new mbgl.Map({
|
|
200
|
+
request: function(req, callback) {
|
|
201
|
+
request({
|
|
202
|
+
url: req.url,
|
|
203
|
+
encoding: null,
|
|
204
|
+
gzip: true
|
|
205
|
+
}, function (err, res, body) {
|
|
206
|
+
if (err) {
|
|
207
|
+
callback(err);
|
|
208
|
+
} else if (res.statusCode == 200) {
|
|
209
|
+
var response = {};
|
|
210
|
+
|
|
211
|
+
if (res.headers.modified) { response.modified = new Date(res.headers.modified); }
|
|
212
|
+
if (res.headers.expires) { response.expires = new Date(res.headers.expires); }
|
|
213
|
+
if (res.headers.etag) { response.etag = res.headers.etag; }
|
|
214
|
+
|
|
215
|
+
response.data = body;
|
|
216
|
+
|
|
217
|
+
callback(null, response);
|
|
218
|
+
} else if (res.statusCode == 204) {
|
|
219
|
+
callback();
|
|
220
|
+
} else {
|
|
221
|
+
callback(new Error(JSON.parse(body).message));
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Stylesheets are free to use any protocols, but your implementation of `request` must support these; e.g. you could use `s3://` to indicate that files are supposed to be loaded from S3.
|
|
229
|
+
|
|
230
|
+
## Listening for log events
|
|
231
|
+
|
|
232
|
+
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.
|
|
233
|
+
|
|
234
|
+
```js
|
|
235
|
+
var mbgl = require('@maplibre/maplibre-gl-native');
|
|
236
|
+
mbgl.on('message', function(msg) {
|
|
237
|
+
t.ok(msg, 'emits error');
|
|
238
|
+
t.equal(msg.class, 'Style');
|
|
239
|
+
t.equal(msg.severity, 'ERROR');
|
|
240
|
+
t.ok(msg.text.match(/Failed to load/), 'error text matches');
|
|
241
|
+
});
|
|
242
|
+
```
|
|
66
243
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
<a href="https://meta.com"><img src="https://maplibre.org/img/meta-logo.svg" alt="Logo Meta" width="25%"/></a>
|
|
70
|
-
|
|
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>
|
|
72
|
-
|
|
73
|
-
<a href="https://komoot.com/"><img src="https://maplibre.org/img/komoot-logo.svg" alt="Logo komoot" width="25%"/></a>
|
|
74
|
-
|
|
75
|
-
Backers and Supporters:
|
|
76
|
-
|
|
77
|
-
[](https://opencollective.com/maplibre)
|
|
78
|
-
|
|
79
|
-
## License
|
|
244
|
+
## Contributing
|
|
80
245
|
|
|
81
|
-
|
|
246
|
+
See [DEVELOPING.md](DEVELOPING.md) for instructions on building this module for development.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// Shim to wrap req.respond while preserving callback-passing API
|
|
4
4
|
|
|
5
|
-
var mbgl = require('
|
|
5
|
+
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) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acalcutt/maplibre-gl-native-test",
|
|
3
|
-
"version": "5.
|
|
4
|
-
"description": "Renders map tiles with
|
|
3
|
+
"version": "5.4.1-pre.2",
|
|
4
|
+
"description": "Renders map tiles with MapLibre Native",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"maplibre",
|
|
7
7
|
"gl"
|
|
@@ -11,47 +11,50 @@
|
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"lib",
|
|
14
|
-
"
|
|
14
|
+
"index.d.ts"
|
|
15
15
|
],
|
|
16
|
-
"main": "
|
|
17
|
-
"types": "
|
|
16
|
+
"main": "index.js",
|
|
17
|
+
"types": "index.d.ts",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/
|
|
20
|
+
"url": "git+https://github.com/WifiDB/maplibre-native.git"
|
|
21
21
|
},
|
|
22
22
|
"license": "BSD-2-Clause",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@acalcutt/node-pre-gyp": "^1.0.
|
|
25
|
-
"@acalcutt/node-pre-gyp-github": "1.4.
|
|
26
|
-
"minimatch": "^
|
|
27
|
-
"npm-run-all": "^4.
|
|
24
|
+
"@acalcutt/node-pre-gyp": "^1.0.15",
|
|
25
|
+
"@acalcutt/node-pre-gyp-github": "1.4.9",
|
|
26
|
+
"minimatch": "^9.0.4",
|
|
27
|
+
"npm-run-all": "^4.1.5"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
+
"@aws-sdk/client-device-farm": "^3.556.0",
|
|
31
|
+
"@aws-sdk/client-s3": "^3.556.0",
|
|
30
32
|
"@mapbox/flow-remove-types": "^2.0.0",
|
|
31
33
|
"@mapbox/mvt-fixtures": "3.10.0",
|
|
32
|
-
"@octokit/plugin-retry": "^
|
|
33
|
-
"@octokit/rest": "^
|
|
34
|
+
"@octokit/plugin-retry": "^7.1.0",
|
|
35
|
+
"@octokit/rest": "^20.1.0",
|
|
36
|
+
"@types/node": "^20.12.7",
|
|
34
37
|
"argparse": "^2.0.1",
|
|
35
|
-
"
|
|
36
|
-
"csscolorparser": "~1.0.2",
|
|
38
|
+
"csscolorparser": "~1.0.3",
|
|
37
39
|
"d3-queue": "3.0.7",
|
|
38
|
-
"diff": "5.
|
|
39
|
-
"ejs": "^3.1.
|
|
40
|
+
"diff": "5.2.0",
|
|
41
|
+
"ejs": "^3.1.9",
|
|
40
42
|
"esm": "~3.2.25",
|
|
41
|
-
"express": "^4.
|
|
43
|
+
"express": "^4.19.2",
|
|
42
44
|
"json-stringify-pretty-compact": "^4.0.0",
|
|
43
|
-
"jsonwebtoken": "^9.0.
|
|
44
|
-
"lodash": "^4.
|
|
45
|
+
"jsonwebtoken": "^9.0.2",
|
|
46
|
+
"lodash": "^4.17.21",
|
|
45
47
|
"lodash.template": "4.5.0",
|
|
46
48
|
"mapbox-gl-styles": "2.0.2",
|
|
47
49
|
"pixelmatch": "^5.3.0",
|
|
48
|
-
"pngjs": "^
|
|
49
|
-
"pretty-bytes": "^6.1.
|
|
50
|
+
"pngjs": "^7.0.0",
|
|
51
|
+
"pretty-bytes": "^6.1.1",
|
|
50
52
|
"request": "^2.88.0",
|
|
51
|
-
"semver": "^7.
|
|
53
|
+
"semver": "^7.6.0",
|
|
52
54
|
"shuffle-seed": "1.1.6",
|
|
53
55
|
"st": "3.0.0",
|
|
54
|
-
"tape": "^5.
|
|
56
|
+
"tape": "^5.7.5",
|
|
57
|
+
"typescript": "^5.4.5",
|
|
55
58
|
"xcode": "^3.0.1"
|
|
56
59
|
},
|
|
57
60
|
"engines": {
|
|
@@ -59,17 +62,17 @@
|
|
|
59
62
|
},
|
|
60
63
|
"scripts": {
|
|
61
64
|
"install": "node-pre-gyp install --fallback-to-build=false",
|
|
62
|
-
"test": "tape
|
|
63
|
-
"test-memory": "node --expose-gc
|
|
64
|
-
"test-expressions": "node -r esm
|
|
65
|
-
"test-render": "node -r esm
|
|
66
|
-
"test-query": "node -r esm
|
|
65
|
+
"test": "tape test/js/**/*.test.js",
|
|
66
|
+
"test-memory": "node --expose-gc test/memory.test.js",
|
|
67
|
+
"test-expressions": "node -r esm test/expression.test.js",
|
|
68
|
+
"test-render": "node -r esm test/render.test.js",
|
|
69
|
+
"test-query": "node -r esm test/query.test.js"
|
|
67
70
|
},
|
|
68
71
|
"gypfile": true,
|
|
69
72
|
"binary": {
|
|
70
73
|
"module_name": "mbgl",
|
|
71
74
|
"module_path": "./lib/{node_abi}",
|
|
72
|
-
"host": "https://github.com/
|
|
75
|
+
"host": "https://github.com/WifiDB/maplibre-native/releases/download/",
|
|
73
76
|
"remote_path": "node-v{version}",
|
|
74
77
|
"package_name": "{node_abi}-{platform}-{arch}-{configuration}.tar.gz"
|
|
75
78
|
}
|