Spaces:
Sleeping
Sleeping
File size: 1,214 Bytes
4a288a7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
export default function (style) {
const styleIDs = [];
const sourceIDs = [];
const compositedSourceLayers = [];
for (const id in style.sources) {
const source = style.sources[id];
if (source.type !== "vector")
continue;
const match = /^mapbox:\/\/(.*)/.exec(source.url);
if (!match)
continue;
styleIDs.push(id);
sourceIDs.push(match[1]);
}
if (styleIDs.length < 2)
return style;
styleIDs.forEach((id) => {
delete style.sources[id];
});
const compositeID = sourceIDs.join(",");
style.sources[compositeID] = {
"type": "vector",
"url": `mapbox://${compositeID}`
};
style.layers.forEach((layer) => {
if (styleIDs.indexOf(layer.source) >= 0) {
layer.source = compositeID;
if ('source-layer' in layer) {
if (compositedSourceLayers.indexOf(layer['source-layer']) >= 0) {
throw new Error('Conflicting source layer names');
} else {
compositedSourceLayers.push(layer['source-layer']);
}
}
}
});
return style;
}
|