libre-routing
Version:
This library was generated with [Nx](https://nx.dev).
36 lines • 1.15 kB
JavaScript
import { LibreRoutingConsts } from '../../consts';
import { mergeDeep } from '../../utils/object';
import { routeLayer, waypointsLayer } from './layers';
export class LayersPlugin {
constructor(_options = {}) {
this._options = _options;
}
get map() {
return this.ctx.map;
}
onAdd(ctx) {
this.ctx = ctx;
this.options = mergeDeep(this.defaultConfig(ctx), this._options);
this.options.layers.forEach((layer) => {
// @ts-ignore
this.map.addLayer(layer.style, layer.before);
});
}
onRemove() {
this.map.removeLayer('route');
this.map.removeLayer('waypoints');
}
defaultConfig(ctx) {
return {
layers: [
{
style: routeLayer(ctx.getUniqueName(LibreRoutingConsts.RouteLayerId), this.ctx.options.routeSourceId),
},
{
style: waypointsLayer(ctx.getUniqueName(LibreRoutingConsts.WaypointsLayerId), this.ctx.options.waypointsSourceId),
},
],
};
}
}
//# sourceMappingURL=layers.plugin.js.map