Files
MapLibreParticleLab/platform/node/index.js
Konstantin Käfer 6b0ad899b3 [node] adhere to node module naming requirements
https://nodejs.org/api/addons.html#addons_building specifies that "The module_name must match the filename of the final binary (excluding the .node suffix).". While the mismatch between `mapbox-gl-native` and `mapbox_gl_native` hasn't caused issues so far, we should play by the book.
2017-02-23 22:15:57 +01:00

32 lines
876 B
JavaScript

"use strict";
// Shim to wrap req.respond while preserving callback-passing API
var mbgl = require('../../lib/mapbox_gl_native.node');
var constructor = mbgl.Map.prototype.constructor;
var Map = function(options) {
if (!(options instanceof Object)) {
throw TypeError("Requires an options object as first argument");
}
if (!options.hasOwnProperty('request') || !(options.request instanceof Function)) {
throw TypeError("Options object must have a 'request' method");
}
var request = options.request;
return new constructor(Object.assign(options, {
request: function(req) {
request(req, function() {
req.respond.apply(req, arguments);
});
}
}));
};
Map.prototype = mbgl.Map.prototype;
Map.prototype.constructor = Map;
module.exports = Object.assign(mbgl, { Map: Map });