Expose clustering in layoutConfig

This commit is contained in:
Pieter Vander Vennet 2021-01-04 20:09:07 +01:00
parent 27f2206cae
commit c548c26158
7 changed files with 40 additions and 16 deletions

View file

@ -24,7 +24,9 @@ export default class LayoutConfig {
public readonly roamingRenderings: TagRenderingConfig[];
public readonly defaultBackgroundId?: string;
public readonly layers: LayerConfig[];
public readonly clustering: { };
public readonly clustering?: {
maxZoom: number
};
public readonly hideFromOverview: boolean;
public readonly enableUserBadge: boolean;
@ -76,22 +78,28 @@ export default class LayoutConfig {
);
this.defaultBackgroundId = json.defaultBackgroundId;
this.layers = json.layers.map((layer, i) => {
if (typeof layer === "string")
if (typeof layer === "string"){
if (SharedLayers.sharedLayers[layer] !== undefined) {
return SharedLayers.sharedLayers[layer];
} else {
throw "Unkown fixed layer " + layer;
}
}
return new LayerConfig(layer, this.roamingRenderings, `${this.id}.layers[${i}]`);
});
this.clustering = json.clustering ?? false;
this.clustering = undefined;
if(json.clustering){
this.clustering = {
maxZoom : json.clustering.maxZoom ?? 18
}
}
if(this.clustering){
for (const layer of this.layers) {
if(layer.wayHandling !== LayerConfig.WAYHANDLING_CENTER_ONLY){
throw "In order to allow clustering, every layer must be set to CENTER_ONLY";
console.error("WARNING: In order to allow clustering, every layer must be set to CENTER_ONLY. Layer", layer.id,"does not respect this for layout",this.id);
}
}
}

View file

@ -126,7 +126,10 @@ export interface LayoutConfigJson {
/**
* If defined, data will be clustered.
*/
clustering: {
clustering: {
/**
* All zoom levels above 'maxzoom' are not clustered anymore
*/
maxZoom?: number
},