Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error if incorrect configuration #971

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions lib/layer/format/vector.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export default layer => {

layer.params ??= {}

// If layer configuration is wrong and contains both cluster.distance and cluster.resolution, error and return
if (layer.cluster?.distance && layer.cluster?.resolution) {

console.error(`Layer: ${layer.key}, cluster.distance and cluster.resolution are mutually exclusive. You cannot use them both on the same layer. Please remove one of them. `)

return;
};

if (layer.cluster?.resolution) {
layer.format = 'cluster';
layer.params.viewport = true;
Expand All @@ -33,33 +41,33 @@ export default layer => {
}

if (!features) return;

layer.source = new ol.source.Vector({
features: mapp.utils.featureFormats[layer.format](layer, [features].flat())
})

delete layer.xhr

if (layer.fade) mapp.layer.fade(layer)

// Geojson is a cluster layer.
if (layer.cluster?.distance) {

// Create cluster source.
layer.cluster.source = new ol.source.Cluster({
distance: layer.cluster.distance,
source: layer.source
})

layer.L.setSource(layer.cluster.source)
return;
}

// Set source if not cluster
layer.L.setSource(layer.source)
}

layer.reload = ()=>{
layer.reload = () => {

// Do not reload the layer if features have been assigned.
if (layer.features) return;
Expand Down Expand Up @@ -90,21 +98,21 @@ export default layer => {

clearTimeout(layer.timeout)

layer.timeout = setTimeout(()=>{
layer.timeout = setTimeout(() => {

layer.xhr = mapp.utils.xhr(
`${layer.mapview.host}/api/query?${mapp.utils.paramString({
template: layer.params.template || layer.format,
locale: layer.mapview.locale.key,
layer: layer.key,
table,
filter: layer.filter?.current,
...layer.params
})}`)
.then(layer.setSource)
template: layer.params.template || layer.format,
locale: layer.mapview.locale.key,
layer: layer.key,
table,
filter: layer.filter?.current,
...layer.params
})}`)
.then(layer.setSource)

}, 100)

}

// Create Openlayer Vector Layer
Expand Down Expand Up @@ -173,11 +181,11 @@ export default layer => {
})

}

// Return length for calculation of max_size.
return features.length
})

if (!feature_counts.length) return;

// Calculate max_size for cluster size styling.
Expand Down
Loading