Skip to content

Commit 6b77a1c

Browse files
committed
Add layerCreated callback
1 parent a1e2be1 commit 6b77a1c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

basemaps.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const XYZ = 'XYZ';
77

88
// All options (except for 'is') follow the OpenLayers options for the respective source class.
99
// Projections (except for EPSG:3857 and EPSG:4326) must be listed in the `crs` array in the config.js.
10+
//
11+
// There's a layerCreated callback that can be used to modify the layer and source after it has been created:
12+
// async layerCreated(Layer layer, Source source) => Layer
1013
const BASEMAPS = {
1114
earth: [
1215
{

src/components/maps/MapMixin.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,16 @@ export default {
140140
import(`ol/source/${options.is}.js`),
141141
import(`ol/layer/${layerClassName}.js`)
142142
]);
143-
return new layerCls({
144-
source: new sourceCls(options),
143+
const source = new sourceCls(options);
144+
const layer = new layerCls({
145+
source,
145146
title: options.title,
146147
base: true
147148
});
149+
if (options.layerCreated) {
150+
return await options.layerCreated(layer, source);
151+
}
152+
return layer;
148153
} catch (error) {
149154
console.error(`Failed to load basemap source for ${options.is}`, error);
150155
return null;

0 commit comments

Comments
 (0)