rlayers
Version:
React Components for OpenLayers
144 lines • 6.02 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var layer_1 = require("ol/layer");
var RLayerRaster_1 = __importDefault(require("./RLayerRaster"));
var debug_1 = __importDefault(require("../debug"));
/**
* A layer from a remote MBTiles raster source
*
* WARNING: Using this module requires manually installing `ol-mbtiles`
*
* `npm install ol-mbtiles`
*
* Be sure to read its own documentation for tips on how to improve
* its performance (COOP/COEP, WASM compression, preloading...)
*
* Requires an `RMap` context
*/
var RLayerRasterMBTiles = /** @class */ (function (_super) {
__extends(RLayerRasterMBTiles, _super);
function RLayerRasterMBTiles(props, context) {
var _this = _super.call(this, props, context) || this;
_this.addon = Promise.resolve().then(function () { return __importStar(require('ol-mbtiles')); });
_this.ol = new layer_1.Tile();
_this.source = null;
_this.abort = null;
_this.createSource();
return _this;
}
RLayerRasterMBTiles.prototype.createSource = function () {
var _this = this;
(0, debug_1.default)('createSource start', this);
this.metadata = this.addon.then(function (mod) {
var _a, _b, _c, _d;
return mod.importMBTiles({
url: _this.props.url,
sqlWorkers: (_a = _this.props.workers) !== null && _a !== void 0 ? _a : 4,
sqlCacheSize: (_b = _this.props.sqlCacheSize) !== null && _b !== void 0 ? _b : 4096,
maxSqlPageSize: (_c = _this.props.maxSqlPageSize) !== null && _c !== void 0 ? _c : 4096,
backendType: (_d = _this.props.backend) !== null && _d !== void 0 ? _d : 'sync'
});
});
var abort = new AbortController();
this.abort = abort;
Promise.all([this.addon, this.metadata]).then(function (_a) {
var _b = __read(_a, 2), addon = _b[0], md = _b[1];
if (abort.signal.aborted) {
(0, debug_1.default)('createSource aborted', _this);
md.pool.then(function (p) { return p.close(); });
return;
}
_this.source = new addon.MBTilesRasterSource(md);
_this.eventSources = [_this.ol, _this.source];
_this.ol.setSource(_this.source);
_this.attachOldEventHandlers(_this.source);
if (_this.props.onMetadataReady)
_this.props.onMetadataReady.call(_this, md);
return _this.source;
});
};
RLayerRasterMBTiles.prototype.destroySource = function () {
(0, debug_1.default)('destroySource', this, this.abort);
if (this.source) {
this.source.dispose();
this.source = null;
if (this.ol)
this.ol.setSource(null);
}
if (this.abort) {
this.abort.abort();
this.abort = null;
}
};
RLayerRasterMBTiles.prototype.componentWillUnmount = function () {
_super.prototype.componentWillUnmount.call(this);
this.destroySource();
};
RLayerRasterMBTiles.prototype.refresh = function (prevProps) {
_super.prototype.refresh.call(this, prevProps);
if ((prevProps === null || prevProps === void 0 ? void 0 : prevProps.url) !== this.props.url) {
this.destroySource();
this.createSource();
}
};
return RLayerRasterMBTiles;
}(RLayerRaster_1.default));
exports.default = RLayerRasterMBTiles;
//# sourceMappingURL=RLayerRasterMBTiles.js.map
;