{"_id":"@alpaca-travel/mapbox-gl-native","name":"@alpaca-travel/mapbox-gl-native","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.2":{"name":"@alpaca-travel/mapbox-gl-native","version":"1.0.2","description":"Node.js bindings to Mapbox GL native","keywords":["mbgl","mapbox","mapbox gl","gl"],"main":"index.js","repository":{"type":"git","url":"git://github.com/cammanderson/mapbox-gl-native.git"},"scripts":{"test":"tape 'test/**/*.test.js'","install":"node-pre-gyp install --fallback-to-build=false"},"license":"BSD-2-Clause","dependencies":{"@mapbox/cmake-node-module":"^1.2.0","node-pre-gyp":"^0.15.0"},"binary":{"module_name":"mbgl","module_path":"./lib/{node_abi}","host":"https://alpacatravel-node-binary.s3.amazonaws.com","remote_path":"./{name}/v{version}","package_name":"{node_abi}-{platform}-{arch}-{configuration}.tar.gz"},"engines":{"node":">=8"},"devDependencies":{"aws-sdk":"^2.768.0","pixelmatch":"^5.2.1","pngjs":"^5.0.0","request":"^2.88.2","tape":"^5.0.1"},"gitHead":"edfb714ee17d9552cbe7fc82ee9590d761f319f7","bugs":{"url":"https://github.com/cammanderson/mapbox-gl-native/issues"},"homepage":"https://github.com/cammanderson/mapbox-gl-native#readme","_id":"@alpaca-travel/mapbox-gl-native@1.0.2","_nodeVersion":"12.22.4","_npmVersion":"6.14.14","dist":{"integrity":"sha512-umNmCcBD1Xlno+pChaHo9DYao+co7CRp3jICNDaGVeyyFZMKxbiabZo8RMjtRObWGFuV/hR3DZ+RJ7+b8pBvbw==","shasum":"496970e933afb9d463334cbb8b763857ed32ab4c","tarball":"https://registry.npmjs.org/@alpaca-travel/mapbox-gl-native/-/mapbox-gl-native-1.0.2.tgz","fileCount":19,"unpackedSize":113649,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAJZ2coadtAhd5HsM9MuRDrUiVdnpJzX8QF0aplufCF6AiEAshzH7d0tXUaCNYTp1BKj6mnSSaAp98FLokNzkcP+qOM="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi7LkvACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrqdxAAlMdXFGQcXYcfVFEWTzLu2DrtvbkeIwxntzyyQFdl3KM+OH/2\r\noqj6fri5BS3APh/6Jctl3bZzuv25ZsCwJNZK05qUEXmmh7Krx/vXo++Cs7vL\r\nRMDKhiNSEOStdW10hVIpTEOQPkn6JaBdqUAwP1+kmbNkF12a/qPF/ZsPEc62\r\njmbug9TN1YuA/A2LtRwOStf8LriMyjZWWmWdnRProg6OBy2qpogg+3TJrpqR\r\nRaFmRjOPhyTghNM2kj/Q0qrIDqG96ZC3dWg04PoTu0R99cjHJAPpAXNHg1uE\r\n99aZLfVdjiO9ITXkJrF/txe/V6xLQHRW6x+4VjmOE/aApJhEbXRaMuSflIPr\r\ncEQKjT2jmg0cXlTzTFhosQ6KeCo8r++fZKfOKNKeob7e2D7mqupgCGJY4DNH\r\niloYQTtaPTw2yuGsNpGrYYW3n6zbk47kO2D7h4jobA89ABQjIGyLC7qJ46uw\r\nsB27/M8umRGAJWsLSE3bsFXOgcIOTX2zK+70hsAvzFLLskB0xsB5PezdKrwK\r\nO9nE+BkdcGca83Q90xmWF8b8GNLCjyD49p80wHEatoTNbtS7+ZrBb2ZBov5I\r\npbCEwUc3Zs4wstmYyHcAeDg4xaMamBJCMxQEPLf9wy/BNSJD8DHF7zEAJ5rV\r\npNzkFNs1UzxtBvsDa9cJUidy13Ho7y6Oing=\r\n=L8tw\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"cammanderson","email":"cameronmanderson@gmail.com"},"directories":{},"maintainers":[{"name":"cammanderson","email":"cameronmanderson@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mapbox-gl-native_1.0.2_1659681070841_0.7545653494296953"},"_hasShrinkwrap":false}},"time":{"created":"2022-08-05T06:31:10.841Z","1.0.2":"2022-08-05T06:31:11.042Z","modified":"2022-08-05T06:31:11.223Z"},"maintainers":[{"name":"cammanderson","email":"cameronmanderson@gmail.com"}],"description":"Node.js bindings to Mapbox GL native","homepage":"https://github.com/cammanderson/mapbox-gl-native#readme","keywords":["mbgl","mapbox","mapbox gl","gl"],"repository":{"type":"git","url":"git://github.com/cammanderson/mapbox-gl-native.git"},"bugs":{"url":"https://github.com/cammanderson/mapbox-gl-native/issues"},"license":"BSD-2-Clause","readme":"# Mapbox GL Native Node Bindings\n\nThis project provides pre-built Node.js bindings to Mapbox GL. Official node bindings from Mapbox are discontinued, per [mapbox-gl-native#16418](https://github.com/mapbox/mapbox-gl-native/issues/16418#issuecomment-621127219).\n\nThis just performs a more recent build supporting the original naturalatlas (see original fork)\n\n```sh\nsudo apt-get install libuv1\nnpm install @alpaca-travel/mapbox-gl-native --save\n```\n\n**Current Node Version Support**: 8, 10, 12, 13, 14, 15, 16, 17, 18\n\n## Rendering a map tile\n\n```js\nconst fs = require(\"fs\");\nconst path = require(\"path\");\nconst mbgl = require(\"@alpaca-travel/mapbox-gl-native\");\nconst sharp = require(\"sharp\");\n\nconst options = {\n  request: function (req, callback) {\n    fs.readFile(path.join(__dirname, \"test\", req.url), function (err, data) {\n      callback(err, { data: data });\n    });\n  },\n  ratio: 1,\n};\n\nconst map = new mbgl.Map(options);\n\nmap.load(require(\"./test/fixtures/style.json\"));\n\nmap.render({ zoom: 0 }, function (err, buffer) {\n  if (err) throw err;\n\n  map.release();\n\n  var image = sharp(buffer, {\n    raw: {\n      width: 512,\n      height: 512,\n      channels: 4,\n    },\n  });\n\n  // Convert raw image buffer to PNG\n  image.toFile(\"image.png\", function (err) {\n    if (err) throw err;\n  });\n});\n```\n\nThe first argument passed to `map.render` is an options object, all keys are optional:\n\n```js\n{\n    zoom: {zoom}, // number, defaults to 0\n    width: {width}, // number (px), defaults to 512\n    height: {height}, // number (px), defaults to 512\n    center: [{longitude}, {latitude}], // array of numbers (coordinates), defaults to [0,0]\n    bearing: {bearing}, // number (in degrees, counter-clockwise from north), defaults to 0\n    pitch: {pitch}, // number (in degrees, arcing towards the horizon), defaults to 0\n    classes: {classes} // array of strings\n}\n```\n\nWhen 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.\n\n## Implementing a file source\n\nWhen creating a `Map`, you must pass an options object (with a required `request` method and optional 'ratio' number) as the first parameter.\n\n```js\nconst map = new mbgl.Map({\n  request: function (req) {\n    // TODO\n  },\n  ratio: 2.0,\n});\n```\n\nThe `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. The `req` parameter has two properties:\n\n```json\n{\n  \"url\": \"http://example.com\",\n  \"kind\": 1\n}\n```\n\nThe `kind` is an enum and defined in [`mbgl.Resource`](https://github.com/mapbox/mapbox-gl-native/blob/master/include/mbgl/storage/resource.hpp):\n\n```json\n{\n  \"Unknown\": 0,\n  \"Style\": 1,\n  \"Source\": 2,\n  \"Tile\": 3,\n  \"Glyphs\": 4,\n  \"SpriteImage\": 5,\n  \"SpriteJSON\": 6\n}\n```\n\nThe `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.\n\nThe `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.\n\nA sample implementation that reads files from disk would look like the following:\n\n```js\nvar map = new mbgl.Map({\n  request: function (req, callback) {\n    fs.readFile(path.join(\"base/path\", req.url), function (err, data) {\n      callback(err, { data: data });\n    });\n  },\n});\n```\n\nThis 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:\n\n```js\n{\n    modified: new Date(),\n    expires: new Date(),\n    etag: \"string\",\n    data: new Buffer()\n}\n```\n\nA sample implementation that uses [`request`](https://github.com/request/request) to fetch data from a remote source:\n\n```js\nconst mbgl = require(\"@alpaca-travel/mapbox-gl-native\");\nconst request = require(\"request\");\n\nconst map = new mbgl.Map({\n  request: function (req, callback) {\n    request(\n      {\n        url: req.url,\n        encoding: null,\n        gzip: true,\n      },\n      function (err, res, body) {\n        if (err) {\n          callback(err);\n        } else if (res.statusCode == 200) {\n          const response = {};\n\n          if (res.headers.modified) {\n            response.modified = new Date(res.headers.modified);\n          }\n          if (res.headers.expires) {\n            response.expires = new Date(res.headers.expires);\n          }\n          if (res.headers.etag) {\n            response.etag = res.headers.etag;\n          }\n\n          response.data = body;\n\n          callback(null, response);\n        } else {\n          callback(new Error(JSON.parse(body).message));\n        }\n      }\n    );\n  },\n});\n```\n\nStylesheets 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.\n\n## Listening for log events\n\nThe module imported with `require('mapbox-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/mapbox/mapbox-gl-native/blob/node-v2.1.0/include/mbgl/platform/event.hpp#L43-L60), [`severity`](https://github.com/mapbox/mapbox-gl-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.\n\n```js\nconst mbgl = require(\"@alpaca-travel/mapbox-gl-native\");\nmbgl.on(\"message\", function (msg) {\n  t.ok(msg, \"emits error\");\n  t.equal(msg.class, \"Style\");\n  t.equal(msg.severity, \"ERROR\");\n  t.ok(msg.text.match(/Failed to load/), \"error text matches\");\n});\n```\n","readmeFilename":"README.md"}